Skip to content

feat(plugins): plugin controller deletion lifecycle#2014

Open
Zaggy21 wants to merge 10 commits into
mainfrom
feat/plugin-controller-deletion-lifecycle
Open

feat(plugins): plugin controller deletion lifecycle#2014
Zaggy21 wants to merge 10 commits into
mainfrom
feat/plugin-controller-deletion-lifecycle

Conversation

@Zaggy21
Copy link
Copy Markdown
Contributor

@Zaggy21 Zaggy21 commented May 21, 2026

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:

  • Issues the delete on the HelmRelease and requeues,
  • If the HelmRelease is still present, checks Flux's ReleasedCondition: an UninstallFailed reason surfaces as HelmUninstallFailedReason on the Plugin; otherwise sets HelmReleaseUninstallPendingReason and relies on the HelmRelease watch to re-trigger reconciliation,
  • Only returns lifecycle.Success (removing the finalizer) once the HelmRelease is gone.

What type of PR is this? (check all applicable)

  • 🍕 Feature
  • 🐛 Bug Fix
  • 📝 Documentation Update
  • 🎨 Style
  • 🧑‍💻 Code Refactor
  • 🔥 Performance Improvements
  • ✅ Test
  • 🤖 Build
  • 🔁 CI
  • 📦 Chore (Release)
  • ⏩ Revert

Related Tickets & Documents

Added tests?

  • 👍 yes
  • 🙅 no, because they aren't needed
  • 🙋 no, because I need help
  • Separate ticket for tests # (issue/pr)

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?

  • 📜 README.md
  • 🤝 Documentation pages updated
  • 🙅 no documentation needed
  • (if applicable) generated OpenAPI docs for CRD changes

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • New and existing unit tests pass locally with my changes

Zaggy21 added 3 commits May 19, 2026 16:29
… 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>
Copilot AI review requested due to automatic review settings May 21, 2026 12:40
@Zaggy21 Zaggy21 requested a review from a team as a code owner May 21, 2026 12:40
@Zaggy21 Zaggy21 linked an issue May 21, 2026 that may be closed by this pull request
4 tasks
@Zaggy21 Zaggy21 changed the title feat(plugin): plugin controller deletion lifecycle feat(plugins): plugin controller deletion lifecycle May 21, 2026
On-behalf-of: @SAP krzysztof.zagorski@sap.com
Signed-off-by: Zaggy21 <k.zaggy@gmail.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 EnsureFluxDeleted to wait for the Flux HelmRelease to be fully removed, requeue while uninstall is pending, and surface UninstallFailed via 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.

Comment thread internal/controller/plugin/util.go Outdated
Comment thread internal/controller/plugin/util.go Outdated
Comment thread internal/controller/plugin/plugin_controller_flux.go Outdated
Zaggy21 added 2 commits May 21, 2026 15:00
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>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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())

Comment thread internal/controller/plugin/util.go Outdated
Comment thread internal/controller/plugin/plugin_controller_flux_test.go Outdated
Zaggy21 and others added 3 commits May 22, 2026 14:43
…finalizer in tests

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT] - Plugin controller deletion lifecycle

2 participants