diff --git a/api/v1alpha1/common_types.go b/api/v1alpha1/common_types.go deleted file mode 100644 index d34b8d8..0000000 --- a/api/v1alpha1/common_types.go +++ /dev/null @@ -1,12 +0,0 @@ -// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and IronCore contributors -// SPDX-License-Identifier: Apache-2.0 - -package v1alpha1 - -// ServerSelector specifies matching criteria for labels on Server. -// This is used to claim specific Server types for a Machine -type ServerSelector struct { - // Key/value pairs of labels that must exist on a chosen Server - // +optional - MatchLabels map[string]string `json:"matchLabels,omitempty"` -} diff --git a/api/v1alpha1/metalmachine_types.go b/api/v1alpha1/metalmachine_types.go index 11b180a..e6e2970 100644 --- a/api/v1alpha1/metalmachine_types.go +++ b/api/v1alpha1/metalmachine_types.go @@ -32,7 +32,7 @@ type MetalMachineSpec struct { // ServerSelector specifies matching criteria for labels on Servers. // This is used to claim specific Server types for a MetalMachine. // +optional - ServerSelector ServerSelector `json:"serverSelector,omitempty"` + ServerSelector *metav1.LabelSelector `json:"serverSelector,omitempty"` } // MetalMachineStatus defines the observed state of MetalMachine diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index b868f3e..918fd69 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -8,6 +8,7 @@ package v1alpha1 import ( + "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/errors" @@ -177,7 +178,11 @@ func (in *MetalMachineSpec) DeepCopyInto(out *MetalMachineSpec) { *out = new(string) **out = **in } - in.ServerSelector.DeepCopyInto(&out.ServerSelector) + if in.ServerSelector != nil { + in, out := &in.ServerSelector, &out.ServerSelector + *out = new(v1.LabelSelector) + (*in).DeepCopyInto(*out) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MetalMachineSpec. @@ -305,25 +310,3 @@ func (in *MetalMachineTemplateSpec) DeepCopy() *MetalMachineTemplateSpec { in.DeepCopyInto(out) return out } - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ServerSelector) DeepCopyInto(out *ServerSelector) { - *out = *in - if in.MatchLabels != nil { - in, out := &in.MatchLabels, &out.MatchLabels - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServerSelector. -func (in *ServerSelector) DeepCopy() *ServerSelector { - if in == nil { - return nil - } - out := new(ServerSelector) - in.DeepCopyInto(out) - return out -} diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_metalmachines.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_metalmachines.yaml index 5edd0a5..cbbb383 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_metalmachines.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_metalmachines.yaml @@ -51,13 +51,49 @@ spec: ServerSelector specifies matching criteria for labels on Servers. This is used to claim specific Server types for a MetalMachine. 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 + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic matchLabels: additionalProperties: type: string - description: Key/value pairs of labels that must exist on a chosen - Server + 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 + x-kubernetes-map-type: atomic required: - image type: object diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_metalmachinetemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_metalmachinetemplates.yaml index 069bf25..e0427c8 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_metalmachinetemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_metalmachinetemplates.yaml @@ -84,13 +84,49 @@ spec: ServerSelector specifies matching criteria for labels on Servers. This is used to claim specific Server types for a MetalMachine. 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 + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic matchLabels: additionalProperties: type: string - description: Key/value pairs of labels that must exist - on a chosen Server + 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 + x-kubernetes-map-type: atomic required: - image type: object diff --git a/docs/api-reference/api.md b/docs/api-reference/api.md index 9ecac63..ab1210c 100644 --- a/docs/api-reference/api.md +++ b/docs/api-reference/api.md @@ -205,10 +205,21 @@ string
image
Image specifies the boot image to be used for the server.
+serverSelector
image
Image specifies the boot image to be used for the server.
+serverSelector
image
Image specifies the boot image to be used for the server.
+serverSelector
-(Appears on:MetalMachineSpec) -
-ServerSelector specifies matching criteria for labels on Server. -This is used to claim specific Server types for a Machine
-Field | -Description | -
---|---|
-matchLabels - -map[string]string - - |
-
-(Optional)
- Key/value pairs of labels that must exist on a chosen Server - |
-
Generated with gen-crd-api-reference-docs
diff --git a/internal/controller/metalmachine_controller.go b/internal/controller/metalmachine_controller.go
index ae900e1..452556a 100644
--- a/internal/controller/metalmachine_controller.go
+++ b/internal/controller/metalmachine_controller.go
@@ -297,23 +297,11 @@ func (r *MetalMachineReconciler) applyServerClaim(ctx context.Context, log *logr
IgnitionSecretRef: &corev1.LocalObjectReference{
Name: ignitionsecret.Name,
},
- Image: metalmachine.Spec.Image,
+ Image: metalmachine.Spec.Image,
+ ServerSelector: metalmachine.Spec.ServerSelector,
},
}
- // TODO: Define proper contract for ServerSelectors.
- serverSelector := metav1.LabelSelector{
- MatchLabels: map[string]string{
- "clusterapi-workload": "",
- },
- }
- if _, exists := metalmachine.Labels["cluster.x-k8s.io/control-plane"]; exists {
- serverSelector.MatchLabels = map[string]string{
- "clusterapi-controlplane": "",
- }
- }
- serverClaimObj.Spec.ServerSelector = &serverSelector
-
if err := controllerutil.SetControllerReference(metalmachine, serverClaimObj, r.Client.Scheme()); err != nil {
return nil, fmt.Errorf("failed to set ControllerReference: %w", err)
}