Skip to content

Commit e59a896

Browse files
authored
feat: support patcher removal for label and annotation (#1374)
1 parent 823e9a9 commit e59a896

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

pkg/generators/appconfiguration/app_configurations_generator.go

+28
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,13 @@ func PatchWorkload(workload *v1.Resource, patcher *v1.Patcher) error {
299299
}
300300
// merge labels
301301
for k, v := range patcher.Labels {
302+
// NOTE: we implement value-based map removal by agreeing on a specific value
303+
// `ops://kusionstack.io/remove` as the `remove` operation index for label patcher.
304+
if v == removalVal {
305+
delete(objLabels, k)
306+
continue
307+
}
308+
302309
objLabels[k] = v
303310
}
304311
un.SetLabels(objLabels)
@@ -315,6 +322,13 @@ func PatchWorkload(workload *v1.Resource, patcher *v1.Patcher) error {
315322
}
316323
// merge labels
317324
for k, v := range patcher.PodLabels {
325+
// NOTE: we implement value-based map removal by agreeing on a specific value
326+
// `ops://kusionstack.io/remove` as the `remove` operation index for pod label patcher.
327+
if v == removalVal {
328+
delete(podLabels, k)
329+
continue
330+
}
331+
318332
podLabels[k] = v
319333
}
320334
err = unstructured.SetNestedStringMap(un.Object, podLabels, "spec", "template", "metadata", "labels")
@@ -331,6 +345,13 @@ func PatchWorkload(workload *v1.Resource, patcher *v1.Patcher) error {
331345
}
332346
// merge annotations
333347
for k, v := range patcher.Annotations {
348+
// NOTE: we implement value-based map removal by agreeing on a specific value
349+
// `ops://kusionstack.io/remove` as the `remove` operation index for annotation patcher.
350+
if v == removalVal {
351+
delete(objAnnotations, k)
352+
continue
353+
}
354+
334355
objAnnotations[k] = v
335356
}
336357
un.SetAnnotations(objAnnotations)
@@ -347,6 +368,13 @@ func PatchWorkload(workload *v1.Resource, patcher *v1.Patcher) error {
347368
}
348369
// merge annotations
349370
for k, v := range patcher.PodAnnotations {
371+
// NOTE: we implement value-based map removal by agreeing on a specific value
372+
// `ops://kusionstack.io/remove` as the `remove` operation index for pod annotation patcher.
373+
if v == removalVal {
374+
delete(podAnnotations, k)
375+
continue
376+
}
377+
350378
podAnnotations[k] = v
351379
}
352380
err = unstructured.SetNestedStringMap(un.Object, podAnnotations, "spec", "template", "metadata", "annotations")

0 commit comments

Comments
 (0)