-
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
Handle errors in additionalItemBackupper #512
Conversation
922f7be
to
1859063
Compare
pkg/backup/item_backupper_test.go
Outdated
snapshotService = &arktest.FakeSnapshotService{ | ||
SnapshottableVolumes: test.snapshottableVolumes, | ||
VolumeID: "vol-abc123", | ||
if test.snapshotError != 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.
This is a bit of a mess - would appreciate some ideas on how to make this clearer
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.
See my comment below
@@ -89,3 +89,31 @@ func (s *FakeSnapshotService) SetVolumeID(pv runtime.Unstructured, volumeID stri | |||
s.VolumeIDSet = volumeID | |||
return pv, 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.
Not sure if this is the right place?
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.
Instead of creating a new type, please add err error
to FakeSnapshotService
and return s.err
wherever we need to return an error.
pkg/backup/item_backupper.go
Outdated
@@ -206,7 +206,10 @@ func (ib *defaultItemBackupper) backupItem(logger logrus.FieldLogger, obj runtim | |||
return err | |||
} | |||
|
|||
ib.additionalItemBackupper.backupItem(log, additionalItem, gvr.GroupResource()) | |||
err = ib.additionalItemBackupper.backupItem(log, additionalItem, gvr.GroupResource()) |
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.
When we are only checking the returned error and aren't doing anything else with it, we usually use the syntax if err := foo(); 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.
Right. I'll do the same for the three if:s above at the same time, then?
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.
Ah, sorry. That doesn't work though, since they set other vars. Never mind, then, just fixing this one :)
@@ -89,3 +89,31 @@ func (s *FakeSnapshotService) SetVolumeID(pv runtime.Unstructured, volumeID stri | |||
s.VolumeIDSet = volumeID | |||
return pv, 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.
Instead of creating a new type, please add err error
to FakeSnapshotService
and return s.err
wherever we need to return an error.
pkg/backup/item_backupper_test.go
Outdated
snapshotService = &arktest.FakeSnapshotService{ | ||
SnapshottableVolumes: test.snapshottableVolumes, | ||
VolumeID: "vol-abc123", | ||
if test.snapshotError != 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.
See my comment below
Signed-off-by: Calle Pettersson <[email protected]>
1859063
to
24dfef6
Compare
@@ -242,6 +243,17 @@ func TestBackupItemNoSkips(t *testing.T) { | |||
"vol-abc123": {SnapshotID: "snapshot-1", AvailabilityZone: "us-east-1c"}, | |||
}, | |||
}, | |||
{ | |||
name: "backup fails when takePVSnapshot fails", |
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.
To test your change to item_backupper.go, we need a test case that has this mocked behavior return a non-nil error: additionalItemBackupper.On("backupItem", mock.AnythingOfType("*logrus.Entry"), test.customActionAdditionalItems[i], item.GroupResource).Return(nil)
.
The test case you've added here is valuable too, so we should keep it, but it doesn't cover your fix: namely, that when we call ib.additionalItemBackupper.backupItem(log, additionalItem, gvr.GroupResource())
, it checks the returned error and returns it if it's non-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.
Something like this would cover your change: https://gist.github.com/ncdc/12c3b6b6f4db0e5c60f4ecf77e8d85c2
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.
Thanks! Updated with this, will ask some questions on Slack too :)
Signed-off-by: Calle Pettersson <[email protected]>
LGTM. @skriss ptal |
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.
Fixes #509.
Currently the corresponding test fails, which I think is because of #511.