Skip to content

Commit

Permalink
Merge pull request #6712 from kaovilai/jobs-label-k8s1.27
Browse files Browse the repository at this point in the history
On restore, delete Kubernetes 1.27 job controller uid label
  • Loading branch information
reasonerjt authored Sep 18, 2023
2 parents 8481b4c + c5aad9e commit cf3cb9c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/6712-kaovilai
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Kubernetes 1.27 new job label batch.kubernetes.io/controller-uid are deleted during restore per https://github.com/kubernetes/kubernetes/pull/114930
11 changes: 9 additions & 2 deletions pkg/restore/job_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ import (
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
)

const (
legacyControllerUIDLabel = "controller-uid" // <=1.27 This still exists in 1.27 for backward compatibility, maybe remove in 1.28?
controllerUIDLabel = "batch.kubernetes.io/controller-uid" // >=1.27 https://github.com/kubernetes/kubernetes/pull/114930#issuecomment-1384667494
)

type JobAction struct {
logger logrus.FieldLogger
}
Expand All @@ -47,9 +52,11 @@ func (a *JobAction) Execute(input *velero.RestoreItemActionExecuteInput) (*veler
}

if job.Spec.Selector != nil {
delete(job.Spec.Selector.MatchLabels, "controller-uid")
delete(job.Spec.Selector.MatchLabels, controllerUIDLabel)
delete(job.Spec.Selector.MatchLabels, legacyControllerUIDLabel)
}
delete(job.Spec.Template.ObjectMeta.Labels, "controller-uid")
delete(job.Spec.Template.ObjectMeta.Labels, controllerUIDLabel)
delete(job.Spec.Template.ObjectMeta.Labels, legacyControllerUIDLabel)

res, err := runtime.DefaultUnstructuredConverter.ToUnstructured(job)
if err != nil {
Expand Down

0 comments on commit cf3cb9c

Please sign in to comment.