Skip to content

Commit

Permalink
Remove legacy label version check, to be added back when version is k…
Browse files Browse the repository at this point in the history
…nown

Signed-off-by: Tiger Kaovilai <[email protected]>
  • Loading branch information
kaovilai committed Aug 28, 2023
1 parent f6e8c20 commit c5aad9e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 36 deletions.
8 changes: 0 additions & 8 deletions pkg/discovery/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,3 @@ func (h *helper) ServerVersion() *version.Info {
defer h.lock.RUnlock()
return h.serverVersion
}

func ServerVersion(logger logrus.FieldLogger) (*version.Info, error) {
discoveryHelper, err := NewHelper(&discovery.DiscoveryClient{}, logger)
if err != nil {
return nil, err
}
return discoveryHelper.ServerVersion(), nil
}
30 changes: 2 additions & 28 deletions pkg/restore/job_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ limitations under the License.
package restore

import (
"strconv"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
batchv1api "k8s.io/api/batch/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"

"github.com/vmware-tanzu/velero/pkg/discovery"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
)

Expand Down Expand Up @@ -54,35 +51,12 @@ func (a *JobAction) Execute(input *velero.RestoreItemActionExecuteInput) (*veler
return nil, errors.WithStack(err)
}

// get kube version
serverVersion, err := discovery.ServerVersion(a.logger)
if err != nil {
return nil, errors.WithStack(err)
}
// if kube version < 1.27, use legacy controller-uid label
majorVersion, err := strconv.Atoi(serverVersion.Major)
if err != nil {
return nil, errors.WithStack(err)
}
minorVersion, err := strconv.Atoi(serverVersion.Minor)
if err != nil {
return nil, errors.WithStack(err)
}
deleteLegacyControllerUIDLabel := false
if majorVersion < 1 || (majorVersion == 1 && minorVersion <= 27) {
deleteLegacyControllerUIDLabel = true
}

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

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

0 comments on commit c5aad9e

Please sign in to comment.