Delete spec.priority in pod restore action

Signed-off-by: Michal Wieczorek <wieczorek-michal@wp.pl>
This commit is contained in:
Michal Wieczorek
2018-11-21 12:49:27 +01:00
parent 858171e812
commit 43cd2ca36f
3 changed files with 16 additions and 2 deletions

View File

@@ -50,6 +50,9 @@ func (a *podAction) Execute(obj runtime.Unstructured, restore *api.Restore) (run
a.logger.Debug("deleting spec.NodeName")
delete(spec, "nodeName")
a.logger.Debug("deleting spec.priority")
delete(spec, "priority")
// if there are no volumes, then there can't be any volume mounts, so we're done.
if !collections.Exists(spec, "volumes") {
return obj, nil, nil

View File

@@ -40,12 +40,20 @@ func TestPodActionExecute(t *testing.T) {
{
name: "nodeName (only) should be deleted from spec",
obj: NewTestUnstructured().WithName("pod-1").WithSpec("nodeName", "foo").
WithSpec("serviceAccountName", "foo").
WithSpecField("containers", []interface{}{}).
Unstructured,
expectedErr: false,
expectedRes: NewTestUnstructured().WithName("pod-1").WithSpec("foo").
WithSpec("serviceAccountName", "foo").
WithSpecField("containers", []interface{}{}).
Unstructured,
},
{
name: "priority (only) should be deleted from spec",
obj: NewTestUnstructured().WithName("pod-1").WithSpec("priority", "foo").
WithSpecField("containers", []interface{}{}).
Unstructured,
expectedErr: false,
expectedRes: NewTestUnstructured().WithName("pod-1").WithSpec("foo").
WithSpecField("containers", []interface{}{}).
Unstructured,
},

View File

@@ -1605,6 +1605,9 @@ func (obj *testUnstructured) WithMetadata(fields ...string) *testUnstructured {
}
func (obj *testUnstructured) WithSpec(fields ...string) *testUnstructured {
if _, found := obj.Object["spec"]; found {
panic("spec already set - you probably didn't mean to do this twice!")
}
return obj.withMap("spec", fields...)
}