Skip to content

Commit

Permalink
fix: Allow control plane endpoint updates with empty location (#255) (#…
Browse files Browse the repository at this point in the history
…266)

Cherry-pick of #255 for release v0.5.1

Co-authored-by: Mario Valderrama <15158349+avorima@users.noreply.github.com>
  • Loading branch information
jriedel-ionos and avorima authored Jan 15, 2025
1 parent 45d56a2 commit 77bb231
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion api/v1alpha1/ionoscloudcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const (
IonosCloudClusterKind = "IonosCloudCluster"
)

//+kubebuilder:validation:XValidation:rule="self.controlPlaneEndpoint.host == '' || has(self.location)",message="location is required when controlPlaneEndpoint.host is set"
//+kubebuilder:validation:XValidation:rule="!has(self.loadBalancerProviderRef) || has(self.location)",message="location is required when loadBalancerProviderRef is set"

// IonosCloudClusterSpec defines the desired state of IonosCloudCluster.
type IonosCloudClusterSpec struct {
Expand Down
17 changes: 14 additions & 3 deletions api/v1alpha1/ionoscloudcluster_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,15 @@ var _ = Describe("IonosCloudCluster", func() {
Expect(k8sClient.Create(context.Background(), cluster)).
Should(MatchError(ContainSubstring("credentialsRef.name must be provided")))
})
It("should not allow creating clusters with empty location when ControlPlaneEndpoint host is set", func() {
It("should not allow creating clusters with empty location when loadBalancerProviderRef is set", func() {
cluster := defaultCluster()
cluster.Spec.Location = ""
Expect(k8sClient.Create(context.Background(), cluster)).
Should(MatchError(ContainSubstring("location is required when controlPlaneEndpoint.host is set")))
Should(MatchError(ContainSubstring("location is required when loadBalancerProviderRef is set")))
})
It("should allow creating clusters with empty location when ControlPlaneEndpoint host is not set", func() {
It("should allow creating clusters with empty location and ControlPlaneEndpoint host when loadBalancerProviderRef is not set", func() {
cluster := defaultCluster()
cluster.Spec.LoadBalancerProviderRef = nil
cluster.Spec.Location = ""
cluster.Spec.ControlPlaneEndpoint.Host = ""
Expect(k8sClient.Create(context.Background(), cluster)).To(Succeed())
Expand Down Expand Up @@ -126,6 +127,16 @@ var _ = Describe("IonosCloudCluster", func() {
cluster.Spec.ControlPlaneEndpoint.Host = "example.org"
Expect(k8sClient.Update(context.Background(), cluster)).To(Succeed())
})
It("should not fail when when location is empty and loadBalancerProviderRef is not set", func() {
cluster := defaultCluster()
cluster.Spec.LoadBalancerProviderRef = nil
cluster.Spec.Location = ""
cluster.Spec.ControlPlaneEndpoint.Host = ""
Expect(k8sClient.Create(context.Background(), cluster)).To(Succeed())

cluster.Spec.ControlPlaneEndpoint = defaultCluster().Spec.ControlPlaneEndpoint
Expect(k8sClient.Update(context.Background(), cluster)).To(Succeed())
})
})
})
Context("Status", func() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ spec:
- credentialsRef
type: object
x-kubernetes-validations:
- message: location is required when controlPlaneEndpoint.host is set
rule: self.controlPlaneEndpoint.host == '' || has(self.location)
- message: location is required when loadBalancerProviderRef is set
rule: '!has(self.loadBalancerProviderRef) || has(self.location)'
status:
description: IonosCloudClusterStatus defines the observed state of IonosCloudCluster.
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ spec:
- credentialsRef
type: object
x-kubernetes-validations:
- message: location is required when controlPlaneEndpoint.host
is set
rule: self.controlPlaneEndpoint.host == '' || has(self.location)
- message: location is required when loadBalancerProviderRef is
set
rule: '!has(self.loadBalancerProviderRef) || has(self.location)'
required:
- spec
type: object
Expand Down

0 comments on commit 77bb231

Please sign in to comment.