diff --git a/pkg/apis/velero/v1/labels_annotations.go b/pkg/apis/velero/v1/labels_annotations.go index f0a4e0064..172b436a8 100644 --- a/pkg/apis/velero/v1/labels_annotations.go +++ b/pkg/apis/velero/v1/labels_annotations.go @@ -51,15 +51,15 @@ const ( // namespace a restic repository stores pod volume backups for. ResticVolumeNamespaceLabel = "velero.io/volume-namespace" - // SourceClusterK8sVersionLabel is the label key used to identify the k8s + // SourceClusterK8sVersionAnnotation is the label key used to identify the k8s // git version of the backup , i.e. v1.16.4 - SourceClusterK8sGitVersionLabel = "velero.io/source-cluster-k8s-gitversion" + SourceClusterK8sGitVersionAnnotation = "velero.io/source-cluster-k8s-gitversion" - // SourceClusterK8sMajorVersionLabel is the label key used to identify the k8s + // SourceClusterK8sMajorVersionAnnotation is the label key used to identify the k8s // major version of the backup , i.e. 1 - SourceClusterK8sMajorVersionLabel = "velero.io/source-cluster-k8s-major-version" + SourceClusterK8sMajorVersionAnnotation = "velero.io/source-cluster-k8s-major-version" - // SourceClusterK8sMajorVersionLabel is the label key used to identify the k8s + // SourceClusterK8sMajorVersionAnnotation is the label key used to identify the k8s // minor version of the backup , i.e. 16 - SourceClusterK8sMinorVersionLabel = "velero.io/source-cluster-k8s-minor-version" + SourceClusterK8sMinorVersionAnnotation = "velero.io/source-cluster-k8s-minor-version" ) diff --git a/pkg/controller/backup_controller.go b/pkg/controller/backup_controller.go index 131f33ac5..ef7a91dc3 100644 --- a/pkg/controller/backup_controller.go +++ b/pkg/controller/backup_controller.go @@ -333,9 +333,12 @@ func (c *backupController) prepareBackupRequest(backup *velerov1api.Backup) *pkg request.Labels[velerov1api.StorageLocationLabel] = label.GetValidName(request.Spec.StorageLocation) // Getting all information of cluster version - useful for future skip-level migration - request.Labels[velerov1api.SourceClusterK8sGitVersionLabel] = label.GetValidName(c.discoveryHelper.ServerVersion().String()) - request.Labels[velerov1api.SourceClusterK8sMajorVersionLabel] = label.GetValidName(c.discoveryHelper.ServerVersion().Major) - request.Labels[velerov1api.SourceClusterK8sMinorVersionLabel] = label.GetValidName(c.discoveryHelper.ServerVersion().Minor) + if request.Annotations == nil { + request.Annotations = make(map[string]string) + } + request.Annotations[velerov1api.SourceClusterK8sGitVersionAnnotation] = c.discoveryHelper.ServerVersion().String() + request.Annotations[velerov1api.SourceClusterK8sMajorVersionAnnotation] = c.discoveryHelper.ServerVersion().Major + request.Annotations[velerov1api.SourceClusterK8sMinorVersionAnnotation] = c.discoveryHelper.ServerVersion().Minor // validate the included/excluded resources for _, err := range collections.ValidateIncludesExcludes(request.Spec.IncludedResources, request.Spec.ExcludedResources) { diff --git a/pkg/controller/backup_controller_test.go b/pkg/controller/backup_controller_test.go index 6d1b750fe..99bd653b1 100644 --- a/pkg/controller/backup_controller_test.go +++ b/pkg/controller/backup_controller_test.go @@ -359,11 +359,13 @@ func TestProcessBackupCompletions(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Namespace: velerov1api.DefaultNamespace, Name: "backup-1", - Labels: map[string]string{ + Annotations: map[string]string{ "velero.io/source-cluster-k8s-major-version": "1", "velero.io/source-cluster-k8s-minor-version": "16", "velero.io/source-cluster-k8s-gitversion": "v1.16.4", - "velero.io/storage-location": "loc-1", + }, + Labels: map[string]string{ + "velero.io/storage-location": "loc-1", }, }, Spec: velerov1api.BackupSpec{ @@ -390,11 +392,13 @@ func TestProcessBackupCompletions(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Namespace: velerov1api.DefaultNamespace, Name: "backup-1", - Labels: map[string]string{ + Annotations: map[string]string{ "velero.io/source-cluster-k8s-major-version": "1", "velero.io/source-cluster-k8s-minor-version": "16", "velero.io/source-cluster-k8s-gitversion": "v1.16.4", - "velero.io/storage-location": "alt-loc", + }, + Labels: map[string]string{ + "velero.io/storage-location": "alt-loc", }, }, Spec: velerov1api.BackupSpec{ @@ -424,11 +428,13 @@ func TestProcessBackupCompletions(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Namespace: velerov1api.DefaultNamespace, Name: "backup-1", - Labels: map[string]string{ + Annotations: map[string]string{ "velero.io/source-cluster-k8s-major-version": "1", "velero.io/source-cluster-k8s-minor-version": "16", "velero.io/source-cluster-k8s-gitversion": "v1.16.4", - "velero.io/storage-location": "read-write", + }, + Labels: map[string]string{ + "velero.io/storage-location": "read-write", }, }, Spec: velerov1api.BackupSpec{ @@ -455,11 +461,13 @@ func TestProcessBackupCompletions(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Namespace: velerov1api.DefaultNamespace, Name: "backup-1", - Labels: map[string]string{ + Annotations: map[string]string{ "velero.io/source-cluster-k8s-major-version": "1", "velero.io/source-cluster-k8s-minor-version": "16", "velero.io/source-cluster-k8s-gitversion": "v1.16.4", - "velero.io/storage-location": "loc-1", + }, + Labels: map[string]string{ + "velero.io/storage-location": "loc-1", }, }, Spec: velerov1api.BackupSpec{ @@ -488,11 +496,13 @@ func TestProcessBackupCompletions(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Namespace: velerov1api.DefaultNamespace, Name: "backup-1", - Labels: map[string]string{ + Annotations: map[string]string{ "velero.io/source-cluster-k8s-major-version": "1", "velero.io/source-cluster-k8s-minor-version": "16", "velero.io/source-cluster-k8s-gitversion": "v1.16.4", - "velero.io/storage-location": "loc-1", + }, + Labels: map[string]string{ + "velero.io/storage-location": "loc-1", }, }, Spec: velerov1api.BackupSpec{ @@ -522,11 +532,13 @@ func TestProcessBackupCompletions(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Namespace: velerov1api.DefaultNamespace, Name: "backup-1", - Labels: map[string]string{ + Annotations: map[string]string{ "velero.io/source-cluster-k8s-major-version": "1", "velero.io/source-cluster-k8s-minor-version": "16", "velero.io/source-cluster-k8s-gitversion": "v1.16.4", - "velero.io/storage-location": "loc-1", + }, + Labels: map[string]string{ + "velero.io/storage-location": "loc-1", }, }, Spec: velerov1api.BackupSpec{ @@ -554,11 +566,13 @@ func TestProcessBackupCompletions(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Namespace: velerov1api.DefaultNamespace, Name: "backup-1", - Labels: map[string]string{ + Annotations: map[string]string{ "velero.io/source-cluster-k8s-major-version": "1", "velero.io/source-cluster-k8s-minor-version": "16", "velero.io/source-cluster-k8s-gitversion": "v1.16.4", - "velero.io/storage-location": "loc-1", + }, + Labels: map[string]string{ + "velero.io/storage-location": "loc-1", }, }, Spec: velerov1api.BackupSpec{