Skip to content

Commit 684fbd6

Browse files
committed
remove AllowImageVolumeSource
1 parent 24a50a3 commit 684fbd6

File tree

4 files changed

+17
-85
lines changed

4 files changed

+17
-85
lines changed

pkg/api/pod/util.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,6 @@ func GetValidationOptionsFromPodSpecAndMeta(podSpec, oldPodSpec *api.PodSpec, po
385385
AllowInvalidTopologySpreadConstraintLabelSelector: false,
386386
AllowNamespacedSysctlsForHostNetAndHostIPC: false,
387387
AllowNonLocalProjectedTokenPath: false,
388-
AllowImageVolumeSource: utilfeature.DefaultFeatureGate.Enabled(features.ImageVolume),
389388
}
390389

391390
// If old spec uses relaxed validation or enabled the RelaxedEnvironmentVariableValidation feature gate,
@@ -416,9 +415,6 @@ func GetValidationOptionsFromPodSpecAndMeta(podSpec, oldPodSpec *api.PodSpec, po
416415
}
417416
}
418417
}
419-
420-
// if old spec has used image volume source, we must allow it
421-
opts.AllowImageVolumeSource = opts.AllowImageVolumeSource || hasUsedImageVolumeSourceWithPodSpec(oldPodSpec)
422418
}
423419
if oldPodMeta != nil && !opts.AllowInvalidPodDeletionCost {
424420
// This is an update, so validate only if the existing object was valid.
@@ -584,19 +580,6 @@ func hasUsedDownwardAPIFieldPathWithContainer(container *api.Container, fieldPat
584580
return false
585581
}
586582

587-
func hasUsedImageVolumeSourceWithPodSpec(podSpec *api.PodSpec) bool {
588-
if podSpec == nil {
589-
return false
590-
}
591-
592-
for _, vol := range podSpec.Volumes {
593-
if vol.Image != nil {
594-
return true
595-
}
596-
}
597-
return false
598-
}
599-
600583
// GetValidationOptionsFromPodTemplate will return pod validation options for specified template.
601584
func GetValidationOptionsFromPodTemplate(podTemplate, oldPodTemplate *api.PodTemplateSpec) apivalidation.PodValidationOptions {
602585
var newPodSpec, oldPodSpec *api.PodSpec

pkg/api/pod/util_test.go

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2553,48 +2553,6 @@ func TestValidateAllowNonLocalProjectedTokenPathOption(t *testing.T) {
25532553
}
25542554
}
25552555

2556-
func TestValidateAllowImageVolumeSourceOption(t *testing.T) {
2557-
testCases := []struct {
2558-
name string
2559-
oldPodSpec *api.PodSpec
2560-
featureEnabled bool
2561-
wantOption bool
2562-
}{
2563-
{
2564-
name: "CreateFeatureEnabled",
2565-
featureEnabled: true,
2566-
wantOption: true,
2567-
},
2568-
{
2569-
name: "CreateFeatureDisabled",
2570-
featureEnabled: false,
2571-
wantOption: false,
2572-
},
2573-
{
2574-
name: "UpdateFeatureDisabled",
2575-
oldPodSpec: &api.PodSpec{Volumes: []api.Volume{{VolumeSource: api.VolumeSource{Image: &api.ImageVolumeSource{Reference: "image"}}}}},
2576-
featureEnabled: false,
2577-
wantOption: true,
2578-
},
2579-
{
2580-
name: "UpdateFeatureEnabled",
2581-
oldPodSpec: &api.PodSpec{Volumes: []api.Volume{{VolumeSource: api.VolumeSource{Image: &api.ImageVolumeSource{Reference: "image"}}}}},
2582-
featureEnabled: true,
2583-
wantOption: true,
2584-
},
2585-
}
2586-
2587-
for _, tc := range testCases {
2588-
t.Run(tc.name, func(t *testing.T) {
2589-
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ImageVolume, tc.featureEnabled)
2590-
gotOptions := GetValidationOptionsFromPodSpecAndMeta(nil, tc.oldPodSpec, nil, nil)
2591-
if tc.wantOption != gotOptions.AllowImageVolumeSource {
2592-
t.Errorf("unexpected diff, want: %v, got: %v", tc.wantOption, gotOptions.AllowImageVolumeSource)
2593-
}
2594-
})
2595-
}
2596-
}
2597-
25982556
func TestDropInPlacePodVerticalScaling(t *testing.T) {
25992557
podWithInPlaceVerticalScaling := func() *api.Pod {
26002558
return &api.Pod{

pkg/apis/core/validation/validation.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ func validateVolumeSource(source *core.VolumeSource, fldPath *field.Path, volNam
741741
}
742742
}
743743
}
744-
if opts.AllowImageVolumeSource && source.Image != nil {
744+
if source.Image != nil {
745745
if numVolumes > 0 {
746746
allErrs = append(allErrs, field.Forbidden(fldPath.Child("image"), "may not specify more than 1 volume type"))
747747
} else {
@@ -2940,14 +2940,12 @@ func ValidateVolumeMounts(mounts []core.VolumeMount, voldevices map[string]strin
29402940
}
29412941

29422942
// Disallow subPath/subPathExpr for image volumes
2943-
if opts.AllowImageVolumeSource {
2944-
if v, ok := volumes[mnt.Name]; ok && v.Image != nil {
2945-
if len(mnt.SubPath) != 0 {
2946-
allErrs = append(allErrs, field.Invalid(idxPath.Child("subPath"), mnt.SubPath, "not allowed in image volume sources"))
2947-
}
2948-
if len(mnt.SubPathExpr) != 0 {
2949-
allErrs = append(allErrs, field.Invalid(idxPath.Child("subPathExpr"), mnt.SubPathExpr, "not allowed in image volume sources"))
2950-
}
2943+
if v, ok := volumes[mnt.Name]; ok && v.Image != nil {
2944+
if len(mnt.SubPath) != 0 {
2945+
allErrs = append(allErrs, field.Invalid(idxPath.Child("subPath"), mnt.SubPath, "not allowed in image volume sources"))
2946+
}
2947+
if len(mnt.SubPathExpr) != 0 {
2948+
allErrs = append(allErrs, field.Invalid(idxPath.Child("subPathExpr"), mnt.SubPathExpr, "not allowed in image volume sources"))
29512949
}
29522950
}
29532951

@@ -4049,8 +4047,6 @@ type PodValidationOptions struct {
40494047
ResourceIsPod bool
40504048
// Allow relaxed validation of environment variable names
40514049
AllowRelaxedEnvironmentVariableValidation bool
4052-
// Allow the use of the ImageVolumeSource API.
4053-
AllowImageVolumeSource bool
40544050
// Allow the use of a relaxed DNS search
40554051
AllowRelaxedDNSSearchValidation bool
40564052
}

pkg/apis/core/validation/validation_test.go

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5378,19 +5378,14 @@ func TestValidateVolumes(t *testing.T) {
53785378
},
53795379
},
53805380
},
5381-
opts: PodValidationOptions{AllowImageVolumeSource: true},
5381+
opts: PodValidationOptions{},
53825382
}, {
5383-
name: "feature disabled",
5383+
name: "no volume source",
53845384
vol: core.Volume{
5385-
Name: "image-volume",
5386-
VolumeSource: core.VolumeSource{
5387-
Image: &core.ImageVolumeSource{
5388-
Reference: "quay.io/my/artifact:v1",
5389-
PullPolicy: "IfNotPresent",
5390-
},
5391-
},
5385+
Name: "volume",
5386+
VolumeSource: core.VolumeSource{},
53925387
},
5393-
opts: PodValidationOptions{AllowImageVolumeSource: false},
5388+
opts: PodValidationOptions{},
53945389
errs: []verr{{
53955390
etype: field.ErrorTypeRequired,
53965391
field: "field[0]",
@@ -5407,7 +5402,7 @@ func TestValidateVolumes(t *testing.T) {
54075402
},
54085403
},
54095404
},
5410-
opts: PodValidationOptions{AllowImageVolumeSource: true},
5405+
opts: PodValidationOptions{},
54115406
errs: []verr{{
54125407
etype: field.ErrorTypeRequired,
54135408
field: "name",
@@ -5423,7 +5418,7 @@ func TestValidateVolumes(t *testing.T) {
54235418
},
54245419
},
54255420
},
5426-
opts: PodValidationOptions{AllowImageVolumeSource: true, ResourceIsPod: true},
5421+
opts: PodValidationOptions{ResourceIsPod: true},
54275422
errs: []verr{{
54285423
etype: field.ErrorTypeRequired,
54295424
field: "image.reference",
@@ -5439,7 +5434,7 @@ func TestValidateVolumes(t *testing.T) {
54395434
},
54405435
},
54415436
},
5442-
opts: PodValidationOptions{AllowImageVolumeSource: true, ResourceIsPod: false},
5437+
opts: PodValidationOptions{ResourceIsPod: false},
54435438
}, {
54445439
name: "image volume with wrong pullPolicy",
54455440
vol: core.Volume{
@@ -5451,7 +5446,7 @@ func TestValidateVolumes(t *testing.T) {
54515446
},
54525447
},
54535448
},
5454-
opts: PodValidationOptions{AllowImageVolumeSource: true},
5449+
opts: PodValidationOptions{},
54555450
errs: []verr{{
54565451
etype: field.ErrorTypeNotSupported,
54575452
field: "image.pullPolicy",
@@ -7066,7 +7061,7 @@ func TestValidateVolumeMounts(t *testing.T) {
70667061
}}}},
70677062
{Name: "image-volume", VolumeSource: core.VolumeSource{Image: &core.ImageVolumeSource{Reference: "quay.io/my/artifact:v1", PullPolicy: "IfNotPresent"}}},
70687063
}
7069-
opts := PodValidationOptions{AllowImageVolumeSource: true}
7064+
opts := PodValidationOptions{}
70707065
vols, v1err := ValidateVolumes(volumes, nil, field.NewPath("field"), opts)
70717066
if len(v1err) > 0 {
70727067
t.Errorf("Invalid test volume - expected success %v", v1err)

0 commit comments

Comments
 (0)