Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore terminating resources while doing a backup #526

Merged
merged 1 commit into from
Jun 8, 2018

Conversation

yastij
Copy link
Member

@yastij yastij commented Jun 4, 2018

this PR fixes #524

@yastij yastij force-pushed the ignore-resources-terminating branch 2 times, most recently from 2fef837 to dbc67d7 Compare June 4, 2018 11:00
@yastij yastij changed the title ignore terminating resources while doing a backup wip: ignore terminating resources while doing a backup Jun 4, 2018
@yastij yastij force-pushed the ignore-resources-terminating branch from dbc67d7 to 111e82e Compare June 4, 2018 11:43
@yastij yastij changed the title wip: ignore terminating resources while doing a backup ignore terminating resources while doing a backup Jun 4, 2018
@@ -147,6 +147,22 @@ func (ib *defaultItemBackupper) backupItem(logger logrus.FieldLogger, obj runtim
return nil
}

resource := obj.UnstructuredContent()
if conditions, err := collections.GetSlice(resource, "status.conditions"); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think checking for metadata.deletionTimestamp != nil would be more universal - WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it'll be easier.

@yastij yastij force-pushed the ignore-resources-terminating branch from 111e82e to 7c539eb Compare June 4, 2018 18:26
@yastij
Copy link
Member Author

yastij commented Jun 4, 2018

@ncdc - updated

@@ -147,6 +147,12 @@ func (ib *defaultItemBackupper) backupItem(logger logrus.FieldLogger, obj runtim
return nil
}

resource := obj.UnstructuredContent()
if deletionTimestamp, err := collections.GetString(resource, "metadata.deletionTimestamp"); err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use metadata.GetDeletionTimestamp()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

func TestBackupItemWhenInTerminatingStatus(t *testing.T) {
f := true
ib := &defaultItemBackupper{
backup: &v1.Backup{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to do &v1.Backup{} - any reason you needed IncludeClusterResources?

ib := &defaultItemBackupper{
backup: &v1.Backup{
Spec: v1.BackupSpec{
IncludeClusterResources: &f,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do need to keep this, use boolptr.True()

resources: collections.NewIncludesExcludes(),
}

u := unstructuredOrDie(`{"apiVersion":"v1","kind":"Foo","metadata":{"name":"bar", "namespace": "test", "deletionTimestamp": "timestamp"}, "status": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a real deletionTimestamp. You can probably remove the conditions too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -123,6 +123,35 @@ func TestBackupItemSkipsClusterScopedResourceWhenIncludeClusterResourcesFalse(t
assert.NoError(t, err)
}

func TestBackupItemWhenInTerminatingStatus(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put this in TestBackupItemSkips

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@yastij yastij force-pushed the ignore-resources-terminating branch from 7c539eb to 7cdd559 Compare June 6, 2018 17:51
@@ -147,6 +147,9 @@ func (ib *defaultItemBackupper) backupItem(logger logrus.FieldLogger, obj runtim
return nil
}

if metadata.GetDeletionTimestamp() != nil {
return nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's log.Info that we're skipping it because it's being deleted.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should use an actual Pod and then the unstructured converter so we're not conditionally modifying json...

@yastij yastij force-pushed the ignore-resources-terminating branch 3 times, most recently from 53e5b4a to 7bccb54 Compare June 7, 2018 21:34
Copy link
Contributor

@skriss skriss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, will let @ncdc do a final review/merge.

@ncdc ncdc added this to the v0.9.0 milestone Jun 8, 2018
if test.terminating {
pod.ObjectMeta.DeletionTimestamp = &metav1.Time{Time: time.Now()}
}
unstructuredObj, _ := runtime.DefaultUnstructuredConverter.ToUnstructured(pod)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you require.NoError on the returned error?

@yastij yastij force-pushed the ignore-resources-terminating branch from 7bccb54 to 17f6a14 Compare June 8, 2018 14:49
@yastij
Copy link
Member Author

yastij commented Jun 8, 2018

@ncdc - ready to merge

@ncdc
Copy link
Contributor

ncdc commented Jun 8, 2018

LGTM, thanks @yastij!

@ncdc ncdc merged commit 0396ca1 into vmware-tanzu:master Jun 8, 2018
@yastij yastij deleted the ignore-resources-terminating branch June 8, 2018 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ark should ignore Terminating resources
3 participants