mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Merge pull request #28517 from Random-Liu/better-image-pull-test
Automatic merge from submit-queue Node E2E: Use waiting reason to figure out image pulling error. Addresses https://github.com/kubernetes/kubernetes/pull/28323#issuecomment-230002158, using `Waiting` reason to check whether the image pulling failures as expected. @yujuhong []()
This commit is contained in:
commit
d6d846f4e5
@ -22,6 +22,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
|
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||||
"k8s.io/kubernetes/pkg/util"
|
"k8s.io/kubernetes/pkg/util"
|
||||||
"k8s.io/kubernetes/test/e2e/framework"
|
"k8s.io/kubernetes/test/e2e/framework"
|
||||||
|
|
||||||
@ -189,44 +190,44 @@ while true; do sleep 1; done
|
|||||||
image string
|
image string
|
||||||
secret bool
|
secret bool
|
||||||
phase api.PodPhase
|
phase api.PodPhase
|
||||||
state ContainerState
|
waiting bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
description: "should not be able to pull image from invalid registry",
|
description: "should not be able to pull image from invalid registry",
|
||||||
image: "invalid.com/invalid/alpine:3.1",
|
image: "invalid.com/invalid/alpine:3.1",
|
||||||
phase: api.PodPending,
|
phase: api.PodPending,
|
||||||
state: ContainerStateWaiting,
|
waiting: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "should not be able to pull non-existing image from gcr.io",
|
description: "should not be able to pull non-existing image from gcr.io",
|
||||||
image: "gcr.io/google_containers/invalid-image:invalid-tag",
|
image: "gcr.io/google_containers/invalid-image:invalid-tag",
|
||||||
phase: api.PodPending,
|
phase: api.PodPending,
|
||||||
state: ContainerStateWaiting,
|
waiting: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "should be able to pull image from gcr.io",
|
description: "should be able to pull image from gcr.io",
|
||||||
image: NoPullImageRegistry[pullTestAlpineWithBash],
|
image: NoPullImageRegistry[pullTestAlpineWithBash],
|
||||||
phase: api.PodRunning,
|
phase: api.PodRunning,
|
||||||
state: ContainerStateRunning,
|
waiting: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "should be able to pull image from docker hub",
|
description: "should be able to pull image from docker hub",
|
||||||
image: NoPullImageRegistry[pullTestAlpine],
|
image: NoPullImageRegistry[pullTestAlpine],
|
||||||
phase: api.PodRunning,
|
phase: api.PodRunning,
|
||||||
state: ContainerStateRunning,
|
waiting: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "should not be able to pull from private registry without secret",
|
description: "should not be able to pull from private registry without secret",
|
||||||
image: NoPullImageRegistry[pullTestAuthenticatedAlpine],
|
image: NoPullImageRegistry[pullTestAuthenticatedAlpine],
|
||||||
phase: api.PodPending,
|
phase: api.PodPending,
|
||||||
state: ContainerStateWaiting,
|
waiting: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "should be able to pull from private registry with secret",
|
description: "should be able to pull from private registry with secret",
|
||||||
image: NoPullImageRegistry[pullTestAuthenticatedAlpine],
|
image: NoPullImageRegistry[pullTestAuthenticatedAlpine],
|
||||||
secret: true,
|
secret: true,
|
||||||
phase: api.PodRunning,
|
phase: api.PodRunning,
|
||||||
state: ContainerStateRunning,
|
waiting: false,
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
testCase := testCase
|
testCase := testCase
|
||||||
@ -261,15 +262,24 @@ while true; do sleep 1; done
|
|||||||
// pod phase first, and the expected pod phase is Pending, the container status may not
|
// pod phase first, and the expected pod phase is Pending, the container status may not
|
||||||
// even show up when we check it.
|
// even show up when we check it.
|
||||||
By("check the container state")
|
By("check the container state")
|
||||||
getState := func() (ContainerState, error) {
|
checkContainerState := func() (bool, error) {
|
||||||
status, err := container.GetStatus()
|
status, err := container.GetStatus()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ContainerStateUnknown, err
|
return false, err
|
||||||
}
|
}
|
||||||
return GetContainerState(status.State), nil
|
if !testCase.waiting && status.State.Running != nil {
|
||||||
|
return true, nil
|
||||||
}
|
}
|
||||||
Eventually(getState, retryTimeout, pollInterval).Should(Equal(testCase.state))
|
if testCase.waiting && status.State.Waiting != nil {
|
||||||
Consistently(getState, consistentCheckTimeout, pollInterval).Should(Equal(testCase.state))
|
reason := status.State.Waiting.Reason
|
||||||
|
return reason == kubecontainer.ErrImagePull.Error() ||
|
||||||
|
reason == kubecontainer.ErrImagePullBackOff.Error(), nil
|
||||||
|
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
Eventually(checkContainerState, retryTimeout, pollInterval).Should(BeTrue())
|
||||||
|
Consistently(checkContainerState, consistentCheckTimeout, pollInterval).Should(BeTrue())
|
||||||
|
|
||||||
By("check the pod phase")
|
By("check the pod phase")
|
||||||
Expect(container.GetPhase()).To(Equal(testCase.phase))
|
Expect(container.GetPhase()).To(Equal(testCase.phase))
|
||||||
|
Loading…
Reference in New Issue
Block a user