feat(plugins): plugin controller deletion lifecycle#2014
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves the Plugin controller’s deletion lifecycle to ensure the greenhouse.sap/cleanup finalizer is not removed until Flux has fully completed the HelmRelease uninstall (and to surface Flux uninstall failures on the Plugin status), preventing orphaned Helm resources.
Changes:
- Update
EnsureFluxDeletedto wait for the FluxHelmReleaseto be fully removed, requeue while uninstall is pending, and surfaceUninstallFailedvia Plugin conditions. - Skip Plugin reconciliation when the target Cluster is already being deleted (via
DeletionTimestamp) by requeueing and setting a deletion-related condition. - Add unit + e2e coverage for pending uninstall and uninstall-failure paths during Plugin deletion.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/controller/plugin/util.go | Adds handling to defer reconciliation when the referenced Cluster is already being deleted. |
| internal/controller/plugin/plugin_controller_flux.go | Holds Plugin finalizer until HelmRelease deletion completes; detects Flux uninstall failure and reports it on Plugin conditions. |
| internal/controller/plugin/plugin_controller_flux_test.go | Adds unit tests for pending uninstall and uninstall failure condition surfacing. |
| e2e/plugin/scenarios/flux_controller.go | Adds an e2e scenario that injects HelmRelease uninstall failure and verifies Plugin behavior/finalizer retention. |
| e2e/plugin/e2e_test.go | Registers the new deletion lifecycle e2e scenario. |
| api/v1alpha1/plugin_types.go | Introduces HelmReleaseUninstallPendingReason condition reason constant. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
internal/controller/plugin/plugin_controller_flux_test.go:456
- This Eventually block appends the Flux finalizer on every retry without checking if it’s already present. If the closure retries after a successful update, the finalizer can be duplicated. Consider guarding the append with a contains-check (or use an idempotent patch) to keep the test stable.
By("adding the Flux finalizer to simulate a real Flux-managed HelmRelease")
Eventually(func(g Gomega) {
err := test.K8sClient.Get(test.Ctx, releaseKey, helmRelease)
g.Expect(err).ToNot(HaveOccurred())
helmRelease.Finalizers = append(helmRelease.Finalizers, helmv2.HelmReleaseFinalizer)
err = test.K8sClient.Update(test.Ctx, helmRelease)
g.Expect(err).ToNot(HaveOccurred())
}).Should(Succeed())
… Flux failures as status conditions On-behalf-of: @SAP krzysztof.zagorski@sap.com Signed-off-by: Zaggy21 <k.zaggy@gmail.com>
…stamp On-behalf-of: @SAP krzysztof.zagorski@sap.com Signed-off-by: Zaggy21 <k.zaggy@gmail.com>
…ng Plugin deletion (wip) On-behalf-of: @SAP krzysztof.zagorski@sap.com Signed-off-by: Zaggy21 <k.zaggy@gmail.com>
On-behalf-of: @SAP krzysztof.zagorski@sap.com Signed-off-by: Zaggy21 <k.zaggy@gmail.com>
…finalizer in tests On-behalf-of: @SAP krzysztof.zagorski@sap.com Signed-off-by: Zaggy21 <k.zaggy@gmail.com>
70a4ec6 to
58bfaf8
Compare
|
|
||
| // FluxControllerPluginDeletionLifecycle verifies that the Plugin controller holds its finalizer | ||
| // and surfaces the HelmRelease uninstall failure as a status condition when Flux reports an error. | ||
| func FluxControllerPluginDeletionLifecycle(ctx context.Context, adminClient client.Client, env *shared.TestEnv, remoteClusterName, teamName string) { |
There was a problem hiding this comment.
Why do we need a dedicated scenario? 😄
Every scenario should satisfy this
There was a problem hiding this comment.
It's to cover the HelmRelease uninstall failure scenario as per the acceptance criterion. Can't really add it seamlessly to other scenarios. The basic check for "Plugin stays pending until HelmRelease is deleted" could be added to other scenarios, but it doesn't add much value. It's also covered in unit tests. I'd leave it as it is.
There was a problem hiding this comment.
We cannot rely on unit tests. There is no work load in there to guarantee clean ups.
There is already failing plugin e2e scenarios... in one of those we can expect HelmRelease to remain which should already be the case.
A dedicated scenario just for this is not needed.
There was a problem hiding this comment.
So to simplify -
During the clean up of every scenario -
- Expect that the
HelmReleaseis also gone - in Existing failing scenarios - Expect both
PluginandHelmReleaseremain.
There was a problem hiding this comment.
Done. Removed the dedicated scenario and added assertions to FluxControllerPluginDependencies's teardown: after deleting the presets, it verifies both Plugins are marked for deletion before the global plugin is removed and Flux can complete the uninstall.
On-behalf-of: @SAP krzysztof.zagorski@sap.com Signed-off-by: Zaggy21 <k.zaggy@gmail.com>
On-behalf-of: @SAP krzysztof.zagorski@sap.com Signed-off-by: Zaggy21 <k.zaggy@gmail.com>
abhijith-darshan
left a comment
There was a problem hiding this comment.
minor improvements
Description
Fixes the plugin deletion lifecycle where the greenhouse.sap/cleanup finalizer was removed before Flux had finished running helm uninstall, potentially leaving orphaned Helm resources on the target cluster.
EnsureFluxDeleted now:
What type of PR is this? (check all applicable)
Related Tickets & Documents
Added tests?
Adds unit tests covering the pending and failure paths, and an e2e scenario that injects an uninstall failure via a test finalizer on the HelmRelease and verifies the Plugin surfaces the condition and retains its finalizer until resolved.
Added to documentation?
Checklist