KEP-3721: Support for env files (#132626)

* Add FileKeyRef field and struct to the Pod API

* Add the implementation code in the kubelet.

* Add validation code

* Add basic functionality e2e tests

* add codes for drop disabled pod fields

* update go.mod

Kubernetes-commit: 6f3b6b91f08585727784620285f990782901572f
This commit is contained in:
Bing Hongtao 2025-07-23 04:40:42 +08:00 committed by Kubernetes Publisher
parent ec5b832e60
commit a052c014c7
6 changed files with 103 additions and 3 deletions

View File

@ -25,6 +25,7 @@ type EnvVarSourceApplyConfiguration struct {
ResourceFieldRef *ResourceFieldSelectorApplyConfiguration `json:"resourceFieldRef,omitempty"`
ConfigMapKeyRef *ConfigMapKeySelectorApplyConfiguration `json:"configMapKeyRef,omitempty"`
SecretKeyRef *SecretKeySelectorApplyConfiguration `json:"secretKeyRef,omitempty"`
FileKeyRef *FileKeySelectorApplyConfiguration `json:"fileKeyRef,omitempty"`
}
// EnvVarSourceApplyConfiguration constructs a declarative configuration of the EnvVarSource type for use with
@ -64,3 +65,11 @@ func (b *EnvVarSourceApplyConfiguration) WithSecretKeyRef(value *SecretKeySelect
b.SecretKeyRef = value
return b
}
// WithFileKeyRef sets the FileKeyRef field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the FileKeyRef field is set to the value of the last call.
func (b *EnvVarSourceApplyConfiguration) WithFileKeyRef(value *FileKeySelectorApplyConfiguration) *EnvVarSourceApplyConfiguration {
b.FileKeyRef = value
return b
}

View File

@ -0,0 +1,66 @@
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by applyconfiguration-gen. DO NOT EDIT.
package v1
// FileKeySelectorApplyConfiguration represents a declarative configuration of the FileKeySelector type for use
// with apply.
type FileKeySelectorApplyConfiguration struct {
VolumeName *string `json:"volumeName,omitempty"`
Path *string `json:"path,omitempty"`
Key *string `json:"key,omitempty"`
Optional *bool `json:"optional,omitempty"`
}
// FileKeySelectorApplyConfiguration constructs a declarative configuration of the FileKeySelector type for use with
// apply.
func FileKeySelector() *FileKeySelectorApplyConfiguration {
return &FileKeySelectorApplyConfiguration{}
}
// WithVolumeName sets the VolumeName field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the VolumeName field is set to the value of the last call.
func (b *FileKeySelectorApplyConfiguration) WithVolumeName(value string) *FileKeySelectorApplyConfiguration {
b.VolumeName = &value
return b
}
// WithPath sets the Path field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the Path field is set to the value of the last call.
func (b *FileKeySelectorApplyConfiguration) WithPath(value string) *FileKeySelectorApplyConfiguration {
b.Path = &value
return b
}
// WithKey sets the Key field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the Key field is set to the value of the last call.
func (b *FileKeySelectorApplyConfiguration) WithKey(value string) *FileKeySelectorApplyConfiguration {
b.Key = &value
return b
}
// WithOptional sets the Optional field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the Optional field is set to the value of the last call.
func (b *FileKeySelectorApplyConfiguration) WithOptional(value bool) *FileKeySelectorApplyConfiguration {
b.Optional = &value
return b
}

View File

@ -5702,6 +5702,9 @@ var schemaYAML = typed.YAMLObject(`types:
- name: fieldRef
type:
namedType: io.k8s.api.core.v1.ObjectFieldSelector
- name: fileKeyRef
type:
namedType: io.k8s.api.core.v1.FileKeySelector
- name: resourceFieldRef
type:
namedType: io.k8s.api.core.v1.ResourceFieldSelector
@ -5937,6 +5940,26 @@ var schemaYAML = typed.YAMLObject(`types:
elementType:
scalar: string
elementRelationship: atomic
- name: io.k8s.api.core.v1.FileKeySelector
map:
fields:
- name: key
type:
scalar: string
default: ""
- name: optional
type:
scalar: boolean
default: false
- name: path
type:
scalar: string
default: ""
- name: volumeName
type:
scalar: string
default: ""
elementRelationship: atomic
- name: io.k8s.api.core.v1.FlexPersistentVolumeSource
map:
fields:

View File

@ -780,6 +780,8 @@ func ForKind(kind schema.GroupVersionKind) interface{} {
return &applyconfigurationscorev1.ExecActionApplyConfiguration{}
case corev1.SchemeGroupVersion.WithKind("FCVolumeSource"):
return &applyconfigurationscorev1.FCVolumeSourceApplyConfiguration{}
case corev1.SchemeGroupVersion.WithKind("FileKeySelector"):
return &applyconfigurationscorev1.FileKeySelectorApplyConfiguration{}
case corev1.SchemeGroupVersion.WithKind("FlexPersistentVolumeSource"):
return &applyconfigurationscorev1.FlexPersistentVolumeSourceApplyConfiguration{}
case corev1.SchemeGroupVersion.WithKind("FlexVolumeSource"):

2
go.mod
View File

@ -25,7 +25,7 @@ require (
golang.org/x/time v0.9.0
google.golang.org/protobuf v1.36.5
gopkg.in/evanphx/json-patch.v4 v4.12.0
k8s.io/api v0.0.0-20250722050559-d0d89ae64553
k8s.io/api v0.0.0-20250722204042-c68fbbed1649
k8s.io/apimachinery v0.0.0-20250722010832-c04562bf9e0a
k8s.io/klog/v2 v2.130.1
k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b

4
go.sum
View File

@ -150,8 +150,8 @@ gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/api v0.0.0-20250722050559-d0d89ae64553 h1:wESDI5DxMyUWVXAtRZbjPxWg2GBEjwM+VSh+dlMZemI=
k8s.io/api v0.0.0-20250722050559-d0d89ae64553/go.mod h1:FvioxCEMxTNUCXlpYjmaOHhxfVFA8yAGncDC2nhYf7w=
k8s.io/api v0.0.0-20250722204042-c68fbbed1649 h1:HLNbFkZn1/O3wPdTUDOFXtPPQxM/h89c5whVWROHdX0=
k8s.io/api v0.0.0-20250722204042-c68fbbed1649/go.mod h1:FvioxCEMxTNUCXlpYjmaOHhxfVFA8yAGncDC2nhYf7w=
k8s.io/apimachinery v0.0.0-20250722010832-c04562bf9e0a h1:eD5rad0CO40MFvvZ6y4G6wAcEIcMu9ddsZWj20RM3Ok=
k8s.io/apimachinery v0.0.0-20250722010832-c04562bf9e0a/go.mod h1:v1p1Jsze3IHLy5gU17yVqR2qLO7jgYeX6mw3HZy2AEU=
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=