Skip to content

[Multi_K8s-Plugin] Prune orphaned resources on rollback#6748

Open
mohammedfirdouss wants to merge 2 commits intopipe-cd:masterfrom
mohammedfirdouss:feat/multicluster-rollback-pruning
Open

[Multi_K8s-Plugin] Prune orphaned resources on rollback#6748
mohammedfirdouss wants to merge 2 commits intopipe-cd:masterfrom
mohammedfirdouss:feat/multicluster-rollback-pruning

Conversation

@mohammedfirdouss
Copy link
Copy Markdown
Contributor

@mohammedfirdouss mohammedfirdouss commented May 7, 2026

What this PR does / Why we need it:

Implements rollback pruning in the kubernetes_multicluster plugin. When a deployment pipeline fails mid-way, the ROLLBACK stage re-applies the last known good manifests but any new resource introduced by the failed deployment (e.g. a ConfigMap or Service already applied to the cluster) was never deleted, leaving orphaned resources that cause permanent live-state drift.

This PR resolves the explicit TODO in rollback.go:

// TODO: prune resources which don't exist in the running manifests but exist in the target manifests.
// This occurs when the user adds a new resource and the deployment pipeline fails.

After applying the running manifests and cleaning up canary/baseline variants, rollback now:

  1. Loads the target (failed) manifests from TargetDeploymentSource
  2. Identifies resources present in target but absent from running (findOrphanedKeys)
  3. Deletes those resources from the cluster (pruneOrphanedResources)

Errors during target manifest loading are non-fatal, logged and skipped so a Helm/Kustomize rendering failure cannot prevent the rollback from completing.

Which issue(s) this PR fixes:

Part of #6446

How was this tested:

Unit tests added to deployment/misc_test.go for findOrphanedKeys covering:

  • No orphans when target equals running
  • All resources orphaned when running is empty
  • New resource in target not present in running is orphaned
  • Resource only in running is not pruned
  • Multiple orphaned resources

Note on single-cluster plugin:

The same TODO exists in pkg/app/pipedv1/plugin/kubernetes/deployment/rollback.go. That plugin is out of scope for this PR.

Signed-off-by: Mohammed Firdous <124298708+mohammedfirdouss@users.noreply.github.com>
@mohammedfirdouss mohammedfirdouss force-pushed the feat/multicluster-rollback-pruning branch from 6edf250 to 41df9e4 Compare May 7, 2026 22:44
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.

1 participant