Skip to content

Commit

Permalink
Merge pull request #4264 from liangyuanpeng/automated-cherry-pick-of-…
Browse files Browse the repository at this point in the history
…#4160-upstream-release-1.5

[1.5] Automated cherry pick of #4160: Prune job label for kubernetes 1.27,prefix with
  • Loading branch information
karmada-bot authored Nov 22, 2023
2 parents bc59377 + 44d59f8 commit 0b7a313
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions pkg/resourceinterpreter/defaultinterpreter/prune/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,12 @@ func removeGenerateSelectorOfJob(workload *unstructured.Unstructured) error {
return err
}
if exist {
if util.GetLabelValue(matchLabels, "controller-uid") != "" {
delete(matchLabels, "controller-uid")
}
delete(matchLabels, "controller-uid")
// The label 'batch.kubernetes.io/controller-uid' was introduced at Kubernetes v1.27, which intend to replace
// the previous label "controller-uid"(without batch.kubernetes.io prefix).
// See https://github.com/kubernetes/kubernetes/pull/114930 for more details.
delete(matchLabels, "batch.kubernetes.io/controller-uid")

err = unstructured.SetNestedStringMap(workload.Object, matchLabels, "spec", "selector", "matchLabels")
if err != nil {
return err
Expand All @@ -112,13 +115,13 @@ func removeGenerateSelectorOfJob(workload *unstructured.Unstructured) error {
return err
}
if exist {
if util.GetLabelValue(templateLabels, "controller-uid") != "" {
delete(templateLabels, "controller-uid")
}

if util.GetLabelValue(templateLabels, "job-name") != "" {
delete(templateLabels, "job-name")
}
delete(templateLabels, "controller-uid")
delete(templateLabels, "job-name")
// The label 'batch.kubernetes.io/controller-uid' and 'batch.kubernetes.io/job-name' were introduced at
// Kubernetes v1.27, which intend to replace the previous labels 'controller-uid' and 'job-name' respectively.
// See https://github.com/kubernetes/kubernetes/pull/114930 for more details.
delete(templateLabels, "batch.kubernetes.io/controller-uid")
delete(templateLabels, "batch.kubernetes.io/job-name")

err = unstructured.SetNestedStringMap(workload.Object, templateLabels, "spec", "template", "metadata", "labels")
if err != nil {
Expand Down

0 comments on commit 0b7a313

Please sign in to comment.