Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ServerSelectors for MetalMachine #28

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions api/v1alpha1/common_types.go

This file was deleted.

2 changes: 1 addition & 1 deletion api/v1alpha1/metalmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 6 additions & 23 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
76 changes: 39 additions & 37 deletions docs/api-reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,21 @@ string
</tr>
<tr>
<td>
<code>image</code><br/>
<em>
string
</em>
</td>
<td>
<p>Image specifies the boot image to be used for the server.</p>
</td>
</tr>
<tr>
<td>
<code>serverSelector</code><br/>
<em>
<a href="#infrastructure.cluster.x-k8s.io/v1alpha1.ServerSelector">
ServerSelector
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#labelselector-v1-meta">
Kubernetes meta/v1.LabelSelector
</a>
</em>
</td>
Expand Down Expand Up @@ -265,10 +276,21 @@ string
</tr>
<tr>
<td>
<code>image</code><br/>
<em>
string
</em>
</td>
<td>
<p>Image specifies the boot image to be used for the server.</p>
</td>
</tr>
<tr>
<td>
<code>serverSelector</code><br/>
<em>
<a href="#infrastructure.cluster.x-k8s.io/v1alpha1.ServerSelector">
ServerSelector
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#labelselector-v1-meta">
Kubernetes meta/v1.LabelSelector
</a>
</em>
</td>
Expand Down Expand Up @@ -475,10 +497,21 @@ string
</tr>
<tr>
<td>
<code>image</code><br/>
<em>
string
</em>
</td>
<td>
<p>Image specifies the boot image to be used for the server.</p>
</td>
</tr>
<tr>
<td>
<code>serverSelector</code><br/>
<em>
<a href="#infrastructure.cluster.x-k8s.io/v1alpha1.ServerSelector">
ServerSelector
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#labelselector-v1-meta">
Kubernetes meta/v1.LabelSelector
</a>
</em>
</td>
Expand Down Expand Up @@ -523,37 +556,6 @@ MetalMachineTemplateResource
</tr>
</tbody>
</table>
<h3 id="infrastructure.cluster.x-k8s.io/v1alpha1.ServerSelector">ServerSelector
</h3>
<p>
(<em>Appears on:</em><a href="#infrastructure.cluster.x-k8s.io/v1alpha1.MetalMachineSpec">MetalMachineSpec</a>)
</p>
<div>
<p>ServerSelector specifies matching criteria for labels on Server.
This is used to claim specific Server types for a Machine</p>
</div>
<table>
<thead>
<tr>
<th>Field</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>matchLabels</code><br/>
<em>
map[string]string
</em>
</td>
<td>
<em>(Optional)</em>
<p>Key/value pairs of labels that must exist on a chosen Server</p>
</td>
</tr>
</tbody>
</table>
<hr/>
<p><em>
Generated with <code>gen-crd-api-reference-docs</code>
Expand Down
16 changes: 2 additions & 14 deletions internal/controller/metalmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Loading