1
16
17 package storage
18
19 import (
20 "context"
21
22 "github.com/onsi/ginkgo/v2"
23 v1 "k8s.io/api/core/v1"
24 apierrors "k8s.io/apimachinery/pkg/api/errors"
25 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26 "k8s.io/kubernetes/test/e2e/framework"
27 "k8s.io/kubernetes/test/e2e/storage/testsuites"
28 "k8s.io/kubernetes/test/e2e/storage/utils"
29 admissionapi "k8s.io/pod-security-admission/api"
30 )
31
32 var _ = utils.SIGDescribe("Subpath", func() {
33 f := framework.NewDefaultFramework("subpath")
34 f.NamespacePodSecurityLevel = admissionapi.LevelBaseline
35
36 ginkgo.Context("Atomic writer volumes", func() {
37 var err error
38
39 ginkgo.BeforeEach(func(ctx context.Context) {
40 ginkgo.By("Setting up data")
41 secret := &v1.Secret{ObjectMeta: metav1.ObjectMeta{Name: "my-secret"}, Data: map[string][]byte{"secret-key": []byte("secret-value")}}
42 _, err = f.ClientSet.CoreV1().Secrets(f.Namespace.Name).Create(ctx, secret, metav1.CreateOptions{})
43 if err != nil && !apierrors.IsAlreadyExists(err) {
44 framework.ExpectNoError(err, "while creating secret")
45 }
46
47 configmap := &v1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "my-configmap"}, Data: map[string]string{"configmap-key": "configmap-value"}}
48 _, err = f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Create(ctx, configmap, metav1.CreateOptions{})
49 if err != nil && !apierrors.IsAlreadyExists(err) {
50 framework.ExpectNoError(err, "while creating configmap")
51 }
52 })
53
54
59 framework.ConformanceIt("should support subpaths with secret pod", func(ctx context.Context) {
60 pod := testsuites.SubpathTestPod(f, "secret-key", "secret", &v1.VolumeSource{Secret: &v1.SecretVolumeSource{SecretName: "my-secret"}}, f.NamespacePodSecurityLevel)
61 testsuites.TestBasicSubpath(ctx, f, "secret-value", pod)
62 })
63
64
69 framework.ConformanceIt("should support subpaths with configmap pod", func(ctx context.Context) {
70 pod := testsuites.SubpathTestPod(f, "configmap-key", "configmap", &v1.VolumeSource{ConfigMap: &v1.ConfigMapVolumeSource{LocalObjectReference: v1.LocalObjectReference{Name: "my-configmap"}}}, f.NamespacePodSecurityLevel)
71 testsuites.TestBasicSubpath(ctx, f, "configmap-value", pod)
72 })
73
74
79 framework.ConformanceIt("should support subpaths with configmap pod with mountPath of existing file", func(ctx context.Context) {
80 pod := testsuites.SubpathTestPod(f, "configmap-key", "configmap", &v1.VolumeSource{ConfigMap: &v1.ConfigMapVolumeSource{LocalObjectReference: v1.LocalObjectReference{Name: "my-configmap"}}}, f.NamespacePodSecurityLevel)
81 file := "/etc/resolv.conf"
82 pod.Spec.Containers[0].VolumeMounts[0].MountPath = file
83 testsuites.TestBasicSubpathFile(ctx, f, "configmap-value", pod, file)
84 })
85
86
91 framework.ConformanceIt("should support subpaths with downward pod", func(ctx context.Context) {
92 pod := testsuites.SubpathTestPod(f, "downward/podname", "downwardAPI", &v1.VolumeSource{
93 DownwardAPI: &v1.DownwardAPIVolumeSource{
94 Items: []v1.DownwardAPIVolumeFile{{Path: "downward/podname", FieldRef: &v1.ObjectFieldSelector{APIVersion: "v1", FieldPath: "metadata.name"}}},
95 },
96 }, f.NamespacePodSecurityLevel)
97 testsuites.TestBasicSubpath(ctx, f, pod.Name, pod)
98 })
99
100
105 framework.ConformanceIt("should support subpaths with projected pod", func(ctx context.Context) {
106 pod := testsuites.SubpathTestPod(f, "projected/configmap-key", "projected", &v1.VolumeSource{
107 Projected: &v1.ProjectedVolumeSource{
108 Sources: []v1.VolumeProjection{
109 {ConfigMap: &v1.ConfigMapProjection{
110 LocalObjectReference: v1.LocalObjectReference{Name: "my-configmap"},
111 Items: []v1.KeyToPath{{Path: "projected/configmap-key", Key: "configmap-key"}},
112 }},
113 },
114 },
115 }, f.NamespacePodSecurityLevel)
116 testsuites.TestBasicSubpath(ctx, f, "configmap-value", pod)
117 })
118
119 })
120
121 ginkgo.Context("Container restart", func() {
122 ginkgo.It("should verify that container can restart successfully after configmaps modified", func(ctx context.Context) {
123 configmapToModify := &v1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "my-configmap-to-modify"}, Data: map[string]string{"configmap-key": "configmap-value"}}
124 configmapModified := &v1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "my-configmap-to-modify"}, Data: map[string]string{"configmap-key": "configmap-modified-value"}}
125 testsuites.TestPodContainerRestartWithConfigmapModified(ctx, f, configmapToModify, configmapModified)
126 })
127 })
128 })
129
View as plain text