mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-15 06:43:54 +00:00
If old pod spec has used image volume source, we must allow it
This commit is contained in:
parent
e5dd48efd0
commit
24a50a3ddf
@ -416,6 +416,9 @@ func GetValidationOptionsFromPodSpecAndMeta(podSpec, oldPodSpec *api.PodSpec, po
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if old spec has used image volume source, we must allow it
|
||||
opts.AllowImageVolumeSource = opts.AllowImageVolumeSource || hasUsedImageVolumeSourceWithPodSpec(oldPodSpec)
|
||||
}
|
||||
if oldPodMeta != nil && !opts.AllowInvalidPodDeletionCost {
|
||||
// This is an update, so validate only if the existing object was valid.
|
||||
@ -581,6 +584,19 @@ func hasUsedDownwardAPIFieldPathWithContainer(container *api.Container, fieldPat
|
||||
return false
|
||||
}
|
||||
|
||||
func hasUsedImageVolumeSourceWithPodSpec(podSpec *api.PodSpec) bool {
|
||||
if podSpec == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, vol := range podSpec.Volumes {
|
||||
if vol.Image != nil {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// GetValidationOptionsFromPodTemplate will return pod validation options for specified template.
|
||||
func GetValidationOptionsFromPodTemplate(podTemplate, oldPodTemplate *api.PodTemplateSpec) apivalidation.PodValidationOptions {
|
||||
var newPodSpec, oldPodSpec *api.PodSpec
|
||||
|
@ -2553,6 +2553,48 @@ func TestValidateAllowNonLocalProjectedTokenPathOption(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateAllowImageVolumeSourceOption(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
oldPodSpec *api.PodSpec
|
||||
featureEnabled bool
|
||||
wantOption bool
|
||||
}{
|
||||
{
|
||||
name: "CreateFeatureEnabled",
|
||||
featureEnabled: true,
|
||||
wantOption: true,
|
||||
},
|
||||
{
|
||||
name: "CreateFeatureDisabled",
|
||||
featureEnabled: false,
|
||||
wantOption: false,
|
||||
},
|
||||
{
|
||||
name: "UpdateFeatureDisabled",
|
||||
oldPodSpec: &api.PodSpec{Volumes: []api.Volume{{VolumeSource: api.VolumeSource{Image: &api.ImageVolumeSource{Reference: "image"}}}}},
|
||||
featureEnabled: false,
|
||||
wantOption: true,
|
||||
},
|
||||
{
|
||||
name: "UpdateFeatureEnabled",
|
||||
oldPodSpec: &api.PodSpec{Volumes: []api.Volume{{VolumeSource: api.VolumeSource{Image: &api.ImageVolumeSource{Reference: "image"}}}}},
|
||||
featureEnabled: true,
|
||||
wantOption: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ImageVolume, tc.featureEnabled)
|
||||
gotOptions := GetValidationOptionsFromPodSpecAndMeta(nil, tc.oldPodSpec, nil, nil)
|
||||
if tc.wantOption != gotOptions.AllowImageVolumeSource {
|
||||
t.Errorf("unexpected diff, want: %v, got: %v", tc.wantOption, gotOptions.AllowImageVolumeSource)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDropInPlacePodVerticalScaling(t *testing.T) {
|
||||
podWithInPlaceVerticalScaling := func() *api.Pod {
|
||||
return &api.Pod{
|
||||
|
Loading…
Reference in New Issue
Block a user