From 0cc58e8b48ba10cba68daf056beffea7ebfbc423 Mon Sep 17 00:00:00 2001 From: lubedacht <132355999+lubedacht@users.noreply.github.com> Date: Tue, 23 Jul 2024 13:51:14 +0200 Subject: [PATCH] :sparkles: allow mutation of control plane endpoint (#187) **What is the purpose of this pull request/Why do we need it?** We want to allow users to change the control plane endpoint if needed. **Description of changes:** Removes the CEL validation that will prevent an update to the control plane endpoint **Special notes for your reviewer:** **Checklist:** - [x] Unit Tests added - [x] Includes [emojis](https://github.com/kubernetes-sigs/kubebuilder-release-tools?tab=readme-ov-file#kubebuilder-project-versioning) --- api/v1alpha1/ionoscloudcluster_types.go | 3 +-- api/v1alpha1/ionoscloudcluster_types_test.go | 26 +++++-------------- ...e.cluster.x-k8s.io_ionoscloudclusters.yaml | 7 +++-- ...r.x-k8s.io_ionoscloudclustertemplates.yaml | 7 +++-- 4 files changed, 13 insertions(+), 30 deletions(-) diff --git a/api/v1alpha1/ionoscloudcluster_types.go b/api/v1alpha1/ionoscloudcluster_types.go index 8f3c27b3..2bee17ba 100644 --- a/api/v1alpha1/ionoscloudcluster_types.go +++ b/api/v1alpha1/ionoscloudcluster_types.go @@ -37,8 +37,7 @@ const ( // IonosCloudClusterSpec defines the desired state of IonosCloudCluster. type IonosCloudClusterSpec struct { // ControlPlaneEndpoint represents the endpoint used to communicate with the control plane. - //+kubebuilder:validation:XValidation:rule="self.host == oldSelf.host || oldSelf.host == ''",message="control plane endpoint host cannot be updated" - //+kubebuilder:validation:XValidation:rule="self.port == oldSelf.port || oldSelf.port == 0",message="control plane endpoint port cannot be updated" + // +kubebuilder:validation:XValidation:rule="size(self.host) == 0 && self.port == 0 || self.port > 0 && self.port < 65536",message="port must be within 1-65535" // // TODO(gfariasalves): as of now, IP must be provided by the user as we still don't insert the // provider-provided block IP into the kube-vip manifest. diff --git a/api/v1alpha1/ionoscloudcluster_types_test.go b/api/v1alpha1/ionoscloudcluster_types_test.go index a0e3ad8e..a7c99c72 100644 --- a/api/v1alpha1/ionoscloudcluster_types_test.go +++ b/api/v1alpha1/ionoscloudcluster_types_test.go @@ -104,34 +104,20 @@ var _ = Describe("IonosCloudCluster", func() { }) When("trying to update the control plane endpoint", func() { - It("should fail if the host is already set", func() { + It("should fail when attempting to set an invalid port number", func() { cluster := defaultCluster() Expect(k8sClient.Create(context.Background(), cluster)).To(Succeed()) - cluster.Spec.ControlPlaneEndpoint.Host = newValueStr - Expect(k8sClient.Update(context.Background(), cluster)).ToNot(Succeed()) - }) - It("should work if the endpoint host is not set", func() { - cluster := defaultCluster() - cluster.Spec.ControlPlaneEndpoint.Host = "" - Expect(k8sClient.Create(context.Background(), cluster)).To(Succeed()) - - cluster.Spec.ControlPlaneEndpoint.Host = newValueStr - Expect(k8sClient.Update(context.Background(), cluster)).To(Succeed()) + cluster.Spec.ControlPlaneEndpoint.Port = 0 + Expect(k8sClient.Update(context.Background(), cluster)). + Should(MatchError(ContainSubstring("port must be within 1-65535"))) }) - It("should fail if the port is already set", func() { + It("should not fail when updating the endpoint correctly", func() { cluster := defaultCluster() Expect(k8sClient.Create(context.Background(), cluster)).To(Succeed()) cluster.Spec.ControlPlaneEndpoint.Port = 1234 - Expect(k8sClient.Update(context.Background(), cluster)).ToNot(Succeed()) - }) - It("should work if the endpoint port is not set", func() { - cluster := defaultCluster() - cluster.Spec.ControlPlaneEndpoint.Port = 0 - Expect(k8sClient.Create(context.Background(), cluster)).To(Succeed()) - - cluster.Spec.ControlPlaneEndpoint.Port = 4657 + cluster.Spec.ControlPlaneEndpoint.Host = "example.org" Expect(k8sClient.Update(context.Background(), cluster)).To(Succeed()) }) }) diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_ionoscloudclusters.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_ionoscloudclusters.yaml index ec4be741..da2fbd77 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_ionoscloudclusters.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_ionoscloudclusters.yaml @@ -77,10 +77,9 @@ spec: - port type: object x-kubernetes-validations: - - message: control plane endpoint host cannot be updated - rule: self.host == oldSelf.host || oldSelf.host == '' - - message: control plane endpoint port cannot be updated - rule: self.port == oldSelf.port || oldSelf.port == 0 + - message: port must be within 1-65535 + rule: size(self.host) == 0 && self.port == 0 || self.port > 0 && + self.port < 65536 credentialsRef: description: CredentialsRef is a reference to the secret containing the credentials to access the IONOS Cloud API. diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_ionoscloudclustertemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_ionoscloudclustertemplates.yaml index a5f4453a..24b5b6d3 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_ionoscloudclustertemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_ionoscloudclustertemplates.yaml @@ -69,10 +69,9 @@ spec: - port type: object x-kubernetes-validations: - - message: control plane endpoint host cannot be updated - rule: self.host == oldSelf.host || oldSelf.host == '' - - message: control plane endpoint port cannot be updated - rule: self.port == oldSelf.port || oldSelf.port == 0 + - message: port must be within 1-65535 + rule: size(self.host) == 0 && self.port == 0 || self.port + > 0 && self.port < 65536 credentialsRef: description: CredentialsRef is a reference to the secret containing the credentials to access the IONOS Cloud API.