Skip to content

Commit

Permalink
ignore terminating resources while doing a backup
Browse files Browse the repository at this point in the history
Signed-off-by: Yassine TIJANI <[email protected]>
  • Loading branch information
yastij committed Jun 6, 2018
1 parent 6f62749 commit 7cdd559
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pkg/backup/item_backupper.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ func (ib *defaultItemBackupper) backupItem(logger logrus.FieldLogger, obj runtim
return nil
}

if metadata.GetDeletionTimestamp() != nil {
return nil
}
key := itemKey{
resource: groupResource.String(),
namespace: namespace,
Expand Down
17 changes: 16 additions & 1 deletion pkg/backup/item_backupper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func TestBackupItemSkips(t *testing.T) {
namespaces *collections.IncludesExcludes
groupResource schema.GroupResource
resources *collections.IncludesExcludes
terminating bool
backedUpItems map[itemKey]struct{}
}{
{
Expand Down Expand Up @@ -89,6 +90,15 @@ func TestBackupItemSkips(t *testing.T) {
{resource: "bar.foo", namespace: "ns", name: "foo"}: {},
},
},
{
testName: "terminating resource",
namespace: "ns",
name: "foo",
groupResource: schema.GroupResource{Group: "foo", Resource: "bar"},
namespaces: collections.NewIncludesExcludes(),
resources: collections.NewIncludesExcludes(),
terminating: true,
},
}

for _, test := range tests {
Expand All @@ -99,7 +109,12 @@ func TestBackupItemSkips(t *testing.T) {
backedUpItems: test.backedUpItems,
}

u := unstructuredOrDie(fmt.Sprintf(`{"apiVersion":"v1","kind":"Pod","metadata":{"namespace":"%s","name":"%s"}}`, test.namespace, test.name))
var deletionTimestamp string

if test.terminating {
deletionTimestamp = `, "deletionTimestamp": "2018-05-30T13:30:34Z"`
}
u := unstructuredOrDie(fmt.Sprintf(`{"apiVersion":"v1","kind":"Pod","metadata":{"namespace":"%s","name":"%s" %s}}`, test.namespace, test.name, deletionTimestamp))
err := ib.backupItem(arktest.NewLogger(), u, test.groupResource)
assert.NoError(t, err)
})
Expand Down

0 comments on commit 7cdd559

Please sign in to comment.