Skip to content

Commit 93023e8

Browse files
feat: add support for CSI volumes (#15815)
* feat: add support for CSI volumes * fix compilation issues --------- Co-authored-by: Dave Protasowski <dprotaso@gmail.com>
1 parent c7f03af commit 93023e8

File tree

11 files changed

+97
-1
lines changed

11 files changed

+97
-1
lines changed

cmd/schema-tweak/overrides.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ func revSpecOverrides(prefixPath string) []entry {
244244
}, {
245245
name: "hostPath",
246246
flag: config.FeaturePodSpecHostPath,
247+
}, {
248+
name: "csi",
249+
flag: config.FeaturePodSpecCSI,
247250
}},
248251
}, {
249252
path: "volumes.secret",

config/core/300-resources/configuration.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,10 @@ spec:
11631163
description: optional specify whether the ConfigMap or its keys must be defined
11641164
type: boolean
11651165
x-kubernetes-map-type: atomic
1166+
csi:
1167+
description: This is accessible behind a feature flag - kubernetes.podspec-volumes-csi
1168+
type: object
1169+
x-kubernetes-preserve-unknown-fields: true
11661170
emptyDir:
11671171
description: |-
11681172
This is accessible behind a feature flag - kubernetes.podspec-volumes-emptydir

config/core/300-resources/revision.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,10 @@ spec:
11391139
description: optional specify whether the ConfigMap or its keys must be defined
11401140
type: boolean
11411141
x-kubernetes-map-type: atomic
1142+
csi:
1143+
description: This is accessible behind a feature flag - kubernetes.podspec-volumes-csi
1144+
type: object
1145+
x-kubernetes-preserve-unknown-fields: true
11421146
emptyDir:
11431147
description: |-
11441148
This is accessible behind a feature flag - kubernetes.podspec-volumes-emptydir

config/core/300-resources/service.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,10 @@ spec:
11811181
description: optional specify whether the ConfigMap or its keys must be defined
11821182
type: boolean
11831183
x-kubernetes-map-type: atomic
1184+
csi:
1185+
description: This is accessible behind a feature flag - kubernetes.podspec-volumes-csi
1186+
type: object
1187+
x-kubernetes-preserve-unknown-fields: true
11841188
emptyDir:
11851189
description: |-
11861190
This is accessible behind a feature flag - kubernetes.podspec-volumes-emptydir

config/core/configmaps/features.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ metadata:
2222
app.kubernetes.io/component: controller
2323
app.kubernetes.io/version: devel
2424
annotations:
25-
knative.dev/example-checksum: "63a13754"
25+
knative.dev/example-checksum: "634edbdf"
2626
data:
2727
_example: |-
2828
################################
@@ -208,6 +208,11 @@ data:
208208
# 2. Disabled: disabling HostPath volume support
209209
kubernetes.podspec-volumes-hostpath: "disabled"
210210
211+
# Controls whether volume support for CSI is enabled or not.
212+
# 1. Enabled: enabling CSI volume support
213+
# 2. Disabled: disabling CSI volume support
214+
kubernetes.podspec-volumes-csi: "disabled"
215+
211216
# Controls whether init containers support is enabled or not.
212217
# 1. Enabled: enabling init containers support
213218
# 2. Disabled: disabling init containers support

pkg/apis/config/features.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const (
6565
FeaturePodSpecHostNetwork = "kubernetes.podspec-hostnetwork"
6666
FeaturePodSpecHostPID = "kubernetes.podspec-hostpid"
6767
FeaturePodSpecHostPath = "kubernetes.podspec-volumes-hostpath"
68+
FeaturePodSpecCSI = "kubernetes.podspec-volumes-csi"
6869
FeaturePodSpecInitContainers = "kubernetes.podspec-init-containers"
6970
FeaturePodSpecNodeSelector = "kubernetes.podspec-nodeselector"
7071
FeaturePodSpecPVClaim = "kubernetes.podspec-persistent-volume-claim"
@@ -99,6 +100,7 @@ func defaultFeaturesConfig() *Features {
99100
PodSpecTolerations: Disabled,
100101
PodSpecVolumesEmptyDir: Enabled,
101102
PodSpecVolumesHostPath: Disabled,
103+
PodSpecVolumesCSI: Disabled,
102104
PodSpecPersistentVolumeClaim: Disabled,
103105
PodSpecPersistentVolumeWrite: Disabled,
104106
QueueProxyMountPodInfo: Disabled,
@@ -137,6 +139,7 @@ func NewFeaturesConfigFromMap(data map[string]string) (*Features, error) {
137139
asFlag(FeaturePodSpecHostNetwork, &nc.PodSpecHostNetwork),
138140
asFlag(FeaturePodSpecHostPID, &nc.PodSpecHostPID),
139141
asFlag(FeaturePodSpecHostPath, &nc.PodSpecVolumesHostPath),
142+
asFlag(FeaturePodSpecCSI, &nc.PodSpecVolumesCSI),
140143
asFlag(FeaturePodSpecInitContainers, &nc.PodSpecInitContainers),
141144
asFlag(FeaturePodSpecNodeSelector, &nc.PodSpecNodeSelector),
142145
asFlag(FeaturePodSpecPVClaim, &nc.PodSpecPersistentVolumeClaim),
@@ -180,6 +183,7 @@ type Features struct {
180183
PodSpecTolerations Flag
181184
PodSpecVolumesEmptyDir Flag
182185
PodSpecVolumesHostPath Flag
186+
PodSpecVolumesCSI Flag
183187
PodSpecInitContainers Flag
184188
PodSpecPersistentVolumeClaim Flag
185189
PodSpecPersistentVolumeWrite Flag

pkg/apis/config/features_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,24 @@ func TestFeaturesConfiguration(t *testing.T) {
455455
data: map[string]string{
456456
"kubernetes.podspec-volumes-hostpath": "Enabled",
457457
},
458+
}, {
459+
name: "kubernetes.podspec-volumes-csi Disabled",
460+
wantErr: false,
461+
wantFeatures: defaultWith(&Features{
462+
PodSpecVolumesCSI: Disabled,
463+
}),
464+
data: map[string]string{
465+
"kubernetes.podspec-volumes-csi": "Disabled",
466+
},
467+
}, {
468+
name: "kubernetes.podspec-volumes-csi Enabled",
469+
wantErr: false,
470+
wantFeatures: defaultWith(&Features{
471+
PodSpecVolumesCSI: Enabled,
472+
}),
473+
data: map[string]string{
474+
"kubernetes.podspec-volumes-csi": "Enabled",
475+
},
458476
}, {
459477
name: "kubernetes.podspec-persistent-volume-claim Disabled",
460478
wantErr: false,

pkg/apis/serving/fieldmask.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ func VolumeSourceMask(ctx context.Context, in *corev1.VolumeSource) *corev1.Volu
7070
out.HostPath = in.HostPath
7171
}
7272

73+
if cfg.Features.PodSpecVolumesCSI != config.Disabled {
74+
out.CSI = in.CSI
75+
}
76+
7377
// Too many disallowed fields to list
7478

7579
return out

pkg/apis/serving/k8s_validation.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ func validateVolume(ctx context.Context, volume corev1.Volume) *apis.FieldError
129129
errs = errs.Also(&apis.FieldError{Message: fmt.Sprintf("HostPath volume support is disabled, "+
130130
"but found HostPath volume %s", volume.Name)})
131131
}
132+
if volume.CSI != nil && features.PodSpecVolumesCSI != config.Enabled {
133+
errs = errs.Also(&apis.FieldError{Message: fmt.Sprintf("CSI volume support is disabled, "+
134+
"but found CSI volume %s", volume.Name)})
135+
}
132136
errs = errs.Also(apis.CheckDisallowedFields(volume, *VolumeMask(ctx, &volume)))
133137
if volume.Name == "" {
134138
errs = apis.ErrMissingField("name")
@@ -169,6 +173,10 @@ func validateVolume(ctx context.Context, volume corev1.Volume) *apis.FieldError
169173
specified = append(specified, "hostPath")
170174
}
171175

176+
if vs.CSI != nil {
177+
specified = append(specified, "csi")
178+
}
179+
172180
if len(specified) == 0 {
173181
fieldPaths := []string{"secret", "configMap", "projected"}
174182
cfg := config.FromContextOrDefaults(ctx)
@@ -181,6 +189,9 @@ func validateVolume(ctx context.Context, volume corev1.Volume) *apis.FieldError
181189
if cfg.Features.PodSpecVolumesHostPath == config.Enabled {
182190
fieldPaths = append(fieldPaths, "hostPath")
183191
}
192+
if cfg.Features.PodSpecVolumesCSI == config.Enabled {
193+
fieldPaths = append(fieldPaths, "csi")
194+
}
184195
errs = errs.Also(apis.ErrMissingOneOf(fieldPaths...))
185196
} else if len(specified) > 1 {
186197
errs = errs.Also(apis.ErrMultipleOneOf(specified...))

pkg/apis/serving/k8s_validation_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ func withPodSpecVolumesHostPathEnabled() configOption {
136136
}
137137
}
138138

139+
func withPodSpecVolumesCSIEnabled() configOption {
140+
return func(cfg *config.Config) *config.Config {
141+
cfg.Features.PodSpecVolumesCSI = config.Enabled
142+
return cfg
143+
}
144+
}
145+
139146
func withPodSpecPersistentVolumeWriteEnabled() configOption {
140147
return func(cfg *config.Config) *config.Config {
141148
cfg.Features.PodSpecPersistentVolumeWrite = config.Enabled
@@ -2921,6 +2928,37 @@ func TestVolumeValidation(t *testing.T) {
29212928
},
29222929
cfgOpts: []configOption{withPodSpecVolumesHostPathEnabled()},
29232930
want: apis.ErrMissingOneOf("secret", "configMap", "projected", "emptyDir", "hostPath"),
2931+
}, {
2932+
name: "valid CSI volume with feature enabled",
2933+
v: corev1.Volume{
2934+
Name: "foo",
2935+
VolumeSource: corev1.VolumeSource{
2936+
CSI: &corev1.CSIVolumeSource{
2937+
Driver: "foo",
2938+
},
2939+
},
2940+
},
2941+
cfgOpts: []configOption{withPodSpecVolumesCSIEnabled()},
2942+
}, {
2943+
name: "CSI volume with feature disabled",
2944+
v: corev1.Volume{
2945+
Name: "foo",
2946+
VolumeSource: corev1.VolumeSource{
2947+
CSI: &corev1.CSIVolumeSource{
2948+
Driver: "foo",
2949+
},
2950+
},
2951+
},
2952+
want: (&apis.FieldError{
2953+
Message: `CSI volume support is disabled, but found CSI volume foo`,
2954+
}).Also(&apis.FieldError{Message: "must not set the field(s)", Paths: []string{"csi"}}),
2955+
}, {
2956+
name: "missing CSI volume when required",
2957+
v: corev1.Volume{
2958+
Name: "foo",
2959+
},
2960+
cfgOpts: []configOption{withPodSpecVolumesCSIEnabled()},
2961+
want: apis.ErrMissingOneOf("secret", "configMap", "projected", "emptyDir", "csi"),
29242962
}, {
29252963
name: "valid PVC with PVC feature enabled",
29262964
v: corev1.Volume{

0 commit comments

Comments
 (0)