Skip to content

Commit 01689d0

Browse files
committed
add e2e tests for relaxed validation
1 parent fa3c101 commit 01689d0

File tree

4 files changed

+142
-3
lines changed

4 files changed

+142
-3
lines changed

test/e2e/common/node/configmap.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2626
"k8s.io/apimachinery/pkg/types"
2727
"k8s.io/apimachinery/pkg/util/uuid"
28+
"k8s.io/kubernetes/test/e2e/feature"
2829
"k8s.io/kubernetes/test/e2e/framework"
2930
e2epodoutput "k8s.io/kubernetes/test/e2e/framework/pod/output"
3031
imageutils "k8s.io/kubernetes/test/utils/image"
@@ -242,6 +243,54 @@ var _ = SIGDescribe("ConfigMap", func() {
242243
framework.ExpectNoError(err, "failed to list ConfigMap by LabelSelector")
243244
gomega.Expect(configMapList.Items).To(gomega.BeEmpty(), "ConfigMap is still present after being deleted by collection")
244245
})
246+
247+
/*
248+
Release: v1.30
249+
Testname: ConfigMap, from environment field
250+
Description: Create a Pod with an environment variable value set using a value from ConfigMap.
251+
Allows users to use envFrom to set prefix starting with a digit as environment variable names.
252+
*/
253+
framework.It("should be consumable as environment variable names when configmap keys start with a digit",
254+
feature.RelaxedEnvironmentVariableValidation, func(ctx context.Context) {
255+
name := "configmap-test-" + string(uuid.NewUUID())
256+
configMap := newConfigMap(f, name)
257+
ginkgo.By(fmt.Sprintf("Creating configMap %v/%v", f.Namespace.Name, configMap.Name))
258+
var err error
259+
if configMap, err = f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Create(ctx, configMap, metav1.CreateOptions{}); err != nil {
260+
framework.Failf("unable to create test configMap %s: %v", configMap.Name, err)
261+
}
262+
263+
pod := &v1.Pod{
264+
ObjectMeta: metav1.ObjectMeta{
265+
Name: "pod-configmaps-" + string(uuid.NewUUID()),
266+
},
267+
Spec: v1.PodSpec{
268+
Containers: []v1.Container{
269+
{
270+
Name: "env-test",
271+
Image: imageutils.GetE2EImage(imageutils.BusyBox),
272+
Command: []string{"sh", "-c", "env"},
273+
EnvFrom: []v1.EnvFromSource{
274+
{
275+
ConfigMapRef: &v1.ConfigMapEnvSource{LocalObjectReference: v1.LocalObjectReference{Name: name}},
276+
},
277+
{
278+
// prefix start with a digit can be consumed as environment variables.
279+
Prefix: "1-",
280+
ConfigMapRef: &v1.ConfigMapEnvSource{LocalObjectReference: v1.LocalObjectReference{Name: name}},
281+
},
282+
},
283+
},
284+
},
285+
RestartPolicy: v1.RestartPolicyNever,
286+
},
287+
}
288+
289+
e2epodoutput.TestContainerOutput(ctx, f, "consume configMaps", pod, 0, []string{
290+
"data-1=value-1", "data-2=value-2", "data-3=value-3",
291+
"1-data-1=value-1", "1-data-2=value-2", "1-data-3=value-3",
292+
})
293+
})
245294
})
246295

247296
func newConfigMap(f *framework.Framework, name string) *v1.ConfigMap {

test/e2e/common/node/expansion.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
v1 "k8s.io/api/core/v1"
2323
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2424
"k8s.io/apimachinery/pkg/util/uuid"
25+
"k8s.io/kubernetes/test/e2e/feature"
2526
"k8s.io/kubernetes/test/e2e/framework"
2627
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
2728
e2epodoutput "k8s.io/kubernetes/test/e2e/framework/pod/output"
@@ -371,6 +372,42 @@ var _ = SIGDescribe("Variable Expansion", func() {
371372
err = e2epod.DeletePodWithWait(ctx, f.ClientSet, pod)
372373
framework.ExpectNoError(err, "failed to delete pod")
373374
})
375+
376+
/*
377+
Release: v1.30
378+
Testname: Environment variables, expansion
379+
Description: Create a Pod with environment variables. Environment variables defined using previously defined environment variables MUST expand to proper values.
380+
Allow almost all printable ASCII characters in environment variables.
381+
*/
382+
framework.It("allow almost all printable ASCII characters as environment variable names", feature.RelaxedEnvironmentVariableValidation, func(ctx context.Context) {
383+
envVars := []v1.EnvVar{
384+
{
385+
Name: "!\"#$%&'()",
386+
Value: "value-1",
387+
},
388+
{
389+
Name: "* +,-./0123456789",
390+
Value: "value-2",
391+
},
392+
{
393+
Name: ":;<>?@",
394+
Value: "value-3",
395+
},
396+
{
397+
Name: "[\\]^_`{}|~",
398+
Value: "value-4",
399+
},
400+
}
401+
pod := newPod([]string{"sh", "-c", "env"}, envVars, nil, nil)
402+
403+
e2epodoutput.TestContainerOutput(ctx, f, "env composition", pod, 0, []string{
404+
"!\"#$%&'()=value-1",
405+
"* +,-./0123456789=value-2",
406+
":;<>?@=value-3",
407+
"[\\]^_`{}|~=value-4",
408+
})
409+
})
410+
374411
})
375412

376413
func testPodFailSubpath(ctx context.Context, f *framework.Framework, pod *v1.Pod) {

test/e2e/common/node/secrets.go

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,18 @@ import (
2222
"encoding/json"
2323
"fmt"
2424

25-
"github.com/onsi/ginkgo/v2"
26-
"github.com/onsi/gomega"
27-
2825
v1 "k8s.io/api/core/v1"
2926
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3027
"k8s.io/apimachinery/pkg/types"
3128
"k8s.io/apimachinery/pkg/util/uuid"
29+
"k8s.io/kubernetes/test/e2e/feature"
3230
"k8s.io/kubernetes/test/e2e/framework"
3331
e2epodoutput "k8s.io/kubernetes/test/e2e/framework/pod/output"
3432
imageutils "k8s.io/kubernetes/test/utils/image"
3533
admissionapi "k8s.io/pod-security-admission/api"
34+
35+
"github.com/onsi/ginkgo/v2"
36+
"github.com/onsi/gomega"
3637
)
3738

3839
var _ = SIGDescribe("Secrets", func() {
@@ -238,6 +239,54 @@ var _ = SIGDescribe("Secrets", func() {
238239
framework.Failf("secret %s/%s was not deleted successfully", f.Namespace.Name, secretTestName)
239240
}
240241
})
242+
243+
/*
244+
Release: v1.30
245+
Testname: Secrets, pod environment from source
246+
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.
247+
Allows users to use envFrom to set prefix starting with a digit as environment variable names.
248+
*/
249+
framework.It("should be consumable as environment variable names when secret keys start with a digit", feature.RelaxedEnvironmentVariableValidation, func(ctx context.Context) {
250+
name := "secret-test-" + string(uuid.NewUUID())
251+
secret := secretForTest(f.Namespace.Name, name)
252+
253+
ginkgo.By(fmt.Sprintf("creating secret %v/%v", f.Namespace.Name, secret.Name))
254+
var err error
255+
if secret, err = f.ClientSet.CoreV1().Secrets(f.Namespace.Name).Create(ctx, secret, metav1.CreateOptions{}); err != nil {
256+
framework.Failf("unable to create test secret %s: %v", secret.Name, err)
257+
}
258+
259+
pod := &v1.Pod{
260+
ObjectMeta: metav1.ObjectMeta{
261+
Name: "pod-configmaps-" + string(uuid.NewUUID()),
262+
},
263+
Spec: v1.PodSpec{
264+
Containers: []v1.Container{
265+
{
266+
Name: "env-test",
267+
Image: imageutils.GetE2EImage(imageutils.BusyBox),
268+
Command: []string{"sh", "-c", "env"},
269+
EnvFrom: []v1.EnvFromSource{
270+
{
271+
SecretRef: &v1.SecretEnvSource{LocalObjectReference: v1.LocalObjectReference{Name: name}},
272+
},
273+
{
274+
// prefix start with a digit can be consumed as environment variables.
275+
Prefix: "1-",
276+
SecretRef: &v1.SecretEnvSource{LocalObjectReference: v1.LocalObjectReference{Name: name}},
277+
},
278+
},
279+
},
280+
},
281+
RestartPolicy: v1.RestartPolicyNever,
282+
},
283+
}
284+
285+
e2epodoutput.TestContainerOutput(ctx, f, "consume secrets", pod, 0, []string{
286+
"data-1=value-1", "data-2=value-2", "data-3=value-3",
287+
"1-data-1=value-1", "1-data-2=value-2", "1-data-3=value-3",
288+
})
289+
})
241290
})
242291

243292
func secretForTest(namespace, name string) *v1.Secret {

test/e2e/feature/feature.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ var (
253253
// TODO: document the feature (owning SIG, when to use this feature for a test)
254254
RecoverVolumeExpansionFailure = framework.WithFeature(framework.ValidFeatures.Add("RecoverVolumeExpansionFailure"))
255255

256+
// RelaxedEnvironmentVariableValidation used when we verify whether the pod can consume all printable ASCII characters as environment variable names,
257+
// and whether the pod can consume configmap/secret that key starts with a number.
258+
RelaxedEnvironmentVariableValidation = framework.WithFeature(framework.ValidFeatures.Add("RelaxedEnvironmentVariableValidation"))
259+
256260
// TODO: document the feature (owning SIG, when to use this feature for a test)
257261
Recreate = framework.WithFeature(framework.ValidFeatures.Add("Recreate"))
258262

0 commit comments

Comments
 (0)