diff --git a/config/crd/bases/controlplane.cluster.x-k8s.io_awsmanagedcontrolplanes.yaml b/config/crd/bases/controlplane.cluster.x-k8s.io_awsmanagedcontrolplanes.yaml index c33fd9df99..5527ae1945 100644 --- a/config/crd/bases/controlplane.cluster.x-k8s.io_awsmanagedcontrolplanes.yaml +++ b/config/crd/bases/controlplane.cluster.x-k8s.io_awsmanagedcontrolplanes.yaml @@ -2700,7 +2700,7 @@ spec: version number is supplied then the latest version of Kubernetes that EKS supports will be used. minLength: 2 - pattern: ^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.?$ + pattern: ^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.?(\.0|[1-9][0-9]*)?$ type: string vpcCni: description: VpcCni is used to set configuration options for the VPC diff --git a/controlplane/eks/api/v1beta1/awsmanagedcontrolplane_types.go b/controlplane/eks/api/v1beta1/awsmanagedcontrolplane_types.go index 3be3e756e0..d9625b568a 100644 --- a/controlplane/eks/api/v1beta1/awsmanagedcontrolplane_types.go +++ b/controlplane/eks/api/v1beta1/awsmanagedcontrolplane_types.go @@ -63,7 +63,7 @@ type AWSManagedControlPlaneSpec struct { //nolint: maligned // is supplied then the latest version of Kubernetes that EKS supports // will be used. // +kubebuilder:validation:MinLength:=2 - // +kubebuilder:validation:Pattern:=^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.?$ + // +kubebuilder:validation:Pattern:=^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.?(\.0|[1-9][0-9]*)?$ // +optional Version *string `json:"version,omitempty"` diff --git a/controlplane/eks/api/v1beta1/awsmanagedcontrolplane_webhook.go b/controlplane/eks/api/v1beta1/awsmanagedcontrolplane_webhook.go index 98718f3b01..768406e99b 100644 --- a/controlplane/eks/api/v1beta1/awsmanagedcontrolplane_webhook.go +++ b/controlplane/eks/api/v1beta1/awsmanagedcontrolplane_webhook.go @@ -70,15 +70,6 @@ func parseEKSVersion(raw string) (*version.Version, error) { return version.MustParseGeneric(fmt.Sprintf("%d.%d", v.Major(), v.Minor())), nil } -func normalizeVersion(raw string) (string, error) { - // Normalize version (i.e. remove patch, add "v" prefix) if necessary - eksV, err := parseEKSVersion(raw) - if err != nil { - return "", err - } - return fmt.Sprintf("v%d.%d", eksV.Major(), eksV.Minor()), nil -} - // ValidateCreate will do any extra validation when creating a AWSManagedControlPlane. func (r *AWSManagedControlPlane) ValidateCreate() error { mcpLog.Info("AWSManagedControlPlane validate create", "name", r.Name) @@ -376,16 +367,6 @@ func (r *AWSManagedControlPlane) Default() { } } - // Normalize version (i.e. remove patch, add "v" prefix) if necessary - if r.Spec.Version != nil { - normalizedV, err := normalizeVersion(*r.Spec.Version) - if err != nil { - mcpLog.Error(err, "couldn't parse version") - return - } - r.Spec.Version = &normalizedV - } - infrav1.SetDefaults_Bastion(&r.Spec.Bastion) infrav1.SetDefaults_NetworkSpec(&r.Spec.NetworkSpec) } diff --git a/controlplane/eks/api/v1beta1/awsmanagedcontrolplane_webhook_test.go b/controlplane/eks/api/v1beta1/awsmanagedcontrolplane_webhook_test.go index fe9ea9faf6..3f1baab46b 100644 --- a/controlplane/eks/api/v1beta1/awsmanagedcontrolplane_webhook_test.go +++ b/controlplane/eks/api/v1beta1/awsmanagedcontrolplane_webhook_test.go @@ -105,7 +105,7 @@ func TestDefaultingWebhook(t *testing.T) { resourceNS: "default", expectHash: false, spec: AWSManagedControlPlaneSpec{Version: &vV1_17_1}, - expectSpec: AWSManagedControlPlaneSpec{EKSClusterName: "default_cluster1", Version: &vV1_17, IdentityRef: defaultIdentityRef, Bastion: defaultTestBastion, NetworkSpec: defaultNetworkSpec, TokenMethod: &EKSTokenMethodIAMAuthenticator}, + expectSpec: AWSManagedControlPlaneSpec{EKSClusterName: "default_cluster1", Version: &vV1_17_1, IdentityRef: defaultIdentityRef, Bastion: defaultTestBastion, NetworkSpec: defaultNetworkSpec, TokenMethod: &EKSTokenMethodIAMAuthenticator}, }, { name: "with allowed ip on bastion",