mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Merge pull request #90135 from claudiubelu/tests/subpath-retry-exec
tests: Retries exec after container restart due to liveness
This commit is contained in:
commit
e01f553ddd
@ -44,37 +44,21 @@ var _ = framework.KubeDescribe("Variable Expansion", func() {
|
|||||||
Description: Create a Pod with environment variables. Environment variables defined using previously defined environment variables MUST expand to proper values.
|
Description: Create a Pod with environment variables. Environment variables defined using previously defined environment variables MUST expand to proper values.
|
||||||
*/
|
*/
|
||||||
framework.ConformanceIt("should allow composing env vars into new env vars [NodeConformance]", func() {
|
framework.ConformanceIt("should allow composing env vars into new env vars [NodeConformance]", func() {
|
||||||
podName := "var-expansion-" + string(uuid.NewUUID())
|
envVars := []v1.EnvVar{
|
||||||
pod := &v1.Pod{
|
{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
Name: "FOO",
|
||||||
Name: podName,
|
Value: "foo-value",
|
||||||
Labels: map[string]string{"name": podName},
|
|
||||||
},
|
},
|
||||||
Spec: v1.PodSpec{
|
{
|
||||||
Containers: []v1.Container{
|
Name: "BAR",
|
||||||
{
|
Value: "bar-value",
|
||||||
Name: "dapi-container",
|
},
|
||||||
Image: imageutils.GetE2EImage(imageutils.BusyBox),
|
{
|
||||||
Command: []string{"sh", "-c", "env"},
|
Name: "FOOBAR",
|
||||||
Env: []v1.EnvVar{
|
Value: "$(FOO);;$(BAR)",
|
||||||
{
|
|
||||||
Name: "FOO",
|
|
||||||
Value: "foo-value",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "BAR",
|
|
||||||
Value: "bar-value",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "FOOBAR",
|
|
||||||
Value: "$(FOO);;$(BAR)",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
RestartPolicy: v1.RestartPolicyNever,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
pod := newPod([]string{"sh", "-c", "env"}, envVars, nil, nil)
|
||||||
|
|
||||||
f.TestContainerOutput("env composition", pod, 0, []string{
|
f.TestContainerOutput("env composition", pod, 0, []string{
|
||||||
"FOO=foo-value",
|
"FOO=foo-value",
|
||||||
@ -89,29 +73,13 @@ var _ = framework.KubeDescribe("Variable Expansion", func() {
|
|||||||
Description: Create a Pod with environment variables and container command using them. Container command using the defined environment variables MUST expand to proper values.
|
Description: Create a Pod with environment variables and container command using them. Container command using the defined environment variables MUST expand to proper values.
|
||||||
*/
|
*/
|
||||||
framework.ConformanceIt("should allow substituting values in a container's command [NodeConformance]", func() {
|
framework.ConformanceIt("should allow substituting values in a container's command [NodeConformance]", func() {
|
||||||
podName := "var-expansion-" + string(uuid.NewUUID())
|
envVars := []v1.EnvVar{
|
||||||
pod := &v1.Pod{
|
{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
Name: "TEST_VAR",
|
||||||
Name: podName,
|
Value: "test-value",
|
||||||
Labels: map[string]string{"name": podName},
|
|
||||||
},
|
|
||||||
Spec: v1.PodSpec{
|
|
||||||
Containers: []v1.Container{
|
|
||||||
{
|
|
||||||
Name: "dapi-container",
|
|
||||||
Image: imageutils.GetE2EImage(imageutils.BusyBox),
|
|
||||||
Command: []string{"sh", "-c", "TEST_VAR=wrong echo \"$(TEST_VAR)\""},
|
|
||||||
Env: []v1.EnvVar{
|
|
||||||
{
|
|
||||||
Name: "TEST_VAR",
|
|
||||||
Value: "test-value",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
RestartPolicy: v1.RestartPolicyNever,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
pod := newPod([]string{"sh", "-c", "TEST_VAR=wrong echo \"$(TEST_VAR)\""}, envVars, nil, nil)
|
||||||
|
|
||||||
f.TestContainerOutput("substitution in container's command", pod, 0, []string{
|
f.TestContainerOutput("substitution in container's command", pod, 0, []string{
|
||||||
"test-value",
|
"test-value",
|
||||||
@ -124,30 +92,14 @@ var _ = framework.KubeDescribe("Variable Expansion", func() {
|
|||||||
Description: Create a Pod with environment variables and container command arguments using them. Container command arguments using the defined environment variables MUST expand to proper values.
|
Description: Create a Pod with environment variables and container command arguments using them. Container command arguments using the defined environment variables MUST expand to proper values.
|
||||||
*/
|
*/
|
||||||
framework.ConformanceIt("should allow substituting values in a container's args [NodeConformance]", func() {
|
framework.ConformanceIt("should allow substituting values in a container's args [NodeConformance]", func() {
|
||||||
podName := "var-expansion-" + string(uuid.NewUUID())
|
envVars := []v1.EnvVar{
|
||||||
pod := &v1.Pod{
|
{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
Name: "TEST_VAR",
|
||||||
Name: podName,
|
Value: "test-value",
|
||||||
Labels: map[string]string{"name": podName},
|
|
||||||
},
|
|
||||||
Spec: v1.PodSpec{
|
|
||||||
Containers: []v1.Container{
|
|
||||||
{
|
|
||||||
Name: "dapi-container",
|
|
||||||
Image: imageutils.GetE2EImage(imageutils.BusyBox),
|
|
||||||
Command: []string{"sh", "-c"},
|
|
||||||
Args: []string{"TEST_VAR=wrong echo \"$(TEST_VAR)\""},
|
|
||||||
Env: []v1.EnvVar{
|
|
||||||
{
|
|
||||||
Name: "TEST_VAR",
|
|
||||||
Value: "test-value",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
RestartPolicy: v1.RestartPolicyNever,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
pod := newPod([]string{"sh", "-c"}, envVars, nil, nil)
|
||||||
|
pod.Spec.Containers[0].Args = []string{"TEST_VAR=wrong echo \"$(TEST_VAR)\""}
|
||||||
|
|
||||||
f.TestContainerOutput("substitution in container's args", pod, 0, []string{
|
f.TestContainerOutput("substitution in container's args", pod, 0, []string{
|
||||||
"test-value",
|
"test-value",
|
||||||
@ -160,48 +112,34 @@ var _ = framework.KubeDescribe("Variable Expansion", func() {
|
|||||||
Description: Make sure a container's subpath can be set using an expansion of environment variables.
|
Description: Make sure a container's subpath can be set using an expansion of environment variables.
|
||||||
*/
|
*/
|
||||||
framework.ConformanceIt("should allow substituting values in a volume subpath [sig-storage]", func() {
|
framework.ConformanceIt("should allow substituting values in a volume subpath [sig-storage]", func() {
|
||||||
podName := "var-expansion-" + string(uuid.NewUUID())
|
envVars := []v1.EnvVar{
|
||||||
pod := &v1.Pod{
|
{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
Name: "POD_NAME",
|
||||||
Name: podName,
|
Value: "foo",
|
||||||
Labels: map[string]string{"name": podName},
|
|
||||||
},
|
},
|
||||||
Spec: v1.PodSpec{
|
}
|
||||||
Containers: []v1.Container{
|
mounts := []v1.VolumeMount{
|
||||||
{
|
{
|
||||||
Name: "dapi-container",
|
Name: "workdir1",
|
||||||
Image: imageutils.GetE2EImage(imageutils.BusyBox),
|
MountPath: "/logscontainer",
|
||||||
Command: []string{"sh", "-c", "test -d /testcontainer/" + podName + ";echo $?"},
|
SubPathExpr: "$(POD_NAME)",
|
||||||
Env: []v1.EnvVar{
|
},
|
||||||
{
|
{
|
||||||
Name: "POD_NAME",
|
Name: "workdir1",
|
||||||
Value: podName,
|
MountPath: "/testcontainer",
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
VolumeMounts: []v1.VolumeMount{
|
volumes := []v1.Volume{
|
||||||
{
|
{
|
||||||
Name: "workdir1",
|
Name: "workdir1",
|
||||||
MountPath: "/logscontainer",
|
VolumeSource: v1.VolumeSource{
|
||||||
SubPathExpr: "$(POD_NAME)",
|
EmptyDir: &v1.EmptyDirVolumeSource{},
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "workdir1",
|
|
||||||
MountPath: "/testcontainer",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
RestartPolicy: v1.RestartPolicyNever,
|
|
||||||
Volumes: []v1.Volume{
|
|
||||||
{
|
|
||||||
Name: "workdir1",
|
|
||||||
VolumeSource: v1.VolumeSource{
|
|
||||||
EmptyDir: &v1.EmptyDirVolumeSource{},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
pod := newPod([]string{}, envVars, mounts, volumes)
|
||||||
|
envVars[0].Value = pod.ObjectMeta.Name
|
||||||
|
pod.Spec.Containers[0].Command = []string{"sh", "-c", "test -d /testcontainer/" + pod.ObjectMeta.Name + ";echo $?"}
|
||||||
|
|
||||||
f.TestContainerOutput("substitution in volume subpath", pod, 0, []string{
|
f.TestContainerOutput("substitution in volume subpath", pod, 0, []string{
|
||||||
"0",
|
"0",
|
||||||
@ -215,43 +153,28 @@ var _ = framework.KubeDescribe("Variable Expansion", func() {
|
|||||||
*/
|
*/
|
||||||
framework.ConformanceIt("should fail substituting values in a volume subpath with backticks [sig-storage][Slow]", func() {
|
framework.ConformanceIt("should fail substituting values in a volume subpath with backticks [sig-storage][Slow]", func() {
|
||||||
|
|
||||||
podName := "var-expansion-" + string(uuid.NewUUID())
|
envVars := []v1.EnvVar{
|
||||||
pod := &v1.Pod{
|
{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
Name: "POD_NAME",
|
||||||
Name: podName,
|
Value: "..",
|
||||||
Labels: map[string]string{"name": podName},
|
|
||||||
},
|
},
|
||||||
Spec: v1.PodSpec{
|
}
|
||||||
Containers: []v1.Container{
|
mounts := []v1.VolumeMount{
|
||||||
{
|
{
|
||||||
Name: "dapi-container",
|
Name: "workdir1",
|
||||||
Image: imageutils.GetE2EImage(imageutils.BusyBox),
|
MountPath: "/logscontainer",
|
||||||
Env: []v1.EnvVar{
|
SubPathExpr: "$(POD_NAME)",
|
||||||
{
|
},
|
||||||
Name: "POD_NAME",
|
}
|
||||||
Value: "..",
|
volumes := []v1.Volume{
|
||||||
},
|
{
|
||||||
},
|
Name: "workdir1",
|
||||||
VolumeMounts: []v1.VolumeMount{
|
VolumeSource: v1.VolumeSource{
|
||||||
{
|
EmptyDir: &v1.EmptyDirVolumeSource{},
|
||||||
Name: "workdir1",
|
|
||||||
MountPath: "/logscontainer",
|
|
||||||
SubPathExpr: "$(POD_NAME)",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
RestartPolicy: v1.RestartPolicyNever,
|
|
||||||
Volumes: []v1.Volume{
|
|
||||||
{
|
|
||||||
Name: "workdir1",
|
|
||||||
VolumeSource: v1.VolumeSource{
|
|
||||||
EmptyDir: &v1.EmptyDirVolumeSource{},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
pod := newPod(nil, envVars, mounts, volumes)
|
||||||
|
|
||||||
// Pod should fail
|
// Pod should fail
|
||||||
testPodFailSubpath(f, pod)
|
testPodFailSubpath(f, pod)
|
||||||
@ -264,43 +187,28 @@ var _ = framework.KubeDescribe("Variable Expansion", func() {
|
|||||||
*/
|
*/
|
||||||
framework.ConformanceIt("should fail substituting values in a volume subpath with absolute path [sig-storage][Slow]", func() {
|
framework.ConformanceIt("should fail substituting values in a volume subpath with absolute path [sig-storage][Slow]", func() {
|
||||||
|
|
||||||
podName := "var-expansion-" + string(uuid.NewUUID())
|
envVars := []v1.EnvVar{
|
||||||
pod := &v1.Pod{
|
{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
Name: "POD_NAME",
|
||||||
Name: podName,
|
Value: "/tmp",
|
||||||
Labels: map[string]string{"name": podName},
|
|
||||||
},
|
},
|
||||||
Spec: v1.PodSpec{
|
}
|
||||||
Containers: []v1.Container{
|
mounts := []v1.VolumeMount{
|
||||||
{
|
{
|
||||||
Name: "dapi-container",
|
Name: "workdir1",
|
||||||
Image: imageutils.GetE2EImage(imageutils.BusyBox),
|
MountPath: "/logscontainer",
|
||||||
Env: []v1.EnvVar{
|
SubPathExpr: "$(POD_NAME)",
|
||||||
{
|
},
|
||||||
Name: "POD_NAME",
|
}
|
||||||
Value: "/tmp",
|
volumes := []v1.Volume{
|
||||||
},
|
{
|
||||||
},
|
Name: "workdir1",
|
||||||
VolumeMounts: []v1.VolumeMount{
|
VolumeSource: v1.VolumeSource{
|
||||||
{
|
EmptyDir: &v1.EmptyDirVolumeSource{},
|
||||||
Name: "workdir1",
|
|
||||||
MountPath: "/logscontainer",
|
|
||||||
SubPathExpr: "$(POD_NAME)",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
RestartPolicy: v1.RestartPolicyNever,
|
|
||||||
Volumes: []v1.Volume{
|
|
||||||
{
|
|
||||||
Name: "workdir1",
|
|
||||||
VolumeSource: v1.VolumeSource{
|
|
||||||
EmptyDir: &v1.EmptyDirVolumeSource{},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
pod := newPod(nil, envVars, mounts, volumes)
|
||||||
|
|
||||||
// Pod should fail
|
// Pod should fail
|
||||||
testPodFailSubpath(f, pod)
|
testPodFailSubpath(f, pod)
|
||||||
@ -313,58 +221,42 @@ var _ = framework.KubeDescribe("Variable Expansion", func() {
|
|||||||
*/
|
*/
|
||||||
framework.ConformanceIt("should verify that a failing subpath expansion can be modified during the lifecycle of a container [sig-storage][Slow]", func() {
|
framework.ConformanceIt("should verify that a failing subpath expansion can be modified during the lifecycle of a container [sig-storage][Slow]", func() {
|
||||||
|
|
||||||
podName := "var-expansion-" + string(uuid.NewUUID())
|
envVars := []v1.EnvVar{
|
||||||
containerName := "dapi-container"
|
{
|
||||||
pod := &v1.Pod{
|
Name: "POD_NAME",
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
Value: "foo",
|
||||||
Name: podName,
|
|
||||||
Labels: map[string]string{"name": podName},
|
|
||||||
Annotations: map[string]string{"notmysubpath": "mypath"},
|
|
||||||
},
|
},
|
||||||
Spec: v1.PodSpec{
|
{
|
||||||
Containers: []v1.Container{
|
Name: "ANNOTATION",
|
||||||
{
|
ValueFrom: &v1.EnvVarSource{
|
||||||
Name: containerName,
|
FieldRef: &v1.ObjectFieldSelector{
|
||||||
Image: imageutils.GetE2EImage(imageutils.BusyBox),
|
APIVersion: "v1",
|
||||||
Command: []string{"sh", "-c", "tail -f /dev/null"},
|
FieldPath: "metadata.annotations['mysubpath']",
|
||||||
Env: []v1.EnvVar{
|
|
||||||
{
|
|
||||||
Name: "POD_NAME",
|
|
||||||
Value: "foo",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "ANNOTATION",
|
|
||||||
ValueFrom: &v1.EnvVarSource{
|
|
||||||
FieldRef: &v1.ObjectFieldSelector{
|
|
||||||
APIVersion: "v1",
|
|
||||||
FieldPath: "metadata.annotations['mysubpath']",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
VolumeMounts: []v1.VolumeMount{
|
|
||||||
{
|
|
||||||
Name: "workdir1",
|
|
||||||
MountPath: "/subpath_mount",
|
|
||||||
SubPathExpr: "$(ANNOTATION)/$(POD_NAME)",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "workdir1",
|
|
||||||
MountPath: "/volume_mount",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Volumes: []v1.Volume{
|
|
||||||
{
|
|
||||||
Name: "workdir1",
|
|
||||||
VolumeSource: v1.VolumeSource{
|
|
||||||
EmptyDir: &v1.EmptyDirVolumeSource{},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
mounts := []v1.VolumeMount{
|
||||||
|
{
|
||||||
|
Name: "workdir1",
|
||||||
|
MountPath: "/subpath_mount",
|
||||||
|
SubPathExpr: "$(ANNOTATION)/$(POD_NAME)",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "workdir1",
|
||||||
|
MountPath: "/volume_mount",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
volumes := []v1.Volume{
|
||||||
|
{
|
||||||
|
Name: "workdir1",
|
||||||
|
VolumeSource: v1.VolumeSource{
|
||||||
|
EmptyDir: &v1.EmptyDirVolumeSource{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
pod := newPod([]string{"sh", "-c", "tail -f /dev/null"}, envVars, mounts, volumes)
|
||||||
|
pod.ObjectMeta.Annotations = map[string]string{"notmysubpath": "mypath"}
|
||||||
|
|
||||||
ginkgo.By("creating the pod with failed condition")
|
ginkgo.By("creating the pod with failed condition")
|
||||||
var podClient *framework.PodClient = f.PodClient()
|
var podClient *framework.PodClient = f.PodClient()
|
||||||
@ -374,7 +266,7 @@ var _ = framework.KubeDescribe("Variable Expansion", func() {
|
|||||||
framework.ExpectError(err, "while waiting for pod to be running")
|
framework.ExpectError(err, "while waiting for pod to be running")
|
||||||
|
|
||||||
ginkgo.By("updating the pod")
|
ginkgo.By("updating the pod")
|
||||||
podClient.Update(podName, func(pod *v1.Pod) {
|
podClient.Update(pod.ObjectMeta.Name, func(pod *v1.Pod) {
|
||||||
pod.ObjectMeta.Annotations = map[string]string{"mysubpath": "mypath"}
|
pod.ObjectMeta.Annotations = map[string]string{"mysubpath": "mypath"}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -398,59 +290,42 @@ var _ = framework.KubeDescribe("Variable Expansion", func() {
|
|||||||
*/
|
*/
|
||||||
framework.ConformanceIt("should succeed in writing subpaths in container [sig-storage][Slow]", func() {
|
framework.ConformanceIt("should succeed in writing subpaths in container [sig-storage][Slow]", func() {
|
||||||
|
|
||||||
podName := "var-expansion-" + string(uuid.NewUUID())
|
envVars := []v1.EnvVar{
|
||||||
containerName := "dapi-container"
|
{
|
||||||
pod := &v1.Pod{
|
Name: "POD_NAME",
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
Value: "foo",
|
||||||
Name: podName,
|
|
||||||
Labels: map[string]string{"name": podName},
|
|
||||||
Annotations: map[string]string{"mysubpath": "mypath"},
|
|
||||||
},
|
},
|
||||||
Spec: v1.PodSpec{
|
{
|
||||||
Containers: []v1.Container{
|
Name: "ANNOTATION",
|
||||||
{
|
ValueFrom: &v1.EnvVarSource{
|
||||||
Name: containerName,
|
FieldRef: &v1.ObjectFieldSelector{
|
||||||
Image: imageutils.GetE2EImage(imageutils.BusyBox),
|
APIVersion: "v1",
|
||||||
Command: []string{"sh", "-c", "tail -f /dev/null"},
|
FieldPath: "metadata.annotations['mysubpath']",
|
||||||
Env: []v1.EnvVar{
|
|
||||||
{
|
|
||||||
Name: "POD_NAME",
|
|
||||||
Value: "foo",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "ANNOTATION",
|
|
||||||
ValueFrom: &v1.EnvVarSource{
|
|
||||||
FieldRef: &v1.ObjectFieldSelector{
|
|
||||||
APIVersion: "v1",
|
|
||||||
FieldPath: "metadata.annotations['mysubpath']",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
VolumeMounts: []v1.VolumeMount{
|
|
||||||
{
|
|
||||||
Name: "workdir1",
|
|
||||||
MountPath: "/subpath_mount",
|
|
||||||
SubPathExpr: "$(ANNOTATION)/$(POD_NAME)",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "workdir1",
|
|
||||||
MountPath: "/volume_mount",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
RestartPolicy: v1.RestartPolicyNever,
|
|
||||||
Volumes: []v1.Volume{
|
|
||||||
{
|
|
||||||
Name: "workdir1",
|
|
||||||
VolumeSource: v1.VolumeSource{
|
|
||||||
EmptyDir: &v1.EmptyDirVolumeSource{},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
mounts := []v1.VolumeMount{
|
||||||
|
{
|
||||||
|
Name: "workdir1",
|
||||||
|
MountPath: "/subpath_mount",
|
||||||
|
SubPathExpr: "$(ANNOTATION)/$(POD_NAME)",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "workdir1",
|
||||||
|
MountPath: "/volume_mount",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
volumes := []v1.Volume{
|
||||||
|
{
|
||||||
|
Name: "workdir1",
|
||||||
|
VolumeSource: v1.VolumeSource{
|
||||||
|
EmptyDir: &v1.EmptyDirVolumeSource{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
pod := newPod([]string{"sh", "-c", "tail -f /dev/null"}, envVars, mounts, volumes)
|
||||||
|
pod.ObjectMeta.Annotations = map[string]string{"mysubpath": "mypath"}
|
||||||
|
|
||||||
ginkgo.By("creating the pod")
|
ginkgo.By("creating the pod")
|
||||||
var podClient *framework.PodClient = f.PodClient()
|
var podClient *framework.PodClient = f.PodClient()
|
||||||
@ -475,7 +350,7 @@ var _ = framework.KubeDescribe("Variable Expansion", func() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ginkgo.By("updating the annotation value")
|
ginkgo.By("updating the annotation value")
|
||||||
podClient.Update(podName, func(pod *v1.Pod) {
|
podClient.Update(pod.ObjectMeta.Name, func(pod *v1.Pod) {
|
||||||
pod.ObjectMeta.Annotations["mysubpath"] = "mynewpath"
|
pod.ObjectMeta.Annotations["mysubpath"] = "mynewpath"
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -499,75 +374,54 @@ var _ = framework.KubeDescribe("Variable Expansion", func() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
framework.ConformanceIt("should not change the subpath mount on a container restart if the environment variable changes [sig-storage][Slow]", func() {
|
framework.ConformanceIt("should not change the subpath mount on a container restart if the environment variable changes [sig-storage][Slow]", func() {
|
||||||
|
envVars := []v1.EnvVar{
|
||||||
suffix := string(uuid.NewUUID())
|
{
|
||||||
podName := fmt.Sprintf("var-expansion-%s", suffix)
|
Name: "POD_NAME",
|
||||||
containerName := "dapi-container"
|
ValueFrom: &v1.EnvVarSource{
|
||||||
pod := &v1.Pod{
|
FieldRef: &v1.ObjectFieldSelector{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
APIVersion: "v1",
|
||||||
Name: podName,
|
FieldPath: "metadata.annotations['mysubpath']",
|
||||||
Labels: map[string]string{"name": podName},
|
|
||||||
Annotations: map[string]string{"mysubpath": "foo"},
|
|
||||||
},
|
|
||||||
Spec: v1.PodSpec{
|
|
||||||
InitContainers: []v1.Container{
|
|
||||||
{
|
|
||||||
Name: fmt.Sprintf("init-volume-%s", suffix),
|
|
||||||
Image: imageutils.GetE2EImage(imageutils.BusyBox),
|
|
||||||
Command: []string{"sh", "-c", "mkdir -p /volume_mount/foo; touch /volume_mount/foo/test.log"},
|
|
||||||
VolumeMounts: []v1.VolumeMount{
|
|
||||||
{
|
|
||||||
Name: "workdir1",
|
|
||||||
MountPath: "/subpath_mount",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "workdir1",
|
|
||||||
MountPath: "/volume_mount",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
Containers: []v1.Container{
|
|
||||||
{
|
|
||||||
Name: containerName,
|
|
||||||
Image: imageutils.GetE2EImage(imageutils.BusyBox),
|
|
||||||
Command: []string{"/bin/sh", "-ec", "sleep 100000"},
|
|
||||||
Env: []v1.EnvVar{
|
|
||||||
{
|
|
||||||
Name: "POD_NAME",
|
|
||||||
ValueFrom: &v1.EnvVarSource{
|
|
||||||
FieldRef: &v1.ObjectFieldSelector{
|
|
||||||
APIVersion: "v1",
|
|
||||||
FieldPath: "metadata.annotations['mysubpath']",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
VolumeMounts: []v1.VolumeMount{
|
|
||||||
{
|
|
||||||
Name: "workdir1",
|
|
||||||
MountPath: "/subpath_mount",
|
|
||||||
SubPathExpr: "$(POD_NAME)",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "workdir1",
|
|
||||||
MountPath: "/volume_mount",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
RestartPolicy: v1.RestartPolicyOnFailure,
|
|
||||||
Volumes: []v1.Volume{
|
|
||||||
{
|
|
||||||
Name: "workdir1",
|
|
||||||
VolumeSource: v1.VolumeSource{
|
|
||||||
EmptyDir: &v1.EmptyDirVolumeSource{},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
mounts := []v1.VolumeMount{
|
||||||
|
{
|
||||||
|
Name: "workdir1",
|
||||||
|
MountPath: "/subpath_mount",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "workdir1",
|
||||||
|
MountPath: "/volume_mount",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
subpathMounts := []v1.VolumeMount{
|
||||||
|
{
|
||||||
|
Name: "workdir1",
|
||||||
|
MountPath: "/subpath_mount",
|
||||||
|
SubPathExpr: "$(POD_NAME)",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "workdir1",
|
||||||
|
MountPath: "/volume_mount",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
volumes := []v1.Volume{
|
||||||
|
{
|
||||||
|
Name: "workdir1",
|
||||||
|
VolumeSource: v1.VolumeSource{
|
||||||
|
EmptyDir: &v1.EmptyDirVolumeSource{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
pod := newPod([]string{"/bin/sh", "-ec", "sleep 100000"}, envVars, subpathMounts, volumes)
|
||||||
|
pod.Spec.RestartPolicy = v1.RestartPolicyOnFailure
|
||||||
|
pod.ObjectMeta.Annotations = map[string]string{"mysubpath": "foo"}
|
||||||
|
sideContainerName := "side-container"
|
||||||
|
pod.Spec.Containers = append(pod.Spec.Containers, newContainer(sideContainerName, []string{"/bin/sh", "-ec", "sleep 100000"}, envVars, subpathMounts))
|
||||||
|
suffix := string(uuid.NewUUID())
|
||||||
|
pod.Spec.InitContainers = []v1.Container{newContainer(
|
||||||
|
fmt.Sprintf("init-volume-%s", suffix), []string{"sh", "-c", "mkdir -p /volume_mount/foo; touch /volume_mount/foo/test.log"}, nil, mounts)}
|
||||||
|
|
||||||
// Add liveness probe to subpath container
|
// Add liveness probe to subpath container
|
||||||
pod.Spec.Containers[0].LivenessProbe = &v1.Probe{
|
pod.Spec.Containers[0].LivenessProbe = &v1.Probe{
|
||||||
@ -593,7 +447,7 @@ var _ = framework.KubeDescribe("Variable Expansion", func() {
|
|||||||
framework.ExpectNoError(err, "while waiting for pod to be running")
|
framework.ExpectNoError(err, "while waiting for pod to be running")
|
||||||
|
|
||||||
ginkgo.By("updating the pod")
|
ginkgo.By("updating the pod")
|
||||||
podClient.Update(podName, func(pod *v1.Pod) {
|
podClient.Update(pod.ObjectMeta.Name, func(pod *v1.Pod) {
|
||||||
pod.ObjectMeta.Annotations = map[string]string{"mysubpath": "newsubpath"}
|
pod.ObjectMeta.Annotations = map[string]string{"mysubpath": "newsubpath"}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -660,9 +514,8 @@ func waitForPodContainerRestart(f *framework.Framework, pod *v1.Pod, volumeMount
|
|||||||
|
|
||||||
// Fix liveness probe
|
// Fix liveness probe
|
||||||
ginkgo.By("Rewriting the file")
|
ginkgo.By("Rewriting the file")
|
||||||
stdout, _, err = f.ExecShellInPodWithFullOutput(pod.Name, fmt.Sprintf("echo test-after > %v", volumeMount))
|
stdout = f.ExecShellInContainer(pod.Name, pod.Spec.Containers[1].Name, fmt.Sprintf("echo test-after > %v", volumeMount))
|
||||||
framework.Logf("Pod exec output: %v", stdout)
|
framework.Logf("Pod exec output: %v", stdout)
|
||||||
framework.ExpectNoError(err, "while rewriting the probe file")
|
|
||||||
|
|
||||||
// Wait for container restarts to stabilize
|
// Wait for container restarts to stabilize
|
||||||
ginkgo.By("Waiting for container to stop restarting")
|
ginkgo.By("Waiting for container to stop restarting")
|
||||||
@ -693,3 +546,28 @@ func waitForPodContainerRestart(f *framework.Framework, pod *v1.Pod, volumeMount
|
|||||||
})
|
})
|
||||||
framework.ExpectNoError(err, "while waiting for container to stabilize")
|
framework.ExpectNoError(err, "while waiting for container to stabilize")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newPod(command []string, envVars []v1.EnvVar, mounts []v1.VolumeMount, volumes []v1.Volume) *v1.Pod {
|
||||||
|
podName := "var-expansion-" + string(uuid.NewUUID())
|
||||||
|
return &v1.Pod{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: podName,
|
||||||
|
Labels: map[string]string{"name": podName},
|
||||||
|
},
|
||||||
|
Spec: v1.PodSpec{
|
||||||
|
Containers: []v1.Container{newContainer("dapi-container", command, envVars, mounts)},
|
||||||
|
RestartPolicy: v1.RestartPolicyNever,
|
||||||
|
Volumes: volumes,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newContainer(containerName string, command []string, envVars []v1.EnvVar, mounts []v1.VolumeMount) v1.Container {
|
||||||
|
return v1.Container{
|
||||||
|
Name: containerName,
|
||||||
|
Image: imageutils.GetE2EImage(imageutils.BusyBox),
|
||||||
|
Command: command,
|
||||||
|
Env: envVars,
|
||||||
|
VolumeMounts: mounts,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user