-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Conversation
2fef837
to
dbc67d7
Compare
dbc67d7
to
111e82e
Compare
pkg/backup/item_backupper.go
Outdated
@@ -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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
111e82e
to
7c539eb
Compare
@ncdc - updated |
pkg/backup/item_backupper.go
Outdated
@@ -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 { |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
pkg/backup/item_backupper_test.go
Outdated
func TestBackupItemWhenInTerminatingStatus(t *testing.T) { | ||
f := true | ||
ib := &defaultItemBackupper{ | ||
backup: &v1.Backup{ |
There was a problem hiding this comment.
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
?
pkg/backup/item_backupper_test.go
Outdated
ib := &defaultItemBackupper{ | ||
backup: &v1.Backup{ | ||
Spec: v1.BackupSpec{ | ||
IncludeClusterResources: &f, |
There was a problem hiding this comment.
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()
pkg/backup/item_backupper_test.go
Outdated
resources: collections.NewIncludesExcludes(), | ||
} | ||
|
||
u := unstructuredOrDie(`{"apiVersion":"v1","kind":"Foo","metadata":{"name":"bar", "namespace": "test", "deletionTimestamp": "timestamp"}, "status": { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
pkg/backup/item_backupper_test.go
Outdated
@@ -123,6 +123,35 @@ func TestBackupItemSkipsClusterScopedResourceWhenIncludeClusterResourcesFalse(t | |||
assert.NoError(t, err) | |||
} | |||
|
|||
func TestBackupItemWhenInTerminatingStatus(t *testing.T) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
7c539eb
to
7cdd559
Compare
pkg/backup/item_backupper.go
Outdated
@@ -147,6 +147,9 @@ func (ib *defaultItemBackupper) backupItem(logger logrus.FieldLogger, obj runtim | |||
return nil | |||
} | |||
|
|||
if metadata.GetDeletionTimestamp() != nil { | |||
return nil |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
pkg/backup/item_backupper_test.go
Outdated
@@ -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 |
There was a problem hiding this comment.
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...
53e5b4a
to
7bccb54
Compare
There was a problem hiding this 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.
pkg/backup/item_backupper_test.go
Outdated
if test.terminating { | ||
pod.ObjectMeta.DeletionTimestamp = &metav1.Time{Time: time.Now()} | ||
} | ||
unstructuredObj, _ := runtime.DefaultUnstructuredConverter.ToUnstructured(pod) |
There was a problem hiding this comment.
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?
Signed-off-by: Yassine TIJANI <[email protected]>
7bccb54
to
17f6a14
Compare
@ncdc - ready to merge |
LGTM, thanks @yastij! |
this PR fixes #524