diff --git a/controlplane/api/v1beta1/rke2controlplane_types.go b/controlplane/api/v1beta1/rke2controlplane_types.go index 6c56308..b853d32 100644 --- a/controlplane/api/v1beta1/rke2controlplane_types.go +++ b/controlplane/api/v1beta1/rke2controlplane_types.go @@ -77,9 +77,9 @@ type RKE2ControlPlaneSpec struct { NodeDrainTimeout *metav1.Duration `json:"nodeDrainTimeout,omitempty"` // RegistrationMethod is the method to use for registering nodes into the RKE2 cluster. - // +kubebuilder:validation:Enum=internal-first;internal-only-ips;external-only-ips;address;control-plane-endpoint + // +kubebuilder:validation:Enum=internal-first;internal-only-ips;external-only-ips;address;control-plane-endpoint;"" // +optional - RegistrationMethod RegistrationMethod `json:"registrationMethod"` + RegistrationMethod RegistrationMethod `json:"registrationMethod,omitempty"` // RegistrationAddress is an explicit address to use when registering a node. This is required if // the registration type is "address". Its for scenarios where a load-balancer or VIP is used. diff --git a/controlplane/api/v1beta1/rke2controlplane_webhook.go b/controlplane/api/v1beta1/rke2controlplane_webhook.go index 475ed14..7a9d110 100644 --- a/controlplane/api/v1beta1/rke2controlplane_webhook.go +++ b/controlplane/api/v1beta1/rke2controlplane_webhook.go @@ -85,9 +85,10 @@ func (r *RKE2ControlPlane) ValidateUpdate(old runtime.Object) (admission.Warning allErrs = append(allErrs, bootstrapv1.ValidateRKE2ConfigSpec(r.Name, &r.Spec.RKE2ConfigSpec)...) allErrs = append(allErrs, r.validateCNI()...) - if r.Spec.RegistrationMethod != oldControlplane.Spec.RegistrationMethod { + oldSet := oldControlplane.Spec.RegistrationMethod != "" + if oldSet && r.Spec.RegistrationMethod != oldControlplane.Spec.RegistrationMethod { allErrs = append(allErrs, - field.Invalid(field.NewPath("spec", "registrationMethod"), r.Spec.RegistrationMethod, "field is immutable"), + field.Invalid(field.NewPath("spec", "registrationMethod"), r.Spec.RegistrationMethod, "field value is immutable once set"), ) } diff --git a/controlplane/api/v1beta1/rke2controlplanetemplate_webhook.go b/controlplane/api/v1beta1/rke2controlplanetemplate_webhook.go index 0da528b..be18d0a 100644 --- a/controlplane/api/v1beta1/rke2controlplanetemplate_webhook.go +++ b/controlplane/api/v1beta1/rke2controlplanetemplate_webhook.go @@ -81,9 +81,10 @@ func (r *RKE2ControlPlaneTemplate) ValidateUpdate(old runtime.Object) (admission allErrs = append(allErrs, bootstrapv1.ValidateRKE2ConfigSpec(r.Name, &r.Spec.Template.Spec.RKE2ConfigSpec)...) allErrs = append(allErrs, r.validateCNI()...) - if r.Spec.Template.Spec.RegistrationMethod != oldControlplane.Spec.Template.Spec.RegistrationMethod { + oldSet := oldControlplane.Spec.Template.Spec.RegistrationMethod != "" + if oldSet && r.Spec.Template.Spec.RegistrationMethod != oldControlplane.Spec.Template.Spec.RegistrationMethod { allErrs = append(allErrs, - field.Invalid(field.NewPath("spec", "registrationMethod"), r.Spec.Template.Spec.RegistrationMethod, "field is immutable"), + field.Invalid(field.NewPath("spec", "registrationMethod"), r.Spec.Template.Spec.RegistrationMethod, "field value is immutable once set"), ) } diff --git a/controlplane/config/crd/bases/controlplane.cluster.x-k8s.io_rke2controlplanes.yaml b/controlplane/config/crd/bases/controlplane.cluster.x-k8s.io_rke2controlplanes.yaml index 7d8f7e0..5449122 100644 --- a/controlplane/config/crd/bases/controlplane.cluster.x-k8s.io_rke2controlplanes.yaml +++ b/controlplane/config/crd/bases/controlplane.cluster.x-k8s.io_rke2controlplanes.yaml @@ -1949,6 +1949,7 @@ spec: - external-only-ips - address - control-plane-endpoint + - "" type: string replicas: description: Replicas is the number of replicas for the Control Plane. diff --git a/controlplane/config/crd/bases/controlplane.cluster.x-k8s.io_rke2controlplanetemplates.yaml b/controlplane/config/crd/bases/controlplane.cluster.x-k8s.io_rke2controlplanetemplates.yaml index 5de035a..8adafa1 100644 --- a/controlplane/config/crd/bases/controlplane.cluster.x-k8s.io_rke2controlplanetemplates.yaml +++ b/controlplane/config/crd/bases/controlplane.cluster.x-k8s.io_rke2controlplanetemplates.yaml @@ -782,6 +782,7 @@ spec: - external-only-ips - address - control-plane-endpoint + - "" type: string replicas: description: Replicas is the number of replicas for the Control diff --git a/pkg/registration/registration.go b/pkg/registration/registration.go index 8c23510..dccc004 100644 --- a/pkg/registration/registration.go +++ b/pkg/registration/registration.go @@ -43,7 +43,7 @@ func NewRegistrationMethod(method string) (GetRegistrationAddresses, error) { return registrationMethodWithFilter(filterExternalOnly), nil case "address": return registrationMethodAddress, nil - case "control-plane-endpoint": + case "control-plane-endpoint", "": return registrationMethodControlPlaneEndpoint, nil default: return nil, fmt.Errorf("unsupported registration method: %s", method) diff --git a/pkg/registration/registration_test.go b/pkg/registration/registration_test.go index 9f8055b..b28d412 100644 --- a/pkg/registration/registration_test.go +++ b/pkg/registration/registration_test.go @@ -53,6 +53,10 @@ func TestNewRegistrationMethod(t *testing.T) { name: "control-plane-endpoint", expectError: false, }, + { + name: "", + expectError: false, + }, { name: "unknownmethod", expectError: true,