Skip to content

Commit

Permalink
Make control plane endpoint default registration method
Browse files Browse the repository at this point in the history
Signed-off-by: Danil-Grigorev <danil.grigorev@suse.com>
  • Loading branch information
Danil-Grigorev committed Aug 27, 2024
1 parent 480a96d commit e6f28a0
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 8 deletions.
4 changes: 2 additions & 2 deletions controlplane/api/v1beta1/rke2controlplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions controlplane/api/v1beta1/rke2controlplane_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
)
}

Expand Down
5 changes: 3 additions & 2 deletions controlplane/api/v1beta1/rke2controlplanetemplate_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1947,6 +1947,7 @@ spec:
- external-only-ips
- address
- control-plane-endpoint
- ""
type: string
replicas:
description: Replicas is the number of replicas for the Control Plane.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,7 @@ spec:
- external-only-ips
- address
- control-plane-endpoint
- ""
type: string
replicas:
description: Replicas is the number of replicas for the Control
Expand Down
3 changes: 1 addition & 2 deletions pkg/registration/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package registration

import (
"errors"
"fmt"

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/util/collections"
Expand Down Expand Up @@ -46,7 +45,7 @@ func NewRegistrationMethod(method string) (GetRegistrationAddresses, error) {
case "control-plane-endpoint":
return registrationMethodControlPlaneEndpoint, nil
default:
return nil, fmt.Errorf("unsupported registration method: %s", method)
return registrationMethodControlPlaneEndpoint, nil
}
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/registration/registration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func TestNewRegistrationMethod(t *testing.T) {
name: "control-plane-endpoint",
expectError: false,
},
{
name: "",
expectError: false,
},
{
name: "unknownmethod",
expectError: true,
Expand Down

0 comments on commit e6f28a0

Please sign in to comment.