Make control plane endpoint default registration method

Signed-off-by: Danil-Grigorev <danil.grigorev@suse.com>
This commit is contained in:
Danil-Grigorev 2024-08-27 14:13:46 +02:00
parent 7b6bbba12a
commit 51a4233c99
No known key found for this signature in database
GPG Key ID: 7C96CE1776C81090
7 changed files with 15 additions and 7 deletions

View File

@ -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.

View File

@ -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"),
)
}

View File

@ -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"),
)
}

View File

@ -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.

View File

@ -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

View File

@ -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)

View File

@ -53,6 +53,10 @@ func TestNewRegistrationMethod(t *testing.T) {
name: "control-plane-endpoint",
expectError: false,
},
{
name: "",
expectError: false,
},
{
name: "unknownmethod",
expectError: true,