Skip to content

Commit 6c69383

Browse files
authored
Merge pull request #542 from anmazzotti/deprecate_infrastructure_ref
Deprecate infrastructure ref
2 parents c2badd9 + baaec2c commit 6c69383

20 files changed

+108
-73
lines changed

controlplane/api/v1beta1/rke2controlplane_types.go

+5
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,17 @@ type RKE2ControlPlaneSpec struct {
7272

7373
// InfrastructureRef is a required reference to a custom resource
7474
// offered by an infrastructure provider.
75+
// This field is deprecated. Use `.machineTemplate.infrastructureRef` instead.
76+
// +optional
77+
// +kubebuilder:deprecatedversion:warning="Use `.machineTemplate.infrastructureRef` instead"
7578
InfrastructureRef corev1.ObjectReference `json:"infrastructureRef"`
7679

7780
// NodeDrainTimeout is the total amount of time that the controller will spend on draining a controlplane node
7881
// The default value is 0, meaning that the node can be drained without any time limitations.
7982
// NOTE: NodeDrainTimeout is different from `kubectl drain --timeout`
83+
// This field is deprecated. Use `.machineTemplate.nodeDrainTimeout` instead.
8084
// +optional
85+
// +kubebuilder:deprecatedversion:warning="Use `.machineTemplate.nodeDrainTimeout` instead"
8186
NodeDrainTimeout *metav1.Duration `json:"nodeDrainTimeout,omitempty"`
8287

8388
// RegistrationMethod is the method to use for registering nodes into the RKE2 cluster.

controlplane/api/v1beta1/rke2controlplane_webhook.go

+24
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ var _ webhook.Defaulter = &RKE2ControlPlane{}
4848
// Default implements webhook.Defaulter so a webhook will be registered for the type.
4949
func (r *RKE2ControlPlane) Default() {
5050
bootstrapv1.DefaultRKE2ConfigSpec(&r.Spec.RKE2ConfigSpec)
51+
52+
// Defaults missing MachineTemplate.InfrastructureRef to Spec.InfrastructureRef
53+
if len(r.Spec.MachineTemplate.InfrastructureRef.Name) == 0 {
54+
r.Spec.MachineTemplate.InfrastructureRef = r.Spec.InfrastructureRef
55+
}
56+
57+
// Defaults missing MachineTemplate.NodeDrainTimeout to Spec.NodeDrainTimeout
58+
if r.Spec.MachineTemplate.NodeDrainTimeout == nil {
59+
r.Spec.MachineTemplate.NodeDrainTimeout = r.Spec.NodeDrainTimeout
60+
}
5161
}
5262

5363
//+kubebuilder:webhook:path=/validate-controlplane-cluster-x-k8s-io-v1beta1-rke2controlplane,mutating=false,failurePolicy=fail,sideEffects=None,groups=controlplane.cluster.x-k8s.io,resources=rke2controlplanes,verbs=create;update,versions=v1beta1,name=vrke2controlplane.kb.io,admissionReviewVersions=v1
@@ -63,6 +73,7 @@ func (r *RKE2ControlPlane) ValidateCreate() (admission.Warnings, error) {
6373
allErrs = append(allErrs, bootstrapv1.ValidateRKE2ConfigSpec(r.Name, &r.Spec.RKE2ConfigSpec)...)
6474
allErrs = append(allErrs, r.validateCNI()...)
6575
allErrs = append(allErrs, r.validateRegistrationMethod()...)
76+
allErrs = append(allErrs, r.validateMachineTemplate()...)
6677

6778
if len(allErrs) == 0 {
6879
return nil, nil
@@ -84,6 +95,7 @@ func (r *RKE2ControlPlane) ValidateUpdate(old runtime.Object) (admission.Warning
8495

8596
allErrs = append(allErrs, bootstrapv1.ValidateRKE2ConfigSpec(r.Name, &r.Spec.RKE2ConfigSpec)...)
8697
allErrs = append(allErrs, r.validateCNI()...)
98+
allErrs = append(allErrs, r.validateMachineTemplate()...)
8799

88100
oldSet := oldControlplane.Spec.RegistrationMethod != ""
89101
if oldSet && r.Spec.RegistrationMethod != oldControlplane.Spec.RegistrationMethod {
@@ -131,3 +143,15 @@ func (r *RKE2ControlPlane) validateRegistrationMethod() field.ErrorList {
131143

132144
return allErrs
133145
}
146+
147+
func (r *RKE2ControlPlane) validateMachineTemplate() field.ErrorList {
148+
var allErrs field.ErrorList
149+
150+
if r.Spec.MachineTemplate.InfrastructureRef.Name == "" && r.Spec.InfrastructureRef.Name == "" {
151+
allErrs = append(allErrs,
152+
field.Invalid(field.NewPath("spec", "machineTemplate", "infrastructureRef"),
153+
r.Spec.MachineTemplate.InfrastructureRef, "machineTemplate is required"))
154+
}
155+
156+
return allErrs
157+
}

controlplane/config/crd/bases/controlplane.cluster.x-k8s.io_rke2controlplanes.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1595,6 +1595,7 @@ spec:
15951595
description: |-
15961596
InfrastructureRef is a required reference to a custom resource
15971597
offered by an infrastructure provider.
1598+
This field is deprecated. Use `.machineTemplate.infrastructureRef` instead.
15981599
properties:
15991600
apiVersion:
16001601
description: API version of the referent.
@@ -1769,6 +1770,7 @@ spec:
17691770
NodeDrainTimeout is the total amount of time that the controller will spend on draining a controlplane node
17701771
The default value is 0, meaning that the node can be drained without any time limitations.
17711772
NOTE: NodeDrainTimeout is different from `kubectl drain --timeout`
1773+
This field is deprecated. Use `.machineTemplate.nodeDrainTimeout` instead.
17721774
type: string
17731775
postRKE2Commands:
17741776
description: PostRKE2Commands specifies extra commands to run after
@@ -2436,7 +2438,6 @@ spec:
24362438
pattern: (v\d\.\d{2}\.\d+\+rke2r\d)|^$
24372439
type: string
24382440
required:
2439-
- infrastructureRef
24402441
- rolloutStrategy
24412442
type: object
24422443
status:

controlplane/config/crd/bases/controlplane.cluster.x-k8s.io_rke2controlplanetemplates.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ spec:
436436
description: |-
437437
InfrastructureRef is a required reference to a custom resource
438438
offered by an infrastructure provider.
439+
This field is deprecated. Use `.machineTemplate.infrastructureRef` instead.
439440
properties:
440441
apiVersion:
441442
description: API version of the referent.
@@ -610,6 +611,7 @@ spec:
610611
NodeDrainTimeout is the total amount of time that the controller will spend on draining a controlplane node
611612
The default value is 0, meaning that the node can be drained without any time limitations.
612613
NOTE: NodeDrainTimeout is different from `kubectl drain --timeout`
614+
This field is deprecated. Use `.machineTemplate.nodeDrainTimeout` instead.
613615
type: string
614616
postRKE2Commands:
615617
description: PostRKE2Commands specifies extra commands to
@@ -1296,7 +1298,6 @@ spec:
12961298
pattern: (v\d\.\d{2}\.\d+\+rke2r\d)|^$
12971299
type: string
12981300
required:
1299-
- infrastructureRef
13001301
- rolloutStrategy
13011302
type: object
13021303
required:

controlplane/internal/controllers/scale.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,12 @@ func (r *RKE2ControlPlaneReconciler) cloneConfigsAndGenerateMachine(
329329
UID: rcp.UID,
330330
}
331331

332-
rcp.Spec.InfrastructureRef.Namespace = cmp.Or(rcp.Spec.InfrastructureRef.Namespace, rcp.Namespace)
332+
rcp.Spec.MachineTemplate.InfrastructureRef.Namespace = cmp.Or(rcp.Spec.MachineTemplate.InfrastructureRef.Namespace, rcp.Namespace)
333333

334334
// Clone the infrastructure template
335335
infraRef, err := external.CreateFromTemplate(ctx, &external.CreateFromTemplateInput{
336336
Client: r.Client,
337-
TemplateRef: &rcp.Spec.InfrastructureRef,
337+
TemplateRef: &rcp.Spec.MachineTemplate.InfrastructureRef,
338338
Namespace: rcp.Namespace,
339339
OwnerRef: infraCloneOwner,
340340
ClusterName: cluster.Name,
@@ -460,7 +460,7 @@ func (r *RKE2ControlPlaneReconciler) generateMachine(
460460
ConfigRef: bootstrapRef,
461461
},
462462
FailureDomain: failureDomain,
463-
NodeDrainTimeout: rcp.Spec.NodeDrainTimeout,
463+
NodeDrainTimeout: rcp.Spec.MachineTemplate.NodeDrainTimeout,
464464
},
465465
}
466466

examples/aws/cluster-template.yaml

+6-5
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,12 @@ spec:
123123
- sudo hostnamectl set-hostname $(curl -s http://169.254.169.254/1.0/meta-data/hostname)
124124
agentConfig:
125125
airGapped: true
126-
infrastructureRef:
127-
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
128-
kind: AWSMachineTemplate
129-
name: ${CLUSTER_NAME}-control-plane
130-
nodeDrainTimeout: 2m
126+
machineTemplate:
127+
infrastructureRef:
128+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
129+
kind: AWSMachineTemplate
130+
name: ${CLUSTER_NAME}-control-plane
131+
nodeDrainTimeout: 2m
131132
replicas: ${CONTROL_PLANE_MACHINE_COUNT}
132133
serverConfig:
133134
cloudProviderName: external

examples/docker/air-gapped/rke2-sample.yaml

+6-5
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@ spec:
5454
kubeProxy:
5555
extraEnv:
5656
hello: world
57-
infrastructureRef:
58-
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
59-
kind: DockerMachineTemplate
60-
name: controlplane
61-
nodeDrainTimeout: 2m
57+
machineTemplate:
58+
infrastructureRef:
59+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
60+
kind: DockerMachineTemplate
61+
name: controlplane
62+
nodeDrainTimeout: 2m
6263
---
6364
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
6465
kind: DockerMachineTemplate

examples/docker/cis-profile/rke2-sample.yaml

+6-5
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@ spec:
5050
- --anonymous-auth=true
5151
agentConfig:
5252
cisProfile: ${CIS_PROFILE}
53-
infrastructureRef:
54-
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
55-
kind: DockerMachineTemplate
56-
name: controlplane
57-
nodeDrainTimeout: 2m
53+
machineTemplate:
54+
infrastructureRef:
55+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
56+
kind: DockerMachineTemplate
57+
name: controlplane
58+
nodeDrainTimeout: 2m
5859
---
5960
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
6061
kind: DockerMachineTemplate

examples/docker/clusterclass/clusterclass-quick-start.yaml

+2-5
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,15 @@ metadata:
151151
spec:
152152
template:
153153
spec:
154-
infrastructureRef:
155-
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
156-
kind: DockerMachineTemplate
157-
name: rke2-class-control-plane
158154
serverConfig:
159155
cni: calico
160156
kubeAPIServer:
161157
extraArgs:
162158
- --anonymous-auth=true
163159
disableComponents:
164160
kubernetesComponents: [ "cloudController"]
165-
nodeDrainTimeout: 2m
161+
machineTemplate:
162+
nodeDrainTimeout: 2m
166163
rolloutStrategy:
167164
type: "RollingUpdate"
168165
rollingUpdate:

examples/docker/disable-components/rke2-sample.yaml

+6-5
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,19 @@ spec:
4545
replicas: ${CONTROL_PLANE_MACHINE_COUNT}
4646
agentConfig:
4747
version: ${KUBERNETES_VERSION}+rke2r1
48-
infrastructureRef:
49-
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
50-
kind: DockerMachineTemplate
51-
name: controlplane
5248
serverConfig:
5349
kubeAPIServer:
5450
extraArgs:
5551
- --anonymous-auth=true
5652
disableComponents:
5753
pluginComponents:
5854
- "rke2-ingress-nginx"
59-
nodeDrainTimeout: 2m
55+
machineTemplate:
56+
infrastructureRef:
57+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
58+
kind: DockerMachineTemplate
59+
name: controlplane
60+
nodeDrainTimeout: 2m
6061
---
6162
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
6263
kind: DockerMachineTemplate

examples/docker/enable-multus/rke2-sample.yaml

+6-5
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ spec:
5151
kubeAPIServer:
5252
extraArgs:
5353
- --anonymous-auth=true
54-
infrastructureRef:
55-
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
56-
kind: DockerMachineTemplate
57-
name: controlplane
58-
nodeDrainTimeout: 2m
54+
machineTemplate:
55+
infrastructureRef:
56+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
57+
kind: DockerMachineTemplate
58+
name: controlplane
59+
nodeDrainTimeout: 2m
5960
---
6061
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
6162
kind: DockerMachineTemplate

examples/docker/enable-multus/rke2controlplane-test.yaml

+6-5
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ spec:
88
version: v1.24.11+rke2r1
99
serverConfig:
1010
cniMultusEnable: true
11-
infrastructureRef:
12-
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
13-
kind: DockerMachineTemplate
14-
name: controlplane
15-
nodeDrainTimeout: 2m
11+
machineTemplate:
12+
infrastructureRef:
13+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
14+
kind: DockerMachineTemplate
15+
name: controlplane
16+
nodeDrainTimeout: 2m

examples/docker/kube-vip/rke2-sample.yaml

+6-5
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@ spec:
4949
version: ${KUBERNETES_VERSION}+rke2r1
5050
serverConfig:
5151
cni: calico
52-
infrastructureRef:
53-
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
54-
kind: DockerMachineTemplate
55-
name: controlplane
56-
nodeDrainTimeout: 2m
52+
machineTemplate:
53+
infrastructureRef:
54+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
55+
kind: DockerMachineTemplate
56+
name: controlplane
57+
nodeDrainTimeout: 2m
5758
registrationMethod: "address"
5859
registrationAddress: "${REGISTRATION_VIP}"
5960
preRKE2Commands:

examples/docker/online-default/cluster-template.yaml

+7-6
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,12 @@ spec:
5757
kubeAPIServer:
5858
extraArgs:
5959
- --anonymous-auth=true
60-
infrastructureRef:
61-
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
62-
kind: DockerMachineTemplate
63-
name: controlplane
64-
nodeDrainTimeout: 2m
60+
machineTemplate:
61+
infrastructureRef:
62+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
63+
kind: DockerMachineTemplate
64+
name: controlplane
65+
nodeDrainTimeout: 2m
6566
---
6667
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
6768
kind: DockerMachineTemplate
@@ -186,4 +187,4 @@ data:
186187
http-check expect status 403
187188
{{range $server, $backend := .BackendServers}}
188189
server {{ $server }} {{ $backend.Address }}:9345 check check-ssl verify none
189-
{{- end}}
190+
{{- end}}

examples/docker/priv-registries/rke2-sample.yaml

+7-6
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,12 @@ spec:
6262
kind: Secret
6363
namespace: ${NAMESPACE}
6464
name: registry-cert
65-
infrastructureRef:
66-
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
67-
kind: DockerMachineTemplate
68-
name: controlplane
69-
nodeDrainTimeout: 2m
65+
machineTemplate:
66+
infrastructureRef:
67+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
68+
kind: DockerMachineTemplate
69+
name: controlplane
70+
nodeDrainTimeout: 2m
7071
---
7172
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
7273
kind: DockerMachineTemplate
@@ -227,4 +228,4 @@ data:
227228
http-check expect status 403
228229
{{range $server, $backend := .BackendServers}}
229230
server {{ $server }} {{ $backend.Address }}:9345 check check-ssl verify none
230-
{{- end}}
231+
{{- end}}

examples/metal3/sample-cluster.yaml

+5-4
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,11 @@ metadata:
7070
name: ${CLUSTER_NAME}
7171
namespace: ${NAMESPACE}
7272
spec:
73-
infrastructureRef:
74-
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
75-
kind: Metal3MachineTemplate
76-
name: ${CLUSTER_NAME}-controlplane
73+
machineTemplate:
74+
infrastructureRef:
75+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
76+
kind: Metal3MachineTemplate
77+
name: ${CLUSTER_NAME}-controlplane
7778
replicas: 1
7879
agentConfig:
7980
kubelet:

examples/vmware/cluster-template.yaml

+6-5
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,12 @@ spec:
156156
type: File
157157
name: kubeconfig
158158
replicas: ${CONTROL_PLANE_MACHINE_COUNT}
159-
infrastructureRef:
160-
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
161-
kind: VSphereMachineTemplate
162-
name: vsphere-controlplane
163-
nodeDrainTimeout: 2m
159+
machineTemplate:
160+
infrastructureRef:
161+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
162+
kind: VSphereMachineTemplate
163+
name: vsphere-controlplane
164+
nodeDrainTimeout: 2m
164165
preRKE2Commands:
165166
- sleep 30 #fix to give OS time to become ready
166167
version: ${RKE2_VERSION}

pkg/rke2/control_plane.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (c *ControlPlane) Version() *string {
124124

125125
// InfrastructureRef returns the RKE2ControlPlane's infrastructure template.
126126
func (c *ControlPlane) InfrastructureRef() *corev1.ObjectReference {
127-
return &c.RCP.Spec.InfrastructureRef
127+
return &c.RCP.Spec.MachineTemplate.InfrastructureRef
128128
}
129129

130130
// AsOwnerReference returns an owner reference to the RKE2ControlPlane.

pkg/rke2/machine_filters.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ func matchesTemplateClonedFrom(infraConfigs map[string]*unstructured.Unstructure
146146
}
147147

148148
// Check if the machine's infrastructure reference has been created from the current RCP infrastructure template.
149-
if clonedFromName != rcp.Spec.InfrastructureRef.Name ||
150-
clonedFromGroupKind != rcp.Spec.InfrastructureRef.GroupVersionKind().GroupKind().String() {
149+
if clonedFromName != rcp.Spec.MachineTemplate.InfrastructureRef.Name ||
150+
clonedFromGroupKind != rcp.Spec.MachineTemplate.InfrastructureRef.GroupVersionKind().GroupKind().String() {
151151
return false
152152
}
153153

0 commit comments

Comments
 (0)