From 10eaade4b9e069cbb5607f08e04cbba84efe105d Mon Sep 17 00:00:00 2001 From: Balazs Gibizer Date: Mon, 18 Sep 2023 12:19:34 +0200 Subject: [PATCH] [envtest]Cover reconfiguration cases --- .../placementapi_controller_test.go | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tests/functional/placementapi_controller_test.go b/tests/functional/placementapi_controller_test.go index 88de766e..f6339dbc 100644 --- a/tests/functional/placementapi_controller_test.go +++ b/tests/functional/placementapi_controller_test.go @@ -629,5 +629,58 @@ var _ = Describe("PlacementAPI controller", func() { db = th.GetMariaDBDatabase(names.MariaDBDatabaseName) Expect(db.Finalizers).NotTo(ContainElement("PlacementAPI")) }) + + It("updates the deployment if configuration changes", func() { + deployment := th.GetDeployment(names.DeploymentName) + oldConfigHash := GetEnvVarValue(deployment.Spec.Template.Spec.Containers[0].Env, "CONFIG_HASH", "") + Expect(oldConfigHash).NotTo(Equal("")) + cm := th.GetConfigMap(names.ConfigMapName) + Expect(cm.Data["custom.conf"]).ShouldNot(ContainSubstring("debug")) + + Eventually(func(g Gomega) { + placement := GetPlacementAPI(names.PlacementAPIName) + placement.Spec.CustomServiceConfig = "[DEFAULT]/ndebug = true" + + g.Expect(k8sClient.Update(ctx, placement)).Should(Succeed()) + }, timeout, interval).Should(Succeed()) + + Eventually(func(g Gomega) { + deployment := th.GetDeployment(names.DeploymentName) + newConfigHash := GetEnvVarValue(deployment.Spec.Template.Spec.Containers[0].Env, "CONFIG_HASH", "") + g.Expect(newConfigHash).NotTo(Equal("")) + g.Expect(newConfigHash).NotTo(Equal(oldConfigHash)) + + cm := th.GetConfigMap(names.ConfigMapName) + g.Expect(cm.Data["custom.conf"]).Should(ContainSubstring("debug = true")) + }, timeout, interval).Should(Succeed()) + }) + + It("updates the deployment if password changes", func() { + deployment := th.GetDeployment(names.DeploymentName) + oldConfigHash := GetEnvVarValue(deployment.Spec.Template.Spec.Containers[0].Env, "CONFIG_HASH", "") + Expect(oldConfigHash).NotTo(Equal("")) + + th.UpdateSecret( + types.NamespacedName{Namespace: namespace, Name: SecretName}, + "PlacementPassword", []byte("foobar")) + + logger.Info("Reconfigured") + + Eventually(func(g Gomega) { + deployment := th.GetDeployment(names.DeploymentName) + newConfigHash := GetEnvVarValue(deployment.Spec.Template.Spec.Containers[0].Env, "CONFIG_HASH", "") + g.Expect(newConfigHash).NotTo(Equal("")) + // FIXME(gibi): The placement-operator does not watch the input + // secret so it does not detect that any input is changed. + // Also the password values are not calculated into the input + // hash as they are only applied in the init container + // This should pass when this is fixed + // g.Expect(newConfigHash).NotTo(Equal(oldConfigHash)) + g.Expect(newConfigHash).To(Equal(oldConfigHash)) + // TODO(gibi): once the password is in the generated config + // assert it there + }, timeout, interval).Should(Succeed()) + }) + }) })