Skip to content

Commit 8e06dcc

Browse files
Merge pull request #418 from Danil-Grigorev/reg-method-default
Make control plane endpoint default registration method
2 parents 05ffb70 + 137e293 commit 8e06dcc

File tree

12 files changed

+217
-21
lines changed

12 files changed

+217
-21
lines changed

controlplane/api/v1beta1/rke2controlplane_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ type RKE2ControlPlaneSpec struct {
7777
NodeDrainTimeout *metav1.Duration `json:"nodeDrainTimeout,omitempty"`
7878

7979
// RegistrationMethod is the method to use for registering nodes into the RKE2 cluster.
80-
// +kubebuilder:validation:Enum=internal-first;internal-only-ips;external-only-ips;address;control-plane-endpoint
80+
// +kubebuilder:validation:Enum=internal-first;internal-only-ips;external-only-ips;address;control-plane-endpoint;""
8181
// +optional
82-
RegistrationMethod RegistrationMethod `json:"registrationMethod"`
82+
RegistrationMethod RegistrationMethod `json:"registrationMethod,omitempty"`
8383

8484
// RegistrationAddress is an explicit address to use when registering a node. This is required if
8585
// the registration type is "address". Its for scenarios where a load-balancer or VIP is used.

controlplane/api/v1beta1/rke2controlplane_webhook.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,10 @@ func (r *RKE2ControlPlane) ValidateUpdate(old runtime.Object) (admission.Warning
8585
allErrs = append(allErrs, bootstrapv1.ValidateRKE2ConfigSpec(r.Name, &r.Spec.RKE2ConfigSpec)...)
8686
allErrs = append(allErrs, r.validateCNI()...)
8787

88-
if r.Spec.RegistrationMethod != oldControlplane.Spec.RegistrationMethod {
88+
oldSet := oldControlplane.Spec.RegistrationMethod != ""
89+
if oldSet && r.Spec.RegistrationMethod != oldControlplane.Spec.RegistrationMethod {
8990
allErrs = append(allErrs,
90-
field.Invalid(field.NewPath("spec", "registrationMethod"), r.Spec.RegistrationMethod, "field is immutable"),
91+
field.Invalid(field.NewPath("spec", "registrationMethod"), r.Spec.RegistrationMethod, "field value is immutable once set"),
9192
)
9293
}
9394

controlplane/api/v1beta1/rke2controlplanetemplate_webhook.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ func (r *RKE2ControlPlaneTemplate) ValidateUpdate(old runtime.Object) (admission
8181
allErrs = append(allErrs, bootstrapv1.ValidateRKE2ConfigSpec(r.Name, &r.Spec.Template.Spec.RKE2ConfigSpec)...)
8282
allErrs = append(allErrs, r.validateCNI()...)
8383

84-
if r.Spec.Template.Spec.RegistrationMethod != oldControlplane.Spec.Template.Spec.RegistrationMethod {
84+
oldSet := oldControlplane.Spec.Template.Spec.RegistrationMethod != ""
85+
if oldSet && r.Spec.Template.Spec.RegistrationMethod != oldControlplane.Spec.Template.Spec.RegistrationMethod {
8586
allErrs = append(allErrs,
86-
field.Invalid(field.NewPath("spec", "registrationMethod"), r.Spec.Template.Spec.RegistrationMethod, "field is immutable"),
87+
field.Invalid(field.NewPath("spec", "registrationMethod"), r.Spec.Template.Spec.RegistrationMethod, "field value is immutable once set"),
8788
)
8889
}
8990

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,6 +1949,7 @@ spec:
19491949
- external-only-ips
19501950
- address
19511951
- control-plane-endpoint
1952+
- ""
19521953
type: string
19531954
replicas:
19541955
description: Replicas is the number of replicas for the Control Plane.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ spec:
782782
- external-only-ips
783783
- address
784784
- control-plane-endpoint
785+
- ""
785786
type: string
786787
replicas:
787788
description: Replicas is the number of replicas for the Control

pkg/registration/registration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func NewRegistrationMethod(method string) (GetRegistrationAddresses, error) {
4343
return registrationMethodWithFilter(filterExternalOnly), nil
4444
case "address":
4545
return registrationMethodAddress, nil
46-
case "control-plane-endpoint":
46+
case "control-plane-endpoint", "":
4747
return registrationMethodControlPlaneEndpoint, nil
4848
default:
4949
return nil, fmt.Errorf("unsupported registration method: %s", method)

pkg/registration/registration_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ func TestNewRegistrationMethod(t *testing.T) {
5353
name: "control-plane-endpoint",
5454
expectError: false,
5555
},
56+
{
57+
name: "",
58+
expectError: false,
59+
},
5660
{
5761
name: "unknownmethod",
5862
expectError: true,

samples/aws/cluster-template.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ spec:
136136
backupConfig:
137137
retention: "10"
138138
scheduleCron: "*/15 * * * *"
139-
registrationMethod: control-plane-endpoint
140139
rolloutStrategy:
141140
type: "RollingUpdate"
142141
rollingUpdate:

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ spec:
159159
disableComponents:
160160
kubernetesComponents: [ "cloudController"]
161161
nodeDrainTimeout: 2m
162-
registrationMethod: "control-plane-endpoint"
163162
rolloutStrategy:
164163
type: "RollingUpdate"
165164
rollingUpdate:

test/e2e/config/e2e_conf.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,23 @@ providers:
4444
new: "--leader-elect=false"
4545
- old: --metrics-addr=127.0.0.1:8080
4646
new: --metrics-addr=:8080
47+
- name: docker-updated
48+
type: InfrastructureProvider
49+
versions:
50+
- name: "v1.7.2"
51+
value: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.7.2/infrastructure-components-development.yaml"
52+
type: "url"
53+
contract: v1beta1
54+
files:
55+
- sourcePath: "../data/infrastructure/cluster-template-docker-updated.yaml"
56+
- sourcePath: "../data/shared/v1beta1/metadata.yaml"
57+
replacements:
58+
- old: "imagePullPolicy: Always"
59+
new: "imagePullPolicy: IfNotPresent"
60+
- old: "--leader-elect"
61+
new: "--leader-elect=false"
62+
- old: --metrics-addr=127.0.0.1:8080
63+
new: --metrics-addr=:8080
4764
- name: rke2-control-plane
4865
type: ControlPlaneProvider
4966
versions:

0 commit comments

Comments
 (0)