Skip to content
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

[1.5] Automated cherry pick of #4160: Prune job label for kubernetes 1.27,prefix with #4264

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
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