Skip to content

Commit

Permalink
🐛 Use CRD version prior to remap_crd_version backup item action (vmwa…
Browse files Browse the repository at this point in the history
…re-tanzu#2683)

* 🐛 preserve crd version before remapping

Signed-off-by: Ashish Amarnath <ashisham@vmware.com>
  • Loading branch information
ashish-amarnath authored and nrb committed Jul 13, 2020
1 parent 4491641 commit 769c7fd
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/2683-ashish-amarnath
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
capture version of the CRD prior before invoking the remap_crd_version backup item action
12 changes: 7 additions & 5 deletions pkg/backup/item_backupper.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,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)
Expand Down Expand Up @@ -203,10 +209,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

Expand Down Expand Up @@ -249,6 +251,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")
Expand All @@ -271,7 +274,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
Expand Down
1 change: 1 addition & 0 deletions pkg/backup/remap_crd_version_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/kuberesource/kuberesource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down

0 comments on commit 769c7fd

Please sign in to comment.