Handle errors in additionalItemBackupper

Signed-off-by: Calle Pettersson <cpettsson@gmail.com>
This commit is contained in:
Calle Pettersson
2018-05-22 15:39:33 +02:00
parent aeb5f6d832
commit 24dfef6f15
3 changed files with 43 additions and 3 deletions

View File

@@ -139,6 +139,7 @@ func TestBackupItemNoSkips(t *testing.T) {
customActionAdditionalItems []runtime.Unstructured
groupResource string
snapshottableVolumes map[string]api.VolumeBackupInfo
snapshotError error
}{
{
name: "explicit namespace include",
@@ -242,6 +243,17 @@ func TestBackupItemNoSkips(t *testing.T) {
"vol-abc123": {SnapshotID: "snapshot-1", AvailabilityZone: "us-east-1c"},
},
},
{
name: "backup fails when takePVSnapshot fails",
namespaceIncludesExcludes: collections.NewIncludesExcludes().Includes("*"),
item: `{"apiVersion": "v1", "kind": "PersistentVolume", "metadata": {"name": "mypv", "labels": {"failure-domain.beta.kubernetes.io/zone": "us-east-1c"}}, "spec": {"awsElasticBlockStore": {"volumeID": "aws://us-east-1c/vol-abc123"}}}`,
expectError: true,
groupResource: "persistentvolumes",
snapshottableVolumes: map[string]api.VolumeBackupInfo{
"vol-abc123": {SnapshotID: "snapshot-1", AvailabilityZone: "us-east-1c"},
},
snapshotError: fmt.Errorf("failure"),
},
}
for _, test := range tests {
@@ -320,6 +332,7 @@ func TestBackupItemNoSkips(t *testing.T) {
snapshotService = &arktest.FakeSnapshotService{
SnapshottableVolumes: test.snapshottableVolumes,
VolumeID: "vol-abc123",
Error: test.snapshotError,
}
b.snapshotService = snapshotService
}
@@ -337,7 +350,10 @@ func TestBackupItemNoSkips(t *testing.T) {
obj := &unstructured.Unstructured{Object: item}
itemHookHandler.On("handleHooks", mock.Anything, groupResource, obj, resourceHooks, hookPhasePre).Return(nil)
itemHookHandler.On("handleHooks", mock.Anything, groupResource, obj, resourceHooks, hookPhasePost).Return(nil)
if test.snapshotError == nil {
// TODO: Remove if-clause when #511 is resolved.
itemHookHandler.On("handleHooks", mock.Anything, groupResource, obj, resourceHooks, hookPhasePost).Return(nil)
}
for i, item := range test.customActionAdditionalItemIdentifiers {
itemClient := &arktest.FakeDynamicClient{}