-
Notifications
You must be signed in to change notification settings - Fork 249
[Multi_K8s-Plugin] Baseline Clean #6607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Warashi
merged 8 commits into
pipe-cd:master
from
mohammedfirdouss:feat/k8s-multi-baseline-clean
Mar 28, 2026
+499
−0
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1e37586
feat: add K8S_BASELINE_CLEAN stage for baseline resource removal
mohammedfirdouss 11fcbe8
feat: implement K8S_BASELINE_CLEAN stage for baseline resource manage…
mohammedfirdouss 7d2b13c
feat: add baseline clean test data with and without create service
mohammedfirdouss 54f4091
Merge branch 'master' into feat/k8s-multi-baseline-clean
mohammedfirdouss 71e519c
Merge branch 'master' into feat/k8s-multi-baseline-clean
mohammedfirdouss 03c2483
fix: resolve merge conflicts with primary rollout PR
mohammedfirdouss c9f5d45
fix: resolve merge conflicts with baseline rollout PR
mohammedfirdouss fc2f429
fix: respect multiTarget kubectl version in baselineClean
mohammedfirdouss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -235,3 +235,95 @@ func generateBaselineManifests(appCfg *kubeconfig.KubernetesApplicationSpec, man | |
|
|
||
| return baselineManifests, nil | ||
| } | ||
|
|
||
| func (p *Plugin) executeK8sMultiBaselineCleanStage(ctx context.Context, input *sdk.ExecuteStageInput[kubeconfig.KubernetesApplicationSpec], dts []*sdk.DeployTarget[kubeconfig.KubernetesDeployTargetConfig]) sdk.StageStatus { | ||
| lp := input.Client.LogPersister() | ||
|
|
||
| cfg, err := input.Request.TargetDeploymentSource.AppConfig() | ||
| if err != nil { | ||
| lp.Errorf("Failed while decoding application config (%v)", err) | ||
| return sdk.StageStatusFailure | ||
| } | ||
|
|
||
| deployTargetMap := make(map[string]*sdk.DeployTarget[kubeconfig.KubernetesDeployTargetConfig], len(dts)) | ||
| for _, dt := range dts { | ||
| deployTargetMap[dt.Name] = dt | ||
| } | ||
|
|
||
| type targetConfig struct { | ||
| deployTarget *sdk.DeployTarget[kubeconfig.KubernetesDeployTargetConfig] | ||
| multiTarget *kubeconfig.KubernetesMultiTarget | ||
| } | ||
|
|
||
| targetConfigs := make([]targetConfig, 0, len(dts)) | ||
| if len(cfg.Spec.Input.MultiTargets) == 0 { | ||
| for _, dt := range dts { | ||
| targetConfigs = append(targetConfigs, targetConfig{deployTarget: dt}) | ||
| } | ||
| } else { | ||
| for _, mt := range cfg.Spec.Input.MultiTargets { | ||
| dt, ok := deployTargetMap[mt.Target.Name] | ||
| if !ok { | ||
| lp.Infof("Ignore multi target '%s': not matched any deployTarget", mt.Target.Name) | ||
| continue | ||
| } | ||
| targetConfigs = append(targetConfigs, targetConfig{deployTarget: dt, multiTarget: &mt}) | ||
| } | ||
| } | ||
|
|
||
| eg, ctx := errgroup.WithContext(ctx) | ||
| for _, tc := range targetConfigs { | ||
| eg.Go(func() error { | ||
| lp.Infof("Start cleaning BASELINE variant on target %s", tc.deployTarget.Name) | ||
| if err := p.baselineClean(ctx, input, tc.deployTarget, tc.multiTarget, cfg); err != nil { | ||
| return fmt.Errorf("failed to clean BASELINE variant on target %s: %w", tc.deployTarget.Name, err) | ||
| } | ||
| return nil | ||
| }) | ||
| } | ||
|
|
||
| if err := eg.Wait(); err != nil { | ||
| lp.Errorf("Failed while cleaning BASELINE variant (%v)", err) | ||
| return sdk.StageStatusFailure | ||
| } | ||
|
|
||
| return sdk.StageStatusSuccess | ||
| } | ||
|
|
||
| func (p *Plugin) baselineClean( | ||
| ctx context.Context, | ||
| input *sdk.ExecuteStageInput[kubeconfig.KubernetesApplicationSpec], | ||
| dt *sdk.DeployTarget[kubeconfig.KubernetesDeployTargetConfig], | ||
| multiTarget *kubeconfig.KubernetesMultiTarget, | ||
| cfg *sdk.ApplicationConfig[kubeconfig.KubernetesApplicationSpec], | ||
| ) error { | ||
| lp := input.Client.LogPersister() | ||
|
|
||
| var ( | ||
| appCfg = cfg.Spec | ||
| variantLabel = appCfg.VariantLabel.Key | ||
| baselineVariant = appCfg.VariantLabel.BaselineValue | ||
| ) | ||
|
|
||
| toolRegistry := toolregistry.NewRegistry(input.Client.ToolRegistry()) | ||
|
|
||
| // Resolve kubectl version: multiTarget > spec > deployTarget | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yes! |
||
| kubectlVersion := cmp.Or(appCfg.Input.KubectlVersion, dt.Config.KubectlVersion) | ||
| if multiTarget != nil { | ||
| kubectlVersion = cmp.Or(multiTarget.KubectlVersion, kubectlVersion) | ||
| } | ||
|
|
||
| kubectlPath, err := toolRegistry.Kubectl(ctx, kubectlVersion) | ||
| if err != nil { | ||
| return fmt.Errorf("failed while getting kubectl tool: %w", err) | ||
| } | ||
|
|
||
| kubectl := provider.NewKubectl(kubectlPath) | ||
| applier := provider.NewApplier(kubectl, appCfg.Input, dt.Config, input.Logger) | ||
|
|
||
| if err := deleteVariantResources(ctx, lp, kubectl, dt.Config.KubeConfigPath, applier, input.Request.Deployment.ApplicationID, variantLabel, baselineVariant); err != nil { | ||
| return fmt.Errorf("unable to remove baseline resources: %w", err) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.