Merge pull request #526 from yastij/ignore-resources-terminating

ignore terminating resources while doing a backup
pull/537/head
Andy Goldstein 2018-06-08 11:10:59 -04:00 committed by GitHub
commit 0396ca1dee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -155,6 +155,10 @@ func (ib *defaultItemBackupper) backupItem(logger logrus.FieldLogger, obj runtim
return nil
}
if metadata.GetDeletionTimestamp() != nil {
log.Info("Skipping item because it's being deleted.")
return nil
}
key := itemKey{
resource: groupResource.String(),
namespace: namespace,

View File

@ -33,6 +33,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
corev1api "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/labels"
@ -48,6 +49,7 @@ func TestBackupItemSkips(t *testing.T) {
namespaces *collections.IncludesExcludes
groupResource schema.GroupResource
resources *collections.IncludesExcludes
terminating bool
backedUpItems map[itemKey]struct{}
}{
{
@ -89,17 +91,37 @@ 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 {
t.Run(test.testName, func(t *testing.T) {
ib := &defaultItemBackupper{
namespaces: test.namespaces,
resources: test.resources,
backedUpItems: test.backedUpItems,
}
u := arktest.UnstructuredOrDie(fmt.Sprintf(`{"apiVersion":"v1","kind":"Pod","metadata":{"namespace":"%s","name":"%s"}}`, test.namespace, test.name))
pod := &corev1api.Pod{
TypeMeta: metav1.TypeMeta{APIVersion: "v1", Kind: "Pod"},
ObjectMeta: metav1.ObjectMeta{Namespace: test.namespace, Name: test.name},
}
if test.terminating {
pod.ObjectMeta.DeletionTimestamp = &metav1.Time{Time: time.Now()}
}
unstructuredObj, unmarshalErr := runtime.DefaultUnstructuredConverter.ToUnstructured(pod)
require.NoError(t, unmarshalErr)
u := &unstructured.Unstructured{Object: unstructuredObj}
err := ib.backupItem(arktest.NewLogger(), u, test.groupResource)
assert.NoError(t, err)
})