From 0492c89dc8c23442724d6e86ae6c78225421048c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corentin=20N=C3=A9au?= Date: Mon, 16 Sep 2024 17:13:09 +0200 Subject: [PATCH] Propagate drift correction force mode to Helm rollback (#2836) * Propagate drift correction force mode to Helm This enables drift correction to be forced after the fact, which can help users deal with edge cases such as patching ports on services, a case known not to be supported [1] by Helm. [1]: https://github.com/helm/helm/issues/12974 * Remove service status drift end-to-end test case That test case is now covered in integration tests. --- e2e/drift/drift_test.go | 21 +++++++++++++++---- .../agent/bundle_deployment_drift_test.go | 2 +- internal/helmdeployer/install.go | 3 +++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/e2e/drift/drift_test.go b/e2e/drift/drift_test.go index ca3cc13583..e342b87bf0 100644 --- a/e2e/drift/drift_test.go +++ b/e2e/drift/drift_test.go @@ -200,13 +200,26 @@ var _ = Describe("Drift", Ordered, func() { GinkgoWriter.Print(out) }) - It("Status is modified", func() { + // Note: more accurate checks on status changes are now done in integration tests. + It("Corrects drift when drift correction is set to force", func() { Eventually(func() string { out, _ := k.Namespace(env.Namespace).Get("bundles", bundleName, "-o=jsonpath={.status.conditions[*].message}") return out - }).Should(ContainSubstring(`service.v1 drift/drift-dummy-service modified {"spec":{"ports":[` + - `{"name":"http","port":80,"protocol":"TCP","targetPort":"http-web-svc"},` + - `{"name":"http","port":1234,"protocol":"TCP","targetPort":"http-web-svc"}]}}`)) + }).Should(ContainSubstring(`service.v1 drift/drift-dummy-service modified`)) + + out, err := k.Patch( + "gitrepo", + "drift-correction-test", + "--type=merge", + "-p", + `{"spec":{"correctDrift":{"force": true}}}`, + ) + Expect(err).ToNot(HaveOccurred(), out) + GinkgoWriter.Print(out) + Eventually(func() string { + out, _ := k.Namespace(env.Namespace).Get("bundles", bundleName, "-o=jsonpath={.status.conditions[*].message}") + return out + }).ShouldNot(ContainSubstring(`drift-dummy-service modified`)) }) }) diff --git a/integrationtests/agent/bundle_deployment_drift_test.go b/integrationtests/agent/bundle_deployment_drift_test.go index 0183dcfa69..dd421afae6 100644 --- a/integrationtests/agent/bundle_deployment_drift_test.go +++ b/integrationtests/agent/bundle_deployment_drift_test.go @@ -115,7 +115,7 @@ var _ = Describe("BundleDeployment drift correction", Ordered, func() { })) }) - Context("A release resource is modified", func() { + Context("A release resource is modified", Ordered, func() { It("Receives a modification on a service", func() { svc, err := env.getService(svcName) Expect(err).NotTo(HaveOccurred()) diff --git a/internal/helmdeployer/install.go b/internal/helmdeployer/install.go index 0f4be0253f..829ccd55b8 100644 --- a/internal/helmdeployer/install.go +++ b/internal/helmdeployer/install.go @@ -159,6 +159,9 @@ func (h *Helm) install(ctx context.Context, bundleID string, manifest *manifest. u.TakeOwnership = true u.EnableDNS = !options.Helm.DisableDNS u.Force = options.Helm.Force + if options.CorrectDrift != nil { + u.Force = u.Force || options.CorrectDrift.Force + } u.Atomic = options.Helm.Atomic u.MaxHistory = options.Helm.MaxHistory if u.MaxHistory == 0 {