Skip to content

feat(plugins): plugin controller deletion lifecycle#2014

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

feat(plugins): plugin controller deletion lifecycle#2014
Zaggy21 wants to merge 12 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

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
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
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 added 5 commits May 27, 2026 10:53
… 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>
@Zaggy21 Zaggy21 force-pushed the feat/plugin-controller-deletion-lifecycle branch from 70a4ec6 to 58bfaf8 Compare May 27, 2026 08:53
IvoGoman
IvoGoman previously approved these changes May 28, 2026
Comment thread internal/controller/plugin/plugin_controller_flux.go Outdated
Comment thread internal/controller/plugin/plugin_controller_flux.go Outdated
Comment thread e2e/plugin/scenarios/flux_controller.go Outdated

// 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) {
Copy link
Copy Markdown
Contributor

@abhijith-darshan abhijith-darshan May 28, 2026

Choose a reason for hiding this comment

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

Why do we need a dedicated scenario? 😄

Every scenario should satisfy this

Copy link
Copy Markdown
Contributor Author

@Zaggy21 Zaggy21 May 28, 2026

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So to simplify -

During the clean up of every scenario -

  • Expect that the HelmRelease is also gone
  • in Existing failing scenarios - Expect both Plugin and HelmRelease remain.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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>
@Zaggy21 Zaggy21 requested a review from abhijith-darshan May 28, 2026 13:01
Comment thread e2e/plugin/e2e_test.go Outdated
Copy link
Copy Markdown
Contributor

@abhijith-darshan abhijith-darshan left a comment

Choose a reason for hiding this comment

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

minor improvements

Comment thread internal/controller/plugin/plugin_controller_flux.go Outdated
Comment thread internal/controller/plugin/plugin_controller_flux.go Outdated
Comment thread internal/controller/plugin/plugin_controller_flux.go Outdated
Zaggy21 added 2 commits June 1, 2026 11:15
…wn assertions

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>
Zaggy21 added 2 commits June 1, 2026 11:41
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>
@Zaggy21 Zaggy21 requested a review from abhijith-darshan June 3, 2026 14:02
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

4 participants