Skip to content

Commit df66ee6

Browse files
authored
Merge pull request kubernetes#126733 from carlory/fix-image-volume-validation
If old pod spec has used image volume source, we must allow it
2 parents 963ebd8 + 684fbd6 commit df66ee6

File tree

3 files changed

+17
-27
lines changed

3 files changed

+17
-27
lines changed

pkg/api/pod/util.go

Lines changed: 0 additions & 1 deletion
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,

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)