From 2d81e29276283f3819298758f1381916b0f0c42e Mon Sep 17 00:00:00 2001 From: Adnan Abdulhussein Date: Tue, 18 Jun 2019 11:19:00 -0700 Subject: [PATCH] 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 * changelog Signed-off-by: Adnan Abdulhussein --- changelogs/unreleased/1587-prydonius | 1 + pkg/backup/backup_new_test.go | 5 ++--- pkg/backup/item_backupper.go | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 changelogs/unreleased/1587-prydonius diff --git a/changelogs/unreleased/1587-prydonius b/changelogs/unreleased/1587-prydonius new file mode 100644 index 000000000..db3cc1ced --- /dev/null +++ b/changelogs/unreleased/1587-prydonius @@ -0,0 +1 @@ +ensures backup item action modifications to an item's namespace/name are saved in the file path in the tarball diff --git a/pkg/backup/backup_new_test.go b/pkg/backup/backup_new_test.go index 639622e15..7a8b93338 100644 --- a/pkg/backup/backup_new_test.go +++ b/pkg/backup/backup_new_test.go @@ -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")), }, }, } diff --git a/pkg/backup/item_backupper.go b/pkg/backup/item_backupper.go index 6b4b83698..189f562c0 100644 --- a/pkg/backup/item_backupper.go +++ b/pkg/backup/item_backupper.go @@ -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 {