Skip to content

Commit

Permalink
Add support for hostPath (#15648)
Browse files Browse the repository at this point in the history
* 15546: Add support for hostPath

* 15546: Fix additional Space and eof

* Fix eof

* update for EOF

* revert mess up

* remove white spaces

* added Comment

* remove extra validations as its there in K8
  • Loading branch information
amarflybot authored Jan 6, 2025
1 parent df03027 commit 0d589da
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 1 deletion.
4 changes: 4 additions & 0 deletions config/core/300-resources/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,10 @@ spec:
description: This is accessible behind a feature flag - kubernetes.podspec-emptydir
type: object
x-kubernetes-preserve-unknown-fields: true
hostPath:
description: This is accessible behind a feature flag - kubernetes.podspec-hostpath
type: object
x-kubernetes-preserve-unknown-fields: true
name:
description: |-
name of the volume.
Expand Down
4 changes: 4 additions & 0 deletions config/core/300-resources/revision.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,10 @@ spec:
description: This is accessible behind a feature flag - kubernetes.podspec-emptydir
type: object
x-kubernetes-preserve-unknown-fields: true
hostPath:
description: This is accessible behind a feature flag - kubernetes.podspec-hostpath
type: object
x-kubernetes-preserve-unknown-fields: true
name:
description: |-
name of the volume.
Expand Down
4 changes: 4 additions & 0 deletions config/core/300-resources/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,10 @@ spec:
description: This is accessible behind a feature flag - kubernetes.podspec-emptydir
type: object
x-kubernetes-preserve-unknown-fields: true
hostPath:
description: This is accessible behind a feature flag - kubernetes.podspec-hostpath
type: object
x-kubernetes-preserve-unknown-fields: true
name:
description: |-
name of the volume.
Expand Down
10 changes: 9 additions & 1 deletion config/core/configmaps/features.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ metadata:
app.kubernetes.io/component: controller
app.kubernetes.io/version: devel
annotations:
knative.dev/example-checksum: "9ff569ad"
knative.dev/example-checksum: "63a13754"
data:
_example: |-
################################
Expand Down Expand Up @@ -200,6 +200,14 @@ data:
# 2. Disabled: disabling EmptyDir volume support
kubernetes.podspec-volumes-emptydir: "enabled"
# Controls whether volume support for HostPath is enabled or not.
# WARNING: Cannot safely be disabled once enabled.
# WARNING: If you can avoid using a hostPath volume, you should.
# Please read https://kubernetes.io/docs/concepts/storage/volumes/#hostpath before enabling this feature.
# 1. Enabled: enabling HostPath volume support
# 2. Disabled: disabling HostPath volume support
kubernetes.podspec-volumes-hostpath: "disabled"
# Controls whether init containers support is enabled or not.
# 1. Enabled: enabling init containers support
# 2. Disabled: disabling init containers support
Expand Down
7 changes: 7 additions & 0 deletions hack/schemapatch-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ k8s.io/api/core/v1.VolumeSource:
# Following are behind feature flags
- EmptyDir
- PersistentVolumeClaim
- HostPath
k8s.io/api/core/v1.PersistentVolumeClaimVolumeSource:
description: "This is accessible behind a feature flag - kubernetes.podspec-persistent-volume-claim"
additionalMarkers:
Expand All @@ -24,6 +25,12 @@ k8s.io/api/core/v1.EmptyDirVolumeSource:
# Part of a feature flag - so we want to omit the schema and preserve unknown fields
- kubebuilder:validation:DropProperties
- kubebuilder:pruning:PreserveUnknownFields
k8s.io/api/core/v1.HostPathVolumeSource:
description: "This is accessible behind a feature flag - kubernetes.podspec-hostpath"
additionalMarkers:
# Part of a feature flag - so we want to omit the schema and preserve unknown fields
- kubebuilder:validation:DropProperties
- kubebuilder:pruning:PreserveUnknownFields
k8s.io/api/core/v1.VolumeProjection:
fieldMask:
- Secret
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/config/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func defaultFeaturesConfig() *Features {
ContainerSpecAddCapabilities: Disabled,
PodSpecTolerations: Disabled,
PodSpecVolumesEmptyDir: Enabled,
PodSpecVolumesHostPath: Disabled,
PodSpecPersistentVolumeClaim: Disabled,
PodSpecPersistentVolumeWrite: Disabled,
QueueProxyMountPodInfo: Disabled,
Expand Down Expand Up @@ -107,6 +108,7 @@ func NewFeaturesConfigFromMap(data map[string]string) (*Features, error) {
asFlag("kubernetes.containerspec-addcapabilities", &nc.ContainerSpecAddCapabilities),
asFlag("kubernetes.podspec-tolerations", &nc.PodSpecTolerations),
asFlag("kubernetes.podspec-volumes-emptydir", &nc.PodSpecVolumesEmptyDir),
asFlag("kubernetes.podspec-volumes-hostpath", &nc.PodSpecVolumesHostPath),
asFlag("kubernetes.podspec-hostipc", &nc.PodSpecHostIPC),
asFlag("kubernetes.podspec-hostpid", &nc.PodSpecHostPID),
asFlag("kubernetes.podspec-hostnetwork", &nc.PodSpecHostNetwork),
Expand Down Expand Up @@ -151,6 +153,7 @@ type Features struct {
ContainerSpecAddCapabilities Flag
PodSpecTolerations Flag
PodSpecVolumesEmptyDir Flag
PodSpecVolumesHostPath Flag
PodSpecInitContainers Flag
PodSpecPersistentVolumeClaim Flag
PodSpecPersistentVolumeWrite Flag
Expand Down
18 changes: 18 additions & 0 deletions pkg/apis/config/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,24 @@ func TestFeaturesConfiguration(t *testing.T) {
data: map[string]string{
"kubernetes.podspec-volumes-emptydir": "Enabled",
},
}, {
name: "kubernetes.podspec-volumes-hostpath Disabled",
wantErr: false,
wantFeatures: defaultWith(&Features{
PodSpecVolumesHostPath: Disabled,
}),
data: map[string]string{
"kubernetes.podspec-volumes-hostpath": "Disabled",
},
}, {
name: "kubernetes.podspec-volumes-hostpath Enabled",
wantErr: false,
wantFeatures: defaultWith(&Features{
PodSpecVolumesHostPath: Enabled,
}),
data: map[string]string{
"kubernetes.podspec-volumes-hostpath": "Enabled",
},
}, {
name: "kubernetes.podspec-persistent-volume-claim Disabled",
wantErr: false,
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/serving/fieldmask.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ func VolumeSourceMask(ctx context.Context, in *corev1.VolumeSource) *corev1.Volu
out.PersistentVolumeClaim = in.PersistentVolumeClaim
}

if cfg.Features.PodSpecVolumesHostPath != config.Disabled {
out.HostPath = in.HostPath
}

// Too many disallowed fields to list

return out
Expand Down
1 change: 1 addition & 0 deletions pkg/reconciler/route/resources/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ func testConfig() *config.Config {
PodSpecNodeSelector: apiConfig.Disabled,
PodSpecTolerations: apiConfig.Disabled,
PodSpecVolumesEmptyDir: apiConfig.Disabled,
PodSpecVolumesHostPath: apiConfig.Disabled,
PodSpecPersistentVolumeClaim: apiConfig.Disabled,
PodSpecPersistentVolumeWrite: apiConfig.Disabled,
PodSpecInitContainers: apiConfig.Disabled,
Expand Down

0 comments on commit 0d589da

Please sign in to comment.