🐛 Use CRD version prior to remap_crd_version backup item action (#2683)
* 🐛 preserve crd version before remapping
Signed-off-by: Ashish Amarnath <ashisham@vmware.com>
pull/2696/head
parent
2d48ac79c2
commit
b4465e92b8
|
@ -0,0 +1 @@
|
|||
capture version of the CRD prior before invoking the remap_crd_version backup item action
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"}
|
||||
|
|
Loading…
Reference in New Issue