diff --git a/config/crd/bases/cluster.x-k8s.io_machinepools.yaml b/config/crd/bases/cluster.x-k8s.io_machinepools.yaml index bd06d84e53cf..9fcd47760f3f 100644 --- a/config/crd/bases/cluster.x-k8s.io_machinepools.yaml +++ b/config/crd/bases/cluster.x-k8s.io_machinepools.yaml @@ -1053,52 +1053,6 @@ spec: pointer to distinguish between explicit zero and not specified. format: int32 type: integer - selector: - description: Label selector for machines. Existing MachineSets whose - machines are selected by this will be the ones affected by this - deployment. It must match the machine template's labels. - properties: - matchExpressions: - description: matchExpressions is a list of label selector requirements. - The requirements are ANDed. - items: - description: A label selector requirement is a selector that - contains values, a key, and an operator that relates the key - and values. - properties: - key: - description: key is the label key that the selector applies - to. - type: string - operator: - description: operator represents a key's relationship to - a set of values. Valid operators are In, NotIn, Exists - and DoesNotExist. - type: string - values: - description: values is an array of string values. If the - operator is In or NotIn, the values array must be non-empty. - If the operator is Exists or DoesNotExist, the values - array must be empty. This array is replaced during a strategic - merge patch. - items: - type: string - type: array - required: - - key - - operator - type: object - type: array - matchLabels: - additionalProperties: - type: string - description: matchLabels is a map of {key,value} pairs. A single - {key,value} in the matchLabels map is equivalent to an element - of matchExpressions, whose key field is "key", the operator - is "In", and the values array contains only "value". The requirements - are ANDed. - type: object - type: object template: description: Template describes the machines that will be created. properties: @@ -1279,7 +1233,6 @@ spec: type: object required: - clusterName - - selector - template type: object status: diff --git a/exp/api/v1alpha3/conversion.go b/exp/api/v1alpha3/conversion.go index b1eccab89345..8f6903b81abc 100644 --- a/exp/api/v1alpha3/conversion.go +++ b/exp/api/v1alpha3/conversion.go @@ -76,7 +76,6 @@ func (src *MachinePool) ConvertTo(dstRaw conversion.Hub) error { } dst.Spec.Template.Spec.NodeDeletionTimeout = restored.Spec.Template.Spec.NodeDeletionTimeout dst.Spec.Template.Spec.NodeVolumeDetachTimeout = restored.Spec.Template.Spec.NodeVolumeDetachTimeout - dst.Spec.Selector = restored.Spec.Selector return nil } diff --git a/exp/api/v1alpha3/zz_generated.conversion.go b/exp/api/v1alpha3/zz_generated.conversion.go index ba418bd028a6..19ae36da3b85 100644 --- a/exp/api/v1alpha3/zz_generated.conversion.go +++ b/exp/api/v1alpha3/zz_generated.conversion.go @@ -163,7 +163,6 @@ func autoConvert_v1alpha3_MachinePoolSpec_To_v1beta1_MachinePoolSpec(in *Machine func autoConvert_v1beta1_MachinePoolSpec_To_v1alpha3_MachinePoolSpec(in *v1beta1.MachinePoolSpec, out *MachinePoolSpec, s conversion.Scope) error { out.ClusterName = in.ClusterName out.Replicas = (*int32)(unsafe.Pointer(in.Replicas)) - // WARNING: in.Selector requires manual conversion: does not exist in peer-type if err := apiv1alpha3.Convert_v1beta1_MachineTemplateSpec_To_v1alpha3_MachineTemplateSpec(&in.Template, &out.Template, s); err != nil { return err } diff --git a/exp/api/v1alpha4/conversion.go b/exp/api/v1alpha4/conversion.go index d66548e85829..fa9d49368d8d 100644 --- a/exp/api/v1alpha4/conversion.go +++ b/exp/api/v1alpha4/conversion.go @@ -42,7 +42,6 @@ func (src *MachinePool) ConvertTo(dstRaw conversion.Hub) error { } dst.Spec.Template.Spec.NodeDeletionTimeout = restored.Spec.Template.Spec.NodeDeletionTimeout dst.Spec.Template.Spec.NodeVolumeDetachTimeout = restored.Spec.Template.Spec.NodeVolumeDetachTimeout - dst.Spec.Selector = restored.Spec.Selector return nil } diff --git a/exp/api/v1alpha4/zz_generated.conversion.go b/exp/api/v1alpha4/zz_generated.conversion.go index 8e2afb6e08d5..1c2ef9cc44f4 100644 --- a/exp/api/v1alpha4/zz_generated.conversion.go +++ b/exp/api/v1alpha4/zz_generated.conversion.go @@ -177,7 +177,6 @@ func Convert_v1alpha4_MachinePoolSpec_To_v1beta1_MachinePoolSpec(in *MachinePool func autoConvert_v1beta1_MachinePoolSpec_To_v1alpha4_MachinePoolSpec(in *v1beta1.MachinePoolSpec, out *MachinePoolSpec, s conversion.Scope) error { out.ClusterName = in.ClusterName out.Replicas = (*int32)(unsafe.Pointer(in.Replicas)) - // WARNING: in.Selector requires manual conversion: does not exist in peer-type if err := apiv1alpha4.Convert_v1beta1_MachineTemplateSpec_To_v1alpha4_MachineTemplateSpec(&in.Template, &out.Template, s); err != nil { return err } diff --git a/exp/api/v1beta1/machinepool_types.go b/exp/api/v1beta1/machinepool_types.go index 7f4d0a1792e2..3d08de8260be 100644 --- a/exp/api/v1beta1/machinepool_types.go +++ b/exp/api/v1beta1/machinepool_types.go @@ -42,11 +42,6 @@ type MachinePoolSpec struct { // +optional Replicas *int32 `json:"replicas,omitempty"` - // Label selector for machines. Existing MachineSets whose machines are - // selected by this will be the ones affected by this deployment. - // It must match the machine template's labels. - Selector metav1.LabelSelector `json:"selector"` - // Template describes the machines that will be created. Template clusterv1.MachineTemplateSpec `json:"template"` diff --git a/exp/api/v1beta1/zz_generated.deepcopy.go b/exp/api/v1beta1/zz_generated.deepcopy.go index 12427e28af55..164680e08999 100644 --- a/exp/api/v1beta1/zz_generated.deepcopy.go +++ b/exp/api/v1beta1/zz_generated.deepcopy.go @@ -95,7 +95,6 @@ func (in *MachinePoolSpec) DeepCopyInto(out *MachinePoolSpec) { *out = new(int32) **out = **in } - in.Selector.DeepCopyInto(&out.Selector) in.Template.DeepCopyInto(&out.Template) if in.MinReadySeconds != nil { in, out := &in.MinReadySeconds, &out.MinReadySeconds diff --git a/internal/controllers/topology/cluster/desired_state.go b/internal/controllers/topology/cluster/desired_state.go index 365f459fdac7..4a455a8f822b 100644 --- a/internal/controllers/topology/cluster/desired_state.go +++ b/internal/controllers/topology/cluster/desired_state.go @@ -1059,14 +1059,6 @@ func computeMachinePool(_ context.Context, s *scope.Scope, desiredControlPlaneSt // Note: the labels in MachineSet are used to properly cleanup templates when the MachineSet is deleted. desiredMachinePoolObj.Spec.Template.Labels = machinePoolLabels - // Set the selector with the subset of labels identifying controlled machines. - // NOTE: this prevents the web hook to add cluster.x-k8s.io/pool-name label, that is - // redundant for managed MachinePool given that we already have topology.cluster.x-k8s.io/pool-name. - desiredMachinePoolObj.Spec.Selector.MatchLabels = map[string]string{} - desiredMachinePoolObj.Spec.Selector.MatchLabels[clusterv1.ClusterNameLabel] = s.Current.Cluster.Name - desiredMachinePoolObj.Spec.Selector.MatchLabels[clusterv1.ClusterTopologyOwnedLabel] = "" - desiredMachinePoolObj.Spec.Selector.MatchLabels[clusterv1.ClusterTopologyMachinePoolNameLabel] = machinePoolTopology.Name - // Set the desired replicas. desiredMachinePoolObj.Spec.Replicas = machinePoolTopology.Replicas diff --git a/internal/controllers/topology/cluster/patches/inline/json_patch_generator.go b/internal/controllers/topology/cluster/patches/inline/json_patch_generator.go index 33b13037c0e7..c924265e1114 100644 --- a/internal/controllers/topology/cluster/patches/inline/json_patch_generator.go +++ b/internal/controllers/topology/cluster/patches/inline/json_patch_generator.go @@ -155,8 +155,8 @@ func matchesSelector(req *runtimehooksv1.GeneratePatchesRequestItem, templateVar } // Check if the request is for a BootstrapConfigTemplate or an InfrastructureMachineTemplate - // of one of the configured MachineDeploymentClasses or MachinePoolClasses. - if selector.MatchResources.MachineDeploymentClass != nil || selector.MatchResources.MachinePoolClass != nil { + // of one of the configured MachineDeploymentClasses. + if selector.MatchResources.MachineDeploymentClass != nil { // MachineDeployment.spec.template.spec.bootstrap.configRef or // MachineDeployment.spec.template.spec.infrastructureRef holds the BootstrapConfigTemplate or // InfrastructureMachineTemplate. @@ -184,7 +184,11 @@ func matchesSelector(req *runtimehooksv1.GeneratePatchesRequestItem, templateVar } } } + } + // Check if the request is for a BootstrapConfigTemplate or an InfrastructureMachineTemplate + // of one of the configured MachinePoolClasses. + if selector.MatchResources.MachinePoolClass != nil { if req.HolderReference.Kind == "MachinePool" && (req.HolderReference.FieldPath == "spec.template.spec.bootstrap.configRef" || req.HolderReference.FieldPath == "spec.template.spec.infrastructureRef") { diff --git a/internal/controllers/topology/cluster/patches/variables/variables.go b/internal/controllers/topology/cluster/patches/variables/variables.go index 6b467cc81d2b..ae16173d7d10 100644 --- a/internal/controllers/topology/cluster/patches/variables/variables.go +++ b/internal/controllers/topology/cluster/patches/variables/variables.go @@ -148,7 +148,7 @@ type MachineDeploymentBuiltins struct { // Bootstrap is the value of the .spec.template.spec.bootstrap field of the MachineDeployment. Bootstrap *MachineBootstrapBuiltins `json:"bootstrap,omitempty"` - // InfrastructureRef is the value of the .spec.template.spec.bootstrap field of the MachineDeployment. + // InfrastructureRef is the value of the .spec.template.spec.infrastructureRef field of the MachineDeployment. InfrastructureRef *MachineInfrastructureRefBuiltins `json:"infrastructureRef,omitempty"` } @@ -181,7 +181,7 @@ type MachinePoolBuiltins struct { // Bootstrap is the value of the .spec.template.spec.bootstrap field of the MachinePool. Bootstrap *MachineBootstrapBuiltins `json:"bootstrap,omitempty"` - // InfrastructureRef is the value of the .spec.template.spec.bootstrap field of the MachinePool. + // InfrastructureRef is the value of the .spec.template.spec.infrastructureRef field of the MachinePool. InfrastructureRef *MachineInfrastructureRefBuiltins `json:"infrastructureRef,omitempty"` }