Skip to content

Commit

Permalink
avoid updating directly cached resource template
Browse files Browse the repository at this point in the history
for clean up policy

Signed-off-by: whitewindmills <[email protected]>
  • Loading branch information
whitewindmills committed Aug 2, 2023
1 parent d916d87 commit 472d5c5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/detector/detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,7 @@ func (d *ResourceDetector) CleanupLabels(objRef workv1alpha2.ObjectReference, la
return err
}

workload = workload.DeepCopy()
workloadLabels := workload.GetLabels()
for _, l := range labels {
delete(workloadLabels, l)
Expand Down
6 changes: 5 additions & 1 deletion pkg/detector/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,13 @@ func (d *ResourceDetector) removeResourceLabelsIfNotMatch(objectReference workv1
return false, nil
}

object = object.DeepCopy()
objLabels := object.GetLabels()
for _, labelKey := range labelKeys {
util.RemoveLabel(object, labelKey)
delete(objLabels, labelKey)
}
object.SetLabels(objLabels)

err = d.Client.Update(context.TODO(), object)
if err != nil {
return false, err
Expand Down

0 comments on commit 472d5c5

Please sign in to comment.