From 6a4751da7fa2d3b9c360f98d13e84f09dd21eaf8 Mon Sep 17 00:00:00 2001 From: HirazawaUi <695097494plus@gmail.com> Date: Mon, 2 Jun 2025 17:50:41 +0800 Subject: [PATCH] Graduate RelaxedEnvironmentVariableValidation Feature gate to GA --- pkg/features/kube_features.go | 1 + pkg/kubelet/kubelet_pods_test.go | 30 ++++---- .../reference/versioned_feature_list.yaml | 4 ++ test/e2e/common/node/configmap.go | 68 +++++++++---------- test/e2e/common/node/expansion.go | 3 +- test/e2e/common/node/secrets.go | 3 +- test/e2e/feature/feature.go | 4 -- 7 files changed, 53 insertions(+), 60 deletions(-) diff --git a/pkg/features/kube_features.go b/pkg/features/kube_features.go index c418e72bf71..8cf73ada6a7 100644 --- a/pkg/features/kube_features.go +++ b/pkg/features/kube_features.go @@ -1663,6 +1663,7 @@ var defaultVersionedKubernetesFeatureGates = map[featuregate.Feature]featuregate RelaxedEnvironmentVariableValidation: { {Version: version.MustParse("1.30"), Default: false, PreRelease: featuregate.Alpha}, {Version: version.MustParse("1.32"), Default: true, PreRelease: featuregate.Beta}, + {Version: version.MustParse("1.34"), Default: true, PreRelease: featuregate.GA, LockToDefault: true}, // remove in 1.37 }, ReloadKubeletServerCertificateFile: { diff --git a/pkg/kubelet/kubelet_pods_test.go b/pkg/kubelet/kubelet_pods_test.go index 6213eaaca36..56ecccafbcf 100644 --- a/pkg/kubelet/kubelet_pods_test.go +++ b/pkg/kubelet/kubelet_pods_test.go @@ -408,20 +408,19 @@ func TestMakeEnvironmentVariables(t *testing.T) { trueValue := true falseValue := false testCases := []struct { - name string // the name of the test case - ns string // the namespace to generate environment for - enableServiceLinks *bool // enabling service links - enableRelaxedEnvironmentVariableValidation bool // enable enableRelaxedEnvironmentVariableValidation feature gate - container *v1.Container // the container to use - nilLister bool // whether the lister should be nil - staticPod bool // whether the pod should be a static pod (versus an API pod) - unsyncedServices bool // whether the services should NOT be synced - configMap *v1.ConfigMap // an optional ConfigMap to pull from - secret *v1.Secret // an optional Secret to pull from - podIPs []string // the pod IPs - expectedEnvs []kubecontainer.EnvVar // a set of expected environment vars - expectedError bool // does the test fail - expectedEvent string // does the test emit an event + name string // the name of the test case + ns string // the namespace to generate environment for + enableServiceLinks *bool // enabling service links + container *v1.Container // the container to use + nilLister bool // whether the lister should be nil + staticPod bool // whether the pod should be a static pod (versus an API pod) + unsyncedServices bool // whether the services should NOT be synced + configMap *v1.ConfigMap // an optional ConfigMap to pull from + secret *v1.Secret // an optional Secret to pull from + podIPs []string // the pod IPs + expectedEnvs []kubecontainer.EnvVar // a set of expected environment vars + expectedError bool // does the test fail + expectedEvent string // does the test emit an event }{ { name: "if services aren't synced, non-static pods should fail", @@ -1339,7 +1338,6 @@ func TestMakeEnvironmentVariables(t *testing.T) { name: "configmap allow prefix to start with a digital", ns: "test1", enableServiceLinks: &falseValue, - enableRelaxedEnvironmentVariableValidation: true, container: &v1.Container{ EnvFrom: []v1.EnvFromSource{ { @@ -1975,8 +1973,6 @@ func TestMakeEnvironmentVariables(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.RelaxedEnvironmentVariableValidation, tc.enableRelaxedEnvironmentVariableValidation) - fakeRecorder := record.NewFakeRecorder(1) testKubelet := newTestKubelet(t, false /* controllerAttachDetachEnabled */) testKubelet.kubelet.recorder = fakeRecorder diff --git a/test/compatibility_lifecycle/reference/versioned_feature_list.yaml b/test/compatibility_lifecycle/reference/versioned_feature_list.yaml index aa0dfbf5f43..c0d05d8cf9a 100644 --- a/test/compatibility_lifecycle/reference/versioned_feature_list.yaml +++ b/test/compatibility_lifecycle/reference/versioned_feature_list.yaml @@ -1189,6 +1189,10 @@ lockToDefault: false preRelease: Beta version: "1.32" + - default: true + lockToDefault: true + preRelease: GA + version: "1.34" - name: ReloadKubeletServerCertificateFile versionedSpecs: - default: true diff --git a/test/e2e/common/node/configmap.go b/test/e2e/common/node/configmap.go index 309441c1634..e795bd42498 100644 --- a/test/e2e/common/node/configmap.go +++ b/test/e2e/common/node/configmap.go @@ -25,7 +25,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/uuid" - "k8s.io/kubernetes/test/e2e/feature" "k8s.io/kubernetes/test/e2e/framework" e2epodoutput "k8s.io/kubernetes/test/e2e/framework/pod/output" imageutils "k8s.io/kubernetes/test/utils/image" @@ -250,47 +249,46 @@ var _ = SIGDescribe("ConfigMap", func() { Description: Create a Pod with an environment variable value set using a value from ConfigMap. Allows users to use envFrom to set prefix starting with a digit as environment variable names. */ - framework.It("should be consumable as environment variable names when configmap keys start with a digit", - feature.RelaxedEnvironmentVariableValidation, func(ctx context.Context) { - name := "configmap-test-" + string(uuid.NewUUID()) - configMap := newConfigMap(f, name) - ginkgo.By(fmt.Sprintf("Creating configMap %v/%v", f.Namespace.Name, configMap.Name)) - var err error - if configMap, err = f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Create(ctx, configMap, metav1.CreateOptions{}); err != nil { - framework.Failf("unable to create test configMap %s: %v", configMap.Name, err) - } + framework.It("should be consumable as environment variable names when configmap keys start with a digit", func(ctx context.Context) { + name := "configmap-test-" + string(uuid.NewUUID()) + configMap := newConfigMap(f, name) + ginkgo.By(fmt.Sprintf("Creating configMap %v/%v", f.Namespace.Name, configMap.Name)) + var err error + if configMap, err = f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Create(ctx, configMap, metav1.CreateOptions{}); err != nil { + framework.Failf("unable to create test configMap %s: %v", configMap.Name, err) + } - pod := &v1.Pod{ - ObjectMeta: metav1.ObjectMeta{ - Name: "pod-configmaps-" + string(uuid.NewUUID()), - }, - Spec: v1.PodSpec{ - Containers: []v1.Container{ - { - Name: "env-test", - Image: imageutils.GetE2EImage(imageutils.BusyBox), - Command: []string{"sh", "-c", "env"}, - EnvFrom: []v1.EnvFromSource{ - { - ConfigMapRef: &v1.ConfigMapEnvSource{LocalObjectReference: v1.LocalObjectReference{Name: name}}, - }, - { - // prefix start with a digit can be consumed as environment variables. - Prefix: "1-", - ConfigMapRef: &v1.ConfigMapEnvSource{LocalObjectReference: v1.LocalObjectReference{Name: name}}, - }, + pod := &v1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Name: "pod-configmaps-" + string(uuid.NewUUID()), + }, + Spec: v1.PodSpec{ + Containers: []v1.Container{ + { + Name: "env-test", + Image: imageutils.GetE2EImage(imageutils.BusyBox), + Command: []string{"sh", "-c", "env"}, + EnvFrom: []v1.EnvFromSource{ + { + ConfigMapRef: &v1.ConfigMapEnvSource{LocalObjectReference: v1.LocalObjectReference{Name: name}}, + }, + { + // prefix start with a digit can be consumed as environment variables. + Prefix: "1-", + ConfigMapRef: &v1.ConfigMapEnvSource{LocalObjectReference: v1.LocalObjectReference{Name: name}}, }, }, }, - RestartPolicy: v1.RestartPolicyNever, }, - } + RestartPolicy: v1.RestartPolicyNever, + }, + } - e2epodoutput.TestContainerOutput(ctx, f, "consume configMaps", pod, 0, []string{ - "data-1=value-1", "data-2=value-2", "data-3=value-3", - "1-data-1=value-1", "1-data-2=value-2", "1-data-3=value-3", - }) + e2epodoutput.TestContainerOutput(ctx, f, "consume configMaps", pod, 0, []string{ + "data-1=value-1", "data-2=value-2", "data-3=value-3", + "1-data-1=value-1", "1-data-2=value-2", "1-data-3=value-3", }) + }) }) func newConfigMap(f *framework.Framework, name string) *v1.ConfigMap { diff --git a/test/e2e/common/node/expansion.go b/test/e2e/common/node/expansion.go index 6417ff9ff4c..702610f1343 100644 --- a/test/e2e/common/node/expansion.go +++ b/test/e2e/common/node/expansion.go @@ -22,7 +22,6 @@ import ( v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/uuid" - "k8s.io/kubernetes/test/e2e/feature" "k8s.io/kubernetes/test/e2e/framework" e2epod "k8s.io/kubernetes/test/e2e/framework/pod" e2epodoutput "k8s.io/kubernetes/test/e2e/framework/pod/output" @@ -379,7 +378,7 @@ var _ = SIGDescribe("Variable Expansion", func() { Description: Create a Pod with environment variables. Environment variables defined using previously defined environment variables MUST expand to proper values. Allow almost all printable ASCII characters in environment variables. */ - framework.It("allow almost all printable ASCII characters as environment variable names", feature.RelaxedEnvironmentVariableValidation, func(ctx context.Context) { + framework.It("allow almost all printable ASCII characters as environment variable names", func(ctx context.Context) { envVars := []v1.EnvVar{ { Name: "!\"#$%&'()", diff --git a/test/e2e/common/node/secrets.go b/test/e2e/common/node/secrets.go index 29be3811933..be5fe239a41 100644 --- a/test/e2e/common/node/secrets.go +++ b/test/e2e/common/node/secrets.go @@ -26,7 +26,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/uuid" - "k8s.io/kubernetes/test/e2e/feature" "k8s.io/kubernetes/test/e2e/framework" e2epodoutput "k8s.io/kubernetes/test/e2e/framework/pod/output" imageutils "k8s.io/kubernetes/test/utils/image" @@ -246,7 +245,7 @@ var _ = SIGDescribe("Secrets", func() { Description: Create a secret. Create a Pod with Container that declares a environment variable using 'EnvFrom' which references the secret created to extract a key value from the secret. Allows users to use envFrom to set prefix starting with a digit as environment variable names. */ - framework.It("should be consumable as environment variable names when secret keys start with a digit", feature.RelaxedEnvironmentVariableValidation, func(ctx context.Context) { + framework.It("should be consumable as environment variable names when secret keys start with a digit", func(ctx context.Context) { name := "secret-test-" + string(uuid.NewUUID()) secret := secretForTest(f.Namespace.Name, name) diff --git a/test/e2e/feature/feature.go b/test/e2e/feature/feature.go index 86caa4e5cee..7487d840906 100644 --- a/test/e2e/feature/feature.go +++ b/test/e2e/feature/feature.go @@ -368,10 +368,6 @@ var ( // TODO: document the feature (owning SIG, when to use this feature for a test) RecoverVolumeExpansionFailure = framework.WithFeature(framework.ValidFeatures.Add("RecoverVolumeExpansionFailure")) - // RelaxedEnvironmentVariableValidation used when we verify whether the pod can consume all printable ASCII characters as environment variable names, - // and whether the pod can consume configmap/secret that key starts with a number. - RelaxedEnvironmentVariableValidation = framework.WithFeature(framework.ValidFeatures.Add("RelaxedEnvironmentVariableValidation")) - // Owner: sig-network // Marks tests of KEP-4427 that require the `RelaxedDNSSearchValidation` feature gate RelaxedDNSSearchValidation = framework.WithFeature(framework.ValidFeatures.Add("RelaxedDNSSearchValidation"))