From 0b2fdbfb079980601ed569b9985a28f79535b2ad Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Tue, 11 Jul 2023 22:13:28 +0900 Subject: [PATCH] Fix defaulting of Replicas spec Currently the default values are ignored because these specs are set to 0 by webhook. Update the type from int32 to *int32 to avoid that behavior and ensure the expected default values are used. --- api/v1beta1/horizon_types.go | 2 +- api/v1beta1/zz_generated.deepcopy.go | 5 +++++ pkg/horizon/deployment.go | 2 +- tests/functional/horizon_controller_test.go | 8 +++++--- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/api/v1beta1/horizon_types.go b/api/v1beta1/horizon_types.go index 09065879..14e7fa44 100644 --- a/api/v1beta1/horizon_types.go +++ b/api/v1beta1/horizon_types.go @@ -42,7 +42,7 @@ type HorizonSpec struct { // +kubebuilder:validation:Maximum=32 // +kubebuilder:validation:Minimum=0 // Replicas of horizon API to run - Replicas int32 `json:"replicas"` + Replicas *int32 `json:"replicas"` // +kubebuilder:validation:Required // Secret containing OpenStack password information for Horizon Secret Key diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index ec8e88b7..b9d9dd43 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -133,6 +133,11 @@ func (in *HorizonRoute) DeepCopy() *HorizonRoute { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *HorizonSpec) DeepCopyInto(out *HorizonSpec) { *out = *in + if in.Replicas != nil { + in, out := &in.Replicas, &out.Replicas + *out = new(int32) + **out = **in + } if in.NodeSelector != nil { in, out := &in.NodeSelector, &out.NodeSelector *out = make(map[string]string, len(*in)) diff --git a/pkg/horizon/deployment.go b/pkg/horizon/deployment.go index 6971637e..d54c19cb 100644 --- a/pkg/horizon/deployment.go +++ b/pkg/horizon/deployment.go @@ -91,7 +91,7 @@ func Deployment(instance *horizonv1.Horizon, configHash string, labels map[strin Selector: &metav1.LabelSelector{ MatchLabels: labels, }, - Replicas: &instance.Spec.Replicas, + Replicas: instance.Spec.Replicas, Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: labels, diff --git a/tests/functional/horizon_controller_test.go b/tests/functional/horizon_controller_test.go index 6a9f8f5d..7d3eeaa9 100644 --- a/tests/functional/horizon_controller_test.go +++ b/tests/functional/horizon_controller_test.go @@ -49,6 +49,7 @@ var _ = Describe("Horizon controller", func() { It("should have the Spec and Status fields initialized", func() { horizon := GetHorizon(horizonName) Expect(horizon.Spec.Secret).Should(Equal("test-osp-secret")) + Expect(*(horizon.Spec.Replicas)).Should(Equal(int32(1))) }) It("should have a finalizer", func() { @@ -230,7 +231,7 @@ var _ = Describe("Horizon controller", func() { }) keystoneAPI := th.CreateKeystoneAPI(namespace) DeferCleanup(th.DeleteKeystoneAPI, keystoneAPI) - th.SimulateDeploymentReadyWithPods(deploymentName, map[string][]string{}) + th.SimulateDeploymentReplicaReady(deploymentName) }) It("should have deployment ready", func() { @@ -248,8 +249,9 @@ var _ = Describe("Horizon controller", func() { ) }) It("should have ReadyCount set", func() { - horizon := GetHorizon(horizonName) - Expect(horizon.Status.ReadyCount).Should(Equal(horizon.Spec.Replicas)) + Eventually(func() int32 { + return GetHorizon(horizonName).Status.ReadyCount + }, timeout, interval).Should(Equal(int32(1))) }) }) })