Merge pull request #2431 from nrb/fix2429

Annotate backups with kubernetes version information
pull/2442/head
Ashish Amarnath 2020-04-15 11:45:10 -07:00 committed by GitHub
commit bf2ef69aa7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 24 deletions

View File

@ -1 +1 @@
adding labels on backup CRD for k8s major, minor and git versions
adding annotations on backup CRD for k8s major, minor and git versions

View File

@ -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"
)

View File

@ -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) {

View File

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