Skip to content

Commit

Permalink
[envtest]Cover reconfiguration cases
Browse files Browse the repository at this point in the history
  • Loading branch information
gibizer authored and openshift-merge-robot committed Sep 22, 2023
1 parent 98b1b73 commit 10eaade
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/functional/placementapi_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})

})
})

0 comments on commit 10eaade

Please sign in to comment.