Skip to content

feat: support patcher removal for label and annotation #1374

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
merged 1 commit into from
Jan 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions pkg/generators/appconfiguration/app_configurations_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,13 @@ func PatchWorkload(workload *v1.Resource, patcher *v1.Patcher) error {
}
// merge labels
for k, v := range patcher.Labels {
// NOTE: we implement value-based map removal by agreeing on a specific value
// `ops://kusionstack.io/remove` as the `remove` operation index for label patcher.
if v == removalVal {
delete(objLabels, k)
continue
}

objLabels[k] = v
}
un.SetLabels(objLabels)
Expand All @@ -315,6 +322,13 @@ func PatchWorkload(workload *v1.Resource, patcher *v1.Patcher) error {
}
// merge labels
for k, v := range patcher.PodLabels {
// NOTE: we implement value-based map removal by agreeing on a specific value
// `ops://kusionstack.io/remove` as the `remove` operation index for pod label patcher.
if v == removalVal {
delete(podLabels, k)
continue
}

podLabels[k] = v
}
err = unstructured.SetNestedStringMap(un.Object, podLabels, "spec", "template", "metadata", "labels")
Expand All @@ -331,6 +345,13 @@ func PatchWorkload(workload *v1.Resource, patcher *v1.Patcher) error {
}
// merge annotations
for k, v := range patcher.Annotations {
// NOTE: we implement value-based map removal by agreeing on a specific value
// `ops://kusionstack.io/remove` as the `remove` operation index for annotation patcher.
if v == removalVal {
delete(objAnnotations, k)
continue
}

objAnnotations[k] = v
}
un.SetAnnotations(objAnnotations)
Expand All @@ -347,6 +368,13 @@ func PatchWorkload(workload *v1.Resource, patcher *v1.Patcher) error {
}
// merge annotations
for k, v := range patcher.PodAnnotations {
// NOTE: we implement value-based map removal by agreeing on a specific value
// `ops://kusionstack.io/remove` as the `remove` operation index for pod annotation patcher.
if v == removalVal {
delete(podAnnotations, k)
continue
}

podAnnotations[k] = v
}
err = unstructured.SetNestedStringMap(un.Object, podAnnotations, "spec", "template", "metadata", "annotations")
Expand Down
Loading