kubelet: Support ClusterTrustBundlePEM projections
This commit is contained in:
@@ -1002,18 +1002,14 @@ func dropDisabledClusterTrustBundleProjection(podSpec, oldPodSpec *api.PodSpec)
|
||||
return
|
||||
}
|
||||
|
||||
for _, v := range podSpec.Volumes {
|
||||
if v.Projected == nil {
|
||||
for i := range podSpec.Volumes {
|
||||
if podSpec.Volumes[i].Projected == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
filteredSources := []api.VolumeProjection{}
|
||||
for _, s := range v.Projected.Sources {
|
||||
if s.ClusterTrustBundle == nil {
|
||||
filteredSources = append(filteredSources, s)
|
||||
}
|
||||
for j := range podSpec.Volumes[i].Projected.Sources {
|
||||
podSpec.Volumes[i].Projected.Sources[j].ClusterTrustBundle = nil
|
||||
}
|
||||
v.Projected.Sources = filteredSources
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -3237,3 +3237,156 @@ func TestMarkPodProposedForResize(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDropClusterTrustBundleProjectedVolumes(t *testing.T) {
|
||||
testCases := []struct {
|
||||
description string
|
||||
clusterTrustBundleProjectionEnabled bool
|
||||
oldPod *api.PodSpec
|
||||
newPod *api.PodSpec
|
||||
wantPod *api.PodSpec
|
||||
}{
|
||||
{
|
||||
description: "feature gate disabled, cannot add CTB volume to pod",
|
||||
oldPod: &api.PodSpec{
|
||||
Volumes: []api.Volume{},
|
||||
},
|
||||
newPod: &api.PodSpec{
|
||||
Volumes: []api.Volume{
|
||||
{
|
||||
Name: "foo",
|
||||
VolumeSource: api.VolumeSource{
|
||||
Projected: &api.ProjectedVolumeSource{
|
||||
Sources: []api.VolumeProjection{
|
||||
{
|
||||
ClusterTrustBundle: &api.ClusterTrustBundleProjection{
|
||||
Name: pointer.String("foo"),
|
||||
},
|
||||
},
|
||||
},
|
||||
}},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantPod: &api.PodSpec{
|
||||
Volumes: []api.Volume{
|
||||
{
|
||||
Name: "foo",
|
||||
VolumeSource: api.VolumeSource{
|
||||
Projected: &api.ProjectedVolumeSource{
|
||||
Sources: []api.VolumeProjection{
|
||||
{},
|
||||
},
|
||||
}},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "feature gate disabled, can keep CTB volume on pod",
|
||||
oldPod: &api.PodSpec{
|
||||
Volumes: []api.Volume{
|
||||
{
|
||||
Name: "foo",
|
||||
VolumeSource: api.VolumeSource{
|
||||
Projected: &api.ProjectedVolumeSource{
|
||||
Sources: []api.VolumeProjection{
|
||||
{
|
||||
ClusterTrustBundle: &api.ClusterTrustBundleProjection{
|
||||
Name: pointer.String("foo"),
|
||||
},
|
||||
},
|
||||
},
|
||||
}},
|
||||
},
|
||||
},
|
||||
},
|
||||
newPod: &api.PodSpec{
|
||||
Volumes: []api.Volume{
|
||||
{
|
||||
Name: "foo",
|
||||
VolumeSource: api.VolumeSource{
|
||||
Projected: &api.ProjectedVolumeSource{
|
||||
Sources: []api.VolumeProjection{
|
||||
{
|
||||
ClusterTrustBundle: &api.ClusterTrustBundleProjection{
|
||||
Name: pointer.String("foo"),
|
||||
},
|
||||
},
|
||||
},
|
||||
}},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantPod: &api.PodSpec{
|
||||
Volumes: []api.Volume{
|
||||
{
|
||||
Name: "foo",
|
||||
VolumeSource: api.VolumeSource{
|
||||
Projected: &api.ProjectedVolumeSource{
|
||||
Sources: []api.VolumeProjection{
|
||||
{
|
||||
ClusterTrustBundle: &api.ClusterTrustBundleProjection{
|
||||
Name: pointer.String("foo"),
|
||||
},
|
||||
},
|
||||
},
|
||||
}},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "feature gate enabled, can add CTB volume to pod",
|
||||
clusterTrustBundleProjectionEnabled: true,
|
||||
oldPod: &api.PodSpec{
|
||||
Volumes: []api.Volume{},
|
||||
},
|
||||
newPod: &api.PodSpec{
|
||||
Volumes: []api.Volume{
|
||||
{
|
||||
Name: "foo",
|
||||
VolumeSource: api.VolumeSource{
|
||||
Projected: &api.ProjectedVolumeSource{
|
||||
Sources: []api.VolumeProjection{
|
||||
{
|
||||
ClusterTrustBundle: &api.ClusterTrustBundleProjection{
|
||||
Name: pointer.String("foo"),
|
||||
},
|
||||
},
|
||||
},
|
||||
}},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantPod: &api.PodSpec{
|
||||
Volumes: []api.Volume{
|
||||
{
|
||||
Name: "foo",
|
||||
VolumeSource: api.VolumeSource{
|
||||
Projected: &api.ProjectedVolumeSource{
|
||||
Sources: []api.VolumeProjection{
|
||||
{
|
||||
ClusterTrustBundle: &api.ClusterTrustBundleProjection{
|
||||
Name: pointer.String("foo"),
|
||||
},
|
||||
},
|
||||
},
|
||||
}},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ClusterTrustBundleProjection, tc.clusterTrustBundleProjectionEnabled)()
|
||||
|
||||
dropDisabledClusterTrustBundleProjection(tc.newPod, tc.oldPod)
|
||||
if diff := cmp.Diff(tc.newPod, tc.wantPod); diff != "" {
|
||||
t.Fatalf("Unexpected modification to new pod; diff (-got +want)\n%s", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user