Skip to content

Commit 78b5003

Browse files
committed
update e2e test
1 parent 3089411 commit 78b5003

File tree

4 files changed

+128
-213
lines changed

4 files changed

+128
-213
lines changed

test/conformance/testdata/conformance.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -431,14 +431,6 @@
431431
environment variables when backticks are supplied.
432432
release: v1.19
433433
file: test/e2e/common/expansion.go
434-
- testname: VolumeSubpathEnvExpansion, subpath lifecycle
435-
codename: '[k8s.io] Variable Expansion should not change the subpath mount on a
436-
container restart if the environment variable changes [sig-storage][Slow] [Conformance]'
437-
description: "Verify should not change the subpath mount on a container restart
438-
if the environment variable changes 1.\tvalid subpathexpr starts a container running
439-
2.\ttest for valid subpath writes 3.\tcontainer restarts 4.\tdelete cleanly"
440-
release: v1.19
441-
file: test/e2e/common/expansion.go
442434
- testname: VolumeSubpathEnvExpansion, subpath test writes
443435
codename: '[k8s.io] Variable Expansion should succeed in writing subpaths in container
444436
[sig-storage][Slow] [Conformance]'

test/e2e/common/expansion.go

Lines changed: 0 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,9 @@ limitations under the License.
1717
package common
1818

1919
import (
20-
"context"
21-
"fmt"
22-
"time"
23-
2420
v1 "k8s.io/api/core/v1"
2521
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2622
"k8s.io/apimachinery/pkg/util/uuid"
27-
"k8s.io/apimachinery/pkg/util/wait"
2823
"k8s.io/kubernetes/test/e2e/framework"
2924
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
3025
imageutils "k8s.io/kubernetes/test/utils/image"
@@ -362,110 +357,6 @@ var _ = framework.KubeDescribe("Variable Expansion", func() {
362357
err = e2epod.DeletePodWithWait(f.ClientSet, pod)
363358
framework.ExpectNoError(err, "failed to delete pod")
364359
})
365-
366-
/*
367-
Release : v1.19
368-
Testname: VolumeSubpathEnvExpansion, subpath lifecycle
369-
Description: Verify should not change the subpath mount on a container restart if the environment variable changes
370-
1. valid subpathexpr starts a container running
371-
2. test for valid subpath writes
372-
3. container restarts
373-
4. delete cleanly
374-
*/
375-
framework.ConformanceIt("should not change the subpath mount on a container restart if the environment variable changes [sig-storage][Slow]", func() {
376-
envVars := []v1.EnvVar{
377-
{
378-
Name: "POD_NAME",
379-
ValueFrom: &v1.EnvVarSource{
380-
FieldRef: &v1.ObjectFieldSelector{
381-
APIVersion: "v1",
382-
FieldPath: "metadata.annotations['mysubpath']",
383-
},
384-
},
385-
},
386-
}
387-
mounts := []v1.VolumeMount{
388-
{
389-
Name: "workdir1",
390-
MountPath: "/subpath_mount",
391-
},
392-
{
393-
Name: "workdir1",
394-
MountPath: "/volume_mount",
395-
},
396-
}
397-
subpathMounts := []v1.VolumeMount{
398-
{
399-
Name: "workdir1",
400-
MountPath: "/subpath_mount",
401-
SubPathExpr: "$(POD_NAME)",
402-
},
403-
{
404-
Name: "workdir1",
405-
MountPath: "/volume_mount",
406-
},
407-
}
408-
volumes := []v1.Volume{
409-
{
410-
Name: "workdir1",
411-
VolumeSource: v1.VolumeSource{
412-
EmptyDir: &v1.EmptyDirVolumeSource{},
413-
},
414-
},
415-
}
416-
pod := newPod([]string{"/bin/sh", "-ec", "sleep 100000"}, envVars, subpathMounts, volumes)
417-
pod.Spec.RestartPolicy = v1.RestartPolicyOnFailure
418-
pod.ObjectMeta.Annotations = map[string]string{"mysubpath": "foo"}
419-
sideContainerName := "side-container"
420-
pod.Spec.Containers = append(pod.Spec.Containers, newContainer(sideContainerName, []string{"/bin/sh", "-ec", "sleep 100000"}, envVars, subpathMounts))
421-
suffix := string(uuid.NewUUID())
422-
pod.Spec.InitContainers = []v1.Container{newContainer(
423-
fmt.Sprintf("init-volume-%s", suffix), []string{"sh", "-c", "mkdir -p /volume_mount/foo; touch /volume_mount/foo/test.log"}, nil, mounts)}
424-
425-
// Add liveness probe to subpath container
426-
pod.Spec.Containers[0].LivenessProbe = &v1.Probe{
427-
Handler: v1.Handler{
428-
Exec: &v1.ExecAction{
429-
430-
Command: []string{"cat", "/subpath_mount/test.log"},
431-
},
432-
},
433-
InitialDelaySeconds: 1,
434-
FailureThreshold: 1,
435-
PeriodSeconds: 2,
436-
}
437-
438-
// Start pod
439-
ginkgo.By(fmt.Sprintf("Creating pod %s", pod.Name))
440-
var podClient *framework.PodClient = f.PodClient()
441-
pod = podClient.Create(pod)
442-
defer func() {
443-
e2epod.DeletePodWithWait(f.ClientSet, pod)
444-
}()
445-
err := e2epod.WaitForPodRunningInNamespace(f.ClientSet, pod)
446-
framework.ExpectNoError(err, "while waiting for pod to be running")
447-
448-
ginkgo.By("updating the pod")
449-
podClient.Update(pod.ObjectMeta.Name, func(pod *v1.Pod) {
450-
pod.ObjectMeta.Annotations = map[string]string{"mysubpath": "newsubpath"}
451-
})
452-
453-
ginkgo.By("waiting for pod and container restart")
454-
waitForPodContainerRestart(f, pod, "/volume_mount/foo/test.log")
455-
456-
ginkgo.By("test for subpath mounted with old value")
457-
cmd := "test -f /volume_mount/foo/test.log"
458-
_, _, err = f.ExecShellInPodWithFullOutput(pod.Name, cmd)
459-
if err != nil {
460-
framework.Failf("expected to be able to verify old file exists")
461-
}
462-
463-
cmd = "test ! -f /volume_mount/newsubpath/test.log"
464-
_, _, err = f.ExecShellInPodWithFullOutput(pod.Name, cmd)
465-
if err != nil {
466-
framework.Failf("expected to be able to verify new file does not exist")
467-
}
468-
})
469360
})
470361

471362
func testPodFailSubpath(f *framework.Framework, pod *v1.Pod) {
@@ -480,72 +371,6 @@ func testPodFailSubpath(f *framework.Framework, pod *v1.Pod) {
480371
framework.ExpectError(err, "while waiting for pod to be running")
481372
}
482373

483-
// Tests that the existing subpath mount is detected when a container restarts
484-
func waitForPodContainerRestart(f *framework.Framework, pod *v1.Pod, volumeMount string) {
485-
486-
ginkgo.By("Failing liveness probe")
487-
stdout, stderr, err := f.ExecShellInPodWithFullOutput(pod.Name, fmt.Sprintf("rm %v", volumeMount))
488-
489-
framework.Logf("Pod exec output: %v / %v", stdout, stderr)
490-
framework.ExpectNoError(err, "while failing liveness probe")
491-
492-
// Check that container has restarted
493-
ginkgo.By("Waiting for container to restart")
494-
restarts := int32(0)
495-
err = wait.PollImmediate(10*time.Second, 2*time.Minute, func() (bool, error) {
496-
pod, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Get(context.TODO(), pod.Name, metav1.GetOptions{})
497-
if err != nil {
498-
return false, err
499-
}
500-
for _, status := range pod.Status.ContainerStatuses {
501-
if status.Name == pod.Spec.Containers[0].Name {
502-
framework.Logf("Container %v, restarts: %v", status.Name, status.RestartCount)
503-
restarts = status.RestartCount
504-
if restarts > 0 {
505-
framework.Logf("Container has restart count: %v", restarts)
506-
return true, nil
507-
}
508-
}
509-
}
510-
return false, nil
511-
})
512-
framework.ExpectNoError(err, "while waiting for container to restart")
513-
514-
// Fix liveness probe
515-
ginkgo.By("Rewriting the file")
516-
stdout = f.ExecShellInContainer(pod.Name, pod.Spec.Containers[1].Name, fmt.Sprintf("echo test-after > %v", volumeMount))
517-
framework.Logf("Pod exec output: %v", stdout)
518-
519-
// Wait for container restarts to stabilize
520-
ginkgo.By("Waiting for container to stop restarting")
521-
stableCount := int(0)
522-
stableThreshold := int(time.Minute / framework.Poll)
523-
err = wait.PollImmediate(framework.Poll, 2*time.Minute, func() (bool, error) {
524-
pod, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Get(context.TODO(), pod.Name, metav1.GetOptions{})
525-
if err != nil {
526-
return false, err
527-
}
528-
for _, status := range pod.Status.ContainerStatuses {
529-
if status.Name == pod.Spec.Containers[0].Name {
530-
if status.RestartCount == restarts {
531-
stableCount++
532-
if stableCount > stableThreshold {
533-
framework.Logf("Container restart has stabilized")
534-
return true, nil
535-
}
536-
} else {
537-
restarts = status.RestartCount
538-
stableCount = 0
539-
framework.Logf("Container has restart count: %v", restarts)
540-
}
541-
break
542-
}
543-
}
544-
return false, nil
545-
})
546-
framework.ExpectNoError(err, "while waiting for container to stabilize")
547-
}
548-
549374
func newPod(command []string, envVars []v1.EnvVar, mounts []v1.VolumeMount, volumes []v1.Volume) *v1.Pod {
550375
podName := "var-expansion-" + string(uuid.NewUUID())
551376
return &v1.Pod{

test/e2e/storage/subpath.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ package storage
1818

1919
import (
2020
"context"
21-
"k8s.io/api/core/v1"
21+
22+
"github.com/onsi/ginkgo"
23+
v1 "k8s.io/api/core/v1"
2224
apierrors "k8s.io/apimachinery/pkg/api/errors"
2325
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2426
"k8s.io/kubernetes/test/e2e/framework"
2527
"k8s.io/kubernetes/test/e2e/storage/testsuites"
2628
"k8s.io/kubernetes/test/e2e/storage/utils"
27-
28-
"github.com/onsi/ginkgo"
2929
)
3030

3131
var _ = utils.SIGDescribe("Subpath", func() {
@@ -48,7 +48,6 @@ var _ = utils.SIGDescribe("Subpath", func() {
4848
if err != nil && !apierrors.IsAlreadyExists(err) {
4949
framework.ExpectNoError(err, "while creating configmap")
5050
}
51-
5251
})
5352

5453
/*
@@ -125,5 +124,14 @@ var _ = utils.SIGDescribe("Subpath", func() {
125124
}, privilegedSecurityContext)
126125
testsuites.TestBasicSubpath(f, "configmap-value", pod)
127126
})
127+
128+
})
129+
130+
ginkgo.Context("Container restart", func() {
131+
ginkgo.It("should verify that container can restart successfully after configmaps modified", func() {
132+
configmapToModify := &v1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "my-configmap-to-modify"}, Data: map[string]string{"configmap-key": "configmap-value"}}
133+
configmapModified := &v1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "my-configmap-to-modify"}, Data: map[string]string{"configmap-key": "configmap-modified-value"}}
134+
testsuites.TestPodContainerRestartWithConfigmapModified(f, configmapToModify, configmapModified)
135+
})
128136
})
129137
})

0 commit comments

Comments
 (0)