From b4465e92b8895ade30fe72ff4b33fe722328b1fd Mon Sep 17 00:00:00 2001 From: Ashish Amarnath Date: Tue, 7 Jul 2020 10:59:41 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Use=20CRD=20version=20prior=20to?= =?UTF-8?q?=20remap=5Fcrd=5Fversion=20backup=20item=20action=20(#2683)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🐛 preserve crd version before remapping Signed-off-by: Ashish Amarnath --- changelogs/unreleased/2683-ashish-amarnath | 1 + pkg/backup/item_backupper.go | 12 +++++++----- pkg/backup/remap_crd_version_action_test.go | 1 + pkg/kuberesource/kuberesource.go | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 changelogs/unreleased/2683-ashish-amarnath diff --git a/changelogs/unreleased/2683-ashish-amarnath b/changelogs/unreleased/2683-ashish-amarnath new file mode 100644 index 000000000..014606d7e --- /dev/null +++ b/changelogs/unreleased/2683-ashish-amarnath @@ -0,0 +1 @@ +capture version of the CRD prior before invoking the remap_crd_version backup item action diff --git a/pkg/backup/item_backupper.go b/pkg/backup/item_backupper.go index d9fd2822b..e2652abca 100644 --- a/pkg/backup/item_backupper.go +++ b/pkg/backup/item_backupper.go @@ -160,6 +160,12 @@ func (ib *itemBackupper) backupItem(logger logrus.FieldLogger, obj runtime.Unstr } } + // capture the version of the object before invoking plugin actions as the plugin may update + // the group version of the object. + // group version of this object + // Used on filepath to backup up all groups and versions + version := resourceVersion(obj) + updatedObj, err := ib.executeActions(log, obj, groupResource, name, namespace, metadata) if err != nil { backupErrs = append(backupErrs, err) @@ -204,10 +210,6 @@ func (ib *itemBackupper) backupItem(logger logrus.FieldLogger, obj runtime.Unstr return false, kubeerrs.NewAggregate(backupErrs) } - // group version of this object - // Used on filepath to backup up all groups and versions - version := resourceVersion(obj) - // Getting the preferred group version of this resource preferredVersion := preferredGVR.Version @@ -250,6 +252,7 @@ func (ib *itemBackupper) backupItem(logger logrus.FieldLogger, obj runtime.Unstr // backing up the preferred version backup without API Group version on path - this is for backward compability + log.Debugf("Resource %s/%s, version= %s, preferredVersion=%s", groupResource.String(), name, version, preferredVersion) if version == preferredVersion { if namespace != "" { filePath = filepath.Join(velerov1api.ResourcesDir, groupResource.String(), velerov1api.NamespaceScopedDir, namespace, name+".json") @@ -272,7 +275,6 @@ func (ib *itemBackupper) backupItem(logger logrus.FieldLogger, obj runtime.Unstr if _, err := ib.tarWriter.Write(itemBytes); err != nil { return false, errors.WithStack(err) } - } return true, nil diff --git a/pkg/backup/remap_crd_version_action_test.go b/pkg/backup/remap_crd_version_action_test.go index e917c24eb..795414cd8 100644 --- a/pkg/backup/remap_crd_version_action_test.go +++ b/pkg/backup/remap_crd_version_action_test.go @@ -170,6 +170,7 @@ func TestRemapCRDVersionActionData(t *testing.T) { require.NoError(t, err) assert.Equal(t, "apiextensions.k8s.io/v1beta1", item.UnstructuredContent()["apiVersion"]) + assert.Equal(t, crd.Kind, item.GetObjectKind().GroupVersionKind().GroupKind().Kind) name, _, err := unstructured.NestedString(item.UnstructuredContent(), "metadata", "name") require.NoError(t, err) assert.Equal(t, crd.Name, name) diff --git a/pkg/kuberesource/kuberesource.go b/pkg/kuberesource/kuberesource.go index a515a70ff..d3daafe35 100644 --- a/pkg/kuberesource/kuberesource.go +++ b/pkg/kuberesource/kuberesource.go @@ -23,7 +23,7 @@ import ( var ( ClusterRoleBindings = schema.GroupResource{Group: "rbac.authorization.k8s.io", Resource: "clusterrolebindings"} ClusterRoles = schema.GroupResource{Group: "rbac.authorization.k8s.io", Resource: "clusterroles"} - CustomResourceDefinitions = schema.GroupResource{Group: "apiextensions.k8s.io", Resource: "customresourcedefinitions"} + CustomResourceDefinitions = schema.GroupResource{Group: "apiextensions.k8s.io", Resource: "CustomResourceDefinition"} Jobs = schema.GroupResource{Group: "batch", Resource: "jobs"} Namespaces = schema.GroupResource{Group: "", Resource: "namespaces"} PersistentVolumeClaims = schema.GroupResource{Group: "", Resource: "persistentvolumeclaims"}