Skip to content

Commit

Permalink
Merge pull request #5852 from azylinski/drop-projected-volumes-for-in…
Browse files Browse the repository at this point in the history
…it-containers

When comparing PodSpec semantically, drop projected volumes for init containers
  • Loading branch information
k8s-ci-robot authored Jun 15, 2023
2 parents 6fcc5fd + 296207c commit ec04940
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cluster-autoscaler/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ func dropProjectedVolumesAndMounts(podSpec *apiv1.PodSpec) {
}
podSpec.Containers[i].VolumeMounts = volumeMounts
}

for i := range podSpec.InitContainers {
var volumeMounts []apiv1.VolumeMount
for _, mount := range podSpec.InitContainers[i].VolumeMounts {
if ok := projectedVolumeNames[mount.Name]; !ok {
volumeMounts = append(volumeMounts, mount)
}
}
podSpec.InitContainers[i].VolumeMounts = volumeMounts
}
}

func dropHostname(podSpec *apiv1.PodSpec) {
Expand Down
4 changes: 4 additions & 0 deletions cluster-autoscaler/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,17 @@ func TestSanitizePodSpec(t *testing.T) {
},
Containers: []apiv1.Container{
{Image: "foo/bar", Name: "foobar", VolumeMounts: []apiv1.VolumeMount{{Name: "projected1"}}},
},
InitContainers: []apiv1.Container{
{Image: "foo/baz", Name: "foobaz", VolumeMounts: []apiv1.VolumeMount{{Name: "projected2"}}},
},
},
outputPodSpec: apiv1.PodSpec{
NodeSelector: map[string]string{"foo": "bar"},
Containers: []apiv1.Container{
{Image: "foo/bar", Name: "foobar"},
},
InitContainers: []apiv1.Container{
{Image: "foo/baz", Name: "foobaz"},
},
},
Expand Down

0 comments on commit ec04940

Please sign in to comment.