ensure backup item action modifications reflected in tarball filepath (#1587)

* ensure backup item action modifications reflected in tarball filepath

This patch ensures the updated backup item's name and namespace are used
when constructing the filepath for the tarball.

Signed-off-by: Adnan Abdulhussein <aadnan@vmware.com>

* changelog

Signed-off-by: Adnan Abdulhussein <aadnan@vmware.com>
pull/1593/head
Adnan Abdulhussein 2019-06-18 11:19:00 -07:00 committed by Steve Kriss
parent 5d3312b7b5
commit 2d81e29276
3 changed files with 6 additions and 3 deletions

View File

@ -0,0 +1 @@
ensures backup item action modifications to an item's namespace/name are saved in the file path in the tarball

View File

@ -1006,8 +1006,7 @@ func TestBackupActionModifications(t *testing.T) {
},
},
{
// TODO this seems like a bug
name: "modifications to name and namespace in an action are persisted in JSON but not in filename",
name: "modifications to name and namespace in an action are persisted in JSON and in filename",
backup: defaultBackup().
Backup(),
apiResources: []*apiResource{
@ -1022,7 +1021,7 @@ func TestBackupActionModifications(t *testing.T) {
}),
},
want: map[string]unstructuredObject{
"resources/pods/namespaces/ns-1/pod-1.json": toUnstructuredOrFail(t, newPod("ns-1-updated", "pod-1-updated")),
"resources/pods/namespaces/ns-1-updated/pod-1-updated.json": toUnstructuredOrFail(t, newPod("ns-1-updated", "pod-1-updated")),
},
},
}

View File

@ -206,6 +206,9 @@ func (ib *defaultItemBackupper) backupItem(logger logrus.FieldLogger, obj runtim
if metadata, err = meta.Accessor(obj); err != nil {
return errors.WithStack(err)
}
// update name and namespace in case they were modified in an action
name = metadata.GetName()
namespace = metadata.GetNamespace()
if groupResource == kuberesource.PersistentVolumes {
if err := ib.takePVSnapshot(obj, log); err != nil {