Skip to content

[Multi_K8s-Plugin] Baseline Clean#6607

Merged
Warashi merged 8 commits intopipe-cd:masterfrom
mohammedfirdouss:feat/k8s-multi-baseline-clean
Mar 28, 2026
Merged

[Multi_K8s-Plugin] Baseline Clean#6607
Warashi merged 8 commits intopipe-cd:masterfrom
mohammedfirdouss:feat/k8s-multi-baseline-clean

Conversation

@mohammedfirdouss
Copy link
Copy Markdown
Contributor

What this PR does: Adds the K8S_BASELINE_CLEAN stage to the kubernetes_multicluster plugin.
After a canary analysis window ends, whether the decision was to promote or roll back, the baseline resources created by K8S_BASELINE_ROLLOUT need to be removed. This stage does exactly that: it finds and deletes all resources labeled pipecd.dev/variant=baseline for the application, across all target clusters in parallel. Without this stage, baseline pods would run indefinitely after the pipeline completes, wasting cluster resources and cluttering kubectl get deployments.

Why we need it: K8S_BASELINE_ROLLOUT creates temporary resources (simple-baseline deployment, optionally a simple-baseline service) so you can compare the current version against canary side-by-side. Once the analysis window is over, those resources are useless. This stage removes them cleanly and in the correct order (Services before Workloads) to avoid routing traffic to terminating pods.

Which issue(s) this PR fixes: #6446

Does this PR introduce a user-facing change?:

  • How are users affected by this change: Users can now add K8S_BASELINE_CLEAN to their pipeline config to automatically remove baseline resources after canary analysis completes. Without this stage they would need to manually delete the baseline deployment and service.

  • Is this breaking change: No.

  • How to migrate (if breaking change): N/A

Signed-off-by: Mohammed Firdous <124298708+mohammedfirdouss@users.noreply.github.com>
…ment

Signed-off-by: Mohammed Firdous <124298708+mohammedfirdouss@users.noreply.github.com>
Signed-off-by: Mohammed Firdous <124298708+mohammedfirdouss@users.noreply.github.com>
@mohammedfirdouss
Copy link
Copy Markdown
Contributor Author

mohammedfirdouss commented Mar 28, 2026

@Warashi I am fixing the merge conflicts on baseline clean too, would wait for your review on this as well. Thanks :)

Copy link
Copy Markdown
Member

@Warashi Warashi left a comment

Choose a reason for hiding this comment

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

Please check the kubectl version resolve handling?


toolRegistry := toolregistry.NewRegistry(input.Client.ToolRegistry())

kubectlPath, err := toolRegistry.Kubectl(ctx, cmp.Or(appCfg.Input.KubectlVersion, dt.Config.KubectlVersion))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm sorry if I missed the same thing in other PRs, but I think we should use the KubectlVersion in multiTarget config if it's defined.
WDYT?

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.

Hm. You are right, the baselineClean wasn't respecting the multiTarget.KubectlVersion. I will apply the same priority order as baselineRollout: multiTarget.KubectlVersion > spec.KubectlVersion > deployTarget.KubectlVersion.

@mohammedfirdouss mohammedfirdouss force-pushed the feat/k8s-multi-baseline-clean branch from 0a6d1f6 to 7200bb2 Compare March 28, 2026 02:58
Merge upstream/master (baseline rollout PR pipe-cd#6606) into feat/k8s-multi-baseline-clean.
Combined baseline rollout and baseline clean functions in baseline.go and baseline_test.go.
Both stages (K8S_BASELINE_ROLLOUT and K8S_BASELINE_CLEAN) are now present in pipeline.go,
plugin.go, and config/application.go.

Signed-off-by: Mohammed Firdous <124298708+mohammedfirdouss@users.noreply.github.com>
@mohammedfirdouss mohammedfirdouss force-pushed the feat/k8s-multi-baseline-clean branch from 7200bb2 to c9f5d45 Compare March 28, 2026 02:59
Pass multiTarget through to baselineClean and apply the same
kubectl version priority as baselineRollout:
multiTarget.KubectlVersion > spec.KubectlVersion > deployTarget.KubectlVersion

Signed-off-by: Mohammed Firdous <124298708+mohammedfirdouss@users.noreply.github.com>

type targetConfig struct {
deployTarget *sdk.DeployTarget[kubeconfig.KubernetesDeployTargetConfig]
multiTarget *kubeconfig.KubernetesMultiTarget
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.

@Warashi Please check from here, If I am on track.


toolRegistry := toolregistry.NewRegistry(input.Client.ToolRegistry())

// Resolve kubectl version: multiTarget > spec > deployTarget
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.

Ah yes!

Copy link
Copy Markdown
Member

@Warashi Warashi left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you!

@Warashi Warashi enabled auto-merge (squash) March 28, 2026 03:08
@Warashi Warashi merged commit 482e8c6 into pipe-cd:master Mar 28, 2026
45 checks passed
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 33.04%. Comparing base (ca43c2f) to head (fc2f429).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6607      +/-   ##
==========================================
+ Coverage   29.21%   33.04%   +3.82%     
==========================================
  Files         582        4     -578     
  Lines       62028      115   -61913     
==========================================
- Hits        18121       38   -18083     
+ Misses      42515       76   -42439     
+ Partials     1392        1    -1391     
Flag Coverage Δ
. ?
.-pkg-app-pipedv1-plugin-analysis ?
.-pkg-app-pipedv1-plugin-ecs ?
.-pkg-app-pipedv1-plugin-kubernetes ?
.-pkg-app-pipedv1-plugin-kubernetes_multicluster ?
.-pkg-app-pipedv1-plugin-scriptrun ?
.-pkg-app-pipedv1-plugin-terraform ?
.-pkg-app-pipedv1-plugin-wait 33.04% <ø> (ø)
.-pkg-app-pipedv1-plugin-waitapproval ?
.-pkg-plugin-sdk ?
.-tool-actions-gh-release ?
.-tool-actions-plan-preview ?
.-tool-codegen-protoc-gen-auth ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

2 participants