mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 07:20:13 +00:00
Merge pull request #93963 from claudiubelu/tests/fixes-expansion-tests-negative-test
Fixes variable expansion false positive
This commit is contained in:
commit
ef1655f691
@ -181,11 +181,16 @@ var _ = framework.KubeDescribe("Variable Expansion", func() {
|
|||||||
Description: Make sure a container's subpath can not be set using an expansion of environment variables when absolute path is supplied.
|
Description: Make sure a container's subpath can not be set using an expansion of environment variables when absolute path is supplied.
|
||||||
*/
|
*/
|
||||||
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() {
|
||||||
|
absolutePath := "/tmp"
|
||||||
|
if framework.NodeOSDistroIs("windows") {
|
||||||
|
// Windows does not typically have a C:\tmp folder.
|
||||||
|
absolutePath = "C:\\Users"
|
||||||
|
}
|
||||||
|
|
||||||
envVars := []v1.EnvVar{
|
envVars := []v1.EnvVar{
|
||||||
{
|
{
|
||||||
Name: "POD_NAME",
|
Name: "POD_NAME",
|
||||||
Value: "/tmp",
|
Value: absolutePath,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
mounts := []v1.VolumeMount{
|
mounts := []v1.VolumeMount{
|
||||||
@ -367,8 +372,8 @@ func testPodFailSubpath(f *framework.Framework, pod *v1.Pod) {
|
|||||||
e2epod.DeletePodWithWait(f.ClientSet, pod)
|
e2epod.DeletePodWithWait(f.ClientSet, pod)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err := e2epod.WaitTimeoutForPodRunningInNamespace(f.ClientSet, pod.Name, pod.Namespace, framework.PodStartShortTimeout)
|
err := e2epod.WaitForPodContainerToFail(f.ClientSet, pod.Namespace, pod.Name, 0, "CreateContainerConfigError", framework.PodStartShortTimeout)
|
||||||
framework.ExpectError(err, "while waiting for pod to be running")
|
framework.ExpectNoError(err, "while waiting for the pod container to fail")
|
||||||
}
|
}
|
||||||
|
|
||||||
func newPod(command []string, envVars []v1.EnvVar, mounts []v1.VolumeMount, volumes []v1.Volume) *v1.Pod {
|
func newPod(command []string, envVars []v1.EnvVar, mounts []v1.VolumeMount, volumes []v1.Volume) *v1.Pod {
|
||||||
|
@ -298,6 +298,29 @@ func podsRunning(c clientset.Interface, pods *v1.PodList) []error {
|
|||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func podContainerFailed(c clientset.Interface, namespace, podName string, containerIndex int, reason string) wait.ConditionFunc {
|
||||||
|
return func() (bool, error) {
|
||||||
|
pod, err := c.CoreV1().Pods(namespace).Get(context.TODO(), podName, metav1.GetOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
switch pod.Status.Phase {
|
||||||
|
case v1.PodPending:
|
||||||
|
if len(pod.Status.ContainerStatuses) == 0 {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
containerStatus := pod.Status.ContainerStatuses[containerIndex]
|
||||||
|
if containerStatus.State.Waiting != nil && containerStatus.State.Waiting.Reason == reason {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
case v1.PodFailed, v1.PodRunning, v1.PodSucceeded:
|
||||||
|
return false, fmt.Errorf("pod was expected to be pending, but it is in the state: %s", pod.Status.Phase)
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// LogPodStates logs basic info of provided pods for debugging.
|
// LogPodStates logs basic info of provided pods for debugging.
|
||||||
func LogPodStates(pods []v1.Pod) {
|
func LogPodStates(pods []v1.Pod) {
|
||||||
// Find maximum widths for pod, node, and phase strings for column printing.
|
// Find maximum widths for pod, node, and phase strings for column printing.
|
||||||
|
@ -537,3 +537,10 @@ func WaitForNRestartablePods(ps *testutils.PodStore, expect int, timeout time.Du
|
|||||||
}
|
}
|
||||||
return podNames, nil
|
return podNames, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WaitForPodContainerToFail waits for the given Pod container to fail with the given reason, specifically due to
|
||||||
|
// invalid container configuration. In this case, the container will remain in a waiting state with a specific
|
||||||
|
// reason set, which should match the given reason.
|
||||||
|
func WaitForPodContainerToFail(c clientset.Interface, namespace, podName string, containerIndex int, reason string, timeout time.Duration) error {
|
||||||
|
return wait.PollImmediate(poll, timeout, podContainerFailed(c, namespace, podName, containerIndex, reason))
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user