Skip to content

Commit

Permalink
Merge pull request #919 from skriss/v0.9.8-beta.1-cherrypicks
Browse files Browse the repository at this point in the history
V0.9.8 beta.1 cherrypicks
  • Loading branch information
carlisia committed Oct 10, 2018
2 parents caa962f + 7d9a7c8 commit 78141e4
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

#### [v0.9.8-beta.1](https://github.com/heptio/ark/releases/tag/v0.9.8-beta.1) - 2018-10-10

#### Bug Fixes
* Discard service account token volume mounts from init containers on restore (#910, @james-powis)

#### [v0.9.7](https://github.com/heptio/ark/releases/tag/v0.9.7) - 2018-10-04

#### Bug Fixes
Expand Down
31 changes: 31 additions & 0 deletions pkg/restore/pod_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,36 @@ func (a *podAction) Execute(obj runtime.Unstructured, restore *api.Restore) (run
return nil, nil, err
}

a.logger.Debug("iterating over init containers")
err = collections.ForEach(spec, "initContainers", func(container map[string]interface{}) error {
var newVolumeMounts []interface{}
err := collections.ForEach(container, "volumeMounts", func(volumeMount map[string]interface{}) error {
name, err := collections.GetString(volumeMount, "name")
if err != nil {
return err
}

a.logger.WithField("volumeMount", name).Debug("Checking volumeMount")
if strings.HasPrefix(name, serviceAccountName+"-token-") {
a.logger.WithField("volumeMount", name).Debug("Excluding volumeMount")
} else {
a.logger.WithField("volumeMount", name).Debug("Preserving volumeMount")
newVolumeMounts = append(newVolumeMounts, volumeMount)
}

return nil
})
if err != nil {
return err
}

container["volumeMounts"] = newVolumeMounts

return nil
})
if err != nil {
return nil, nil, err
}

return obj, nil, nil
}
41 changes: 41 additions & 0 deletions pkg/restore/pod_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,29 @@ func TestPodActionExecute(t *testing.T) {
WithSpec("serviceAccountName", "foo").
WithSpecField("volumes", []interface{}{}).
WithSpecField("containers", []interface{}{}).
WithSpecField("initContainers", []interface{}{}).
Unstructured,
expectedErr: false,
expectedRes: NewTestUnstructured().WithName("pod-1").WithSpec("foo").
WithSpec("serviceAccountName", "foo").
WithSpecField("volumes", []interface{}{}).
WithSpecField("containers", []interface{}{}).
WithSpecField("initContainers", []interface{}{}).
Unstructured,
},
{
name: "volumes matching prefix ServiceAccount-token- should be deleted",
obj: NewTestUnstructured().WithName("pod-1").
WithSpec("serviceAccountName", "foo").
WithSpecField("initContainers", []interface{}{}).
WithSpecField("volumes", []interface{}{
map[string]interface{}{"name": "foo"},
map[string]interface{}{"name": "foo-token-foo"},
}).WithSpecField("containers", []interface{}{}).Unstructured,
expectedErr: false,
expectedRes: NewTestUnstructured().WithName("pod-1").
WithSpec("serviceAccountName", "foo").
WithSpecField("initContainers", []interface{}{}).
WithSpecField("volumes", []interface{}{
map[string]interface{}{"name": "foo"},
}).WithSpecField("containers", []interface{}{}).Unstructured,
Expand All @@ -71,6 +75,7 @@ func TestPodActionExecute(t *testing.T) {
obj: NewTestUnstructured().WithName("svc-1").
WithSpec("serviceAccountName", "foo").
WithSpecField("volumes", []interface{}{}).
WithSpecField("initContainers", []interface{}{}).
WithSpecField("containers", []interface{}{
map[string]interface{}{
"volumeMounts": []interface{}{
Expand All @@ -88,6 +93,7 @@ func TestPodActionExecute(t *testing.T) {
expectedRes: NewTestUnstructured().WithName("svc-1").
WithSpec("serviceAccountName", "foo").
WithSpecField("volumes", []interface{}{}).
WithSpecField("initContainers", []interface{}{}).
WithSpecField("containers", []interface{}{
map[string]interface{}{
"volumeMounts": []interface{}{
Expand All @@ -99,6 +105,41 @@ func TestPodActionExecute(t *testing.T) {
}).
Unstructured,
},
{
name: "initContainer volumeMounts matching prefix ServiceAccount-token- should be deleted",
obj: NewTestUnstructured().WithName("svc-1").
WithSpec("serviceAccountName", "foo").
WithSpecField("volumes", []interface{}{}).
WithSpecField("containers", []interface{}{}).
WithSpecField("initContainers", []interface{}{
map[string]interface{}{
"volumeMounts": []interface{}{
map[string]interface{}{
"name": "foo",
},
map[string]interface{}{
"name": "foo-token-foo",
},
},
},
}).
Unstructured,
expectedErr: false,
expectedRes: NewTestUnstructured().WithName("svc-1").
WithSpec("serviceAccountName", "foo").
WithSpecField("volumes", []interface{}{}).
WithSpecField("containers", []interface{}{}).
WithSpecField("initContainers", []interface{}{
map[string]interface{}{
"volumeMounts": []interface{}{
map[string]interface{}{
"name": "foo",
},
},
},
}).
Unstructured,
},
}

for _, test := range tests {
Expand Down

0 comments on commit 78141e4

Please sign in to comment.