Commit 364239a2 authored by k8s-merge-robot's avatar k8s-merge-robot Committed by GitHub

Merge pull request #27342 from Random-Liu/add-image-pulling-node-e2e

Automatic merge from submit-queue Add image pulling node e2e Fixes #27007. Based on #27309, will rebase after #27309 gets merged. This PR added all tests mentioned in #27007: * Pull an image from invalid registry; * Pull an invalid image from gcr; * Pull an image from gcr; * Pull an image from docker hub; * Pull an image needs auth with/without secrets. For the imagePullSecrets test, I created a new gcloud project "authenticated-image-pulling", and the service account in the code only has "Storage Object Viewer" permission. /cc @pwittrock @vishh [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/.github/PULL_REQUEST_TEMPLATE.md?pixel)]()
parents 5ba4b3f2 89502d3c
......@@ -17,58 +17,33 @@ limitations under the License.
package e2e_node
import (
"errors"
"fmt"
"k8s.io/kubernetes/pkg/api"
apierrs "k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/errors"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/util"
"github.com/onsi/gomega/format"
"github.com/onsi/gomega/types"
)
// One pod one container
type ConformanceContainer struct {
Container api.Container
Client *client.Client
RestartPolicy api.RestartPolicy
Volumes []api.Volume
NodeName string
Namespace string
Container api.Container
Client *client.Client
RestartPolicy api.RestartPolicy
Volumes []api.Volume
ImagePullSecrets []string
NodeName string
Namespace string
podName string
}
type ConformanceContainerEqualMatcher struct {
Expected interface{}
}
func CContainerEqual(expected interface{}) types.GomegaMatcher {
return &ConformanceContainerEqualMatcher{
Expected: expected,
}
}
func (matcher *ConformanceContainerEqualMatcher) Match(actual interface{}) (bool, error) {
if actual == nil && matcher.Expected == nil {
return false, fmt.Errorf("Refusing to compare <nil> to <nil>.\nBe explicit and use BeNil() instead. This is to avoid mistakes where both sides of an assertion are erroneously uninitialized.")
}
val := api.Semantic.DeepDerivative(matcher.Expected, actual)
return val, nil
}
func (matcher *ConformanceContainerEqualMatcher) FailureMessage(actual interface{}) (message string) {
return format.Message(actual, "to equal", matcher.Expected)
}
func (matcher *ConformanceContainerEqualMatcher) NegatedFailureMessage(actual interface{}) (message string) {
return format.Message(actual, "not to equal", matcher.Expected)
}
func (cc *ConformanceContainer) Create() error {
cc.podName = cc.Container.Name + string(util.NewUUID())
imagePullSecrets := []api.LocalObjectReference{}
for _, s := range cc.ImagePullSecrets {
imagePullSecrets = append(imagePullSecrets, api.LocalObjectReference{Name: s})
}
pod := &api.Pod{
ObjectMeta: api.ObjectMeta{
Name: cc.podName,
......@@ -80,7 +55,8 @@ func (cc *ConformanceContainer) Create() error {
Containers: []api.Container{
cc.Container,
},
Volumes: cc.Volumes,
Volumes: cc.Volumes,
ImagePullSecrets: imagePullSecrets,
},
}
......@@ -88,26 +64,8 @@ func (cc *ConformanceContainer) Create() error {
return err
}
//Same with 'delete'
func (cc *ConformanceContainer) Stop() error {
return cc.Client.Pods(cc.Namespace).Delete(cc.podName, &api.DeleteOptions{})
}
func (cc *ConformanceContainer) Delete() error {
return cc.Client.Pods(cc.Namespace).Delete(cc.podName, &api.DeleteOptions{})
}
func (cc *ConformanceContainer) Get() (ConformanceContainer, error) {
pod, err := cc.Client.Pods(cc.Namespace).Get(cc.podName)
if err != nil {
return ConformanceContainer{}, err
}
containers := pod.Spec.Containers
if containers == nil || len(containers) != 1 {
return ConformanceContainer{}, errors.New("Failed to get container")
}
return ConformanceContainer{containers[0], cc.Client, pod.Spec.RestartPolicy, pod.Spec.Volumes, pod.Spec.NodeName, cc.Namespace, cc.podName}, nil
return cc.Client.Pods(cc.Namespace).Delete(cc.podName, api.NewDeleteOptions(0))
}
func (cc *ConformanceContainer) IsReady() (bool, error) {
......@@ -143,7 +101,7 @@ func (cc *ConformanceContainer) Present() (bool, error) {
if err == nil {
return true, nil
}
if apierrs.IsNotFound(err) {
if errors.IsNotFound(err) {
return false, nil
}
return false, err
......
......@@ -38,8 +38,10 @@ const (
pauseImage
// Images just used for explicitly testing pulling of images
pullTestExecHealthz
pullTestAlpine
pullTestAlpineWithBash
pullTestAuthenticatedAlpine
pullTestExecHealthz
)
var ImageRegistry = map[int]string{
......@@ -51,9 +53,11 @@ var ImageRegistry = map[int]string{
}
// These are used by tests that explicitly test the ability to pull images
var NoPullImagRegistry = map[int]string{
pullTestAlpineWithBash: "gcr.io/google_containers/alpine-with-bash:1.0",
pullTestExecHealthz: "gcr.io/google_containers/exechealthz:1.0",
var NoPullImageRegistry = map[int]string{
pullTestExecHealthz: "gcr.io/google_containers/exechealthz:1.0",
pullTestAlpine: "alpine:3.1",
pullTestAlpineWithBash: "gcr.io/google_containers/alpine-with-bash:1.0",
pullTestAuthenticatedAlpine: "gcr.io/authenticated-image-pulling/alpine:3.1",
}
// Pre-fetch all images tests depend on so that we don't fail in an actual test
......
......@@ -21,23 +21,16 @@ import (
"time"
"k8s.io/kubernetes/pkg/api"
apierrs "k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/client/restclient"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/test/e2e/framework"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Kubelet Container Manager", func() {
var cl *client.Client
BeforeEach(func() {
// Setup the apiserver client
cl = client.NewOrDie(&restclient.Config{Host: *apiServerAddress})
})
var _ = framework.KubeDescribe("Kubelet Container Manager", func() {
f := NewDefaultFramework("kubelet-container-manager")
Describe("oom score adjusting", func() {
namespace := "oom-adj"
Context("when scheduling a busybox command that always fails in a pod", func() {
var podName string
......@@ -46,7 +39,7 @@ var _ = Describe("Kubelet Container Manager", func() {
pod := &api.Pod{
ObjectMeta: api.ObjectMeta{
Name: podName,
Namespace: namespace,
Namespace: f.Namespace.Name,
},
Spec: api.PodSpec{
// Force the Pod to schedule to the node without a scheduler running
......@@ -63,13 +56,13 @@ var _ = Describe("Kubelet Container Manager", func() {
},
}
_, err := cl.Pods(namespace).Create(pod)
_, err := f.Client.Pods(f.Namespace.Name).Create(pod)
Expect(err).To(BeNil(), fmt.Sprintf("Error creating Pod %v", err))
})
It("it should have an error terminated reason", func() {
It("should have an error terminated reason", func() {
Eventually(func() error {
podData, err := cl.Pods(namespace).Get(podName)
podData, err := f.Client.Pods(f.Namespace.Name).Get(podName)
if err != nil {
return err
}
......@@ -87,22 +80,10 @@ var _ = Describe("Kubelet Container Manager", func() {
}, time.Minute, time.Second*4).Should(BeNil())
})
It("it should be possible to delete", func() {
err := cl.Pods(namespace).Delete(podName, &api.DeleteOptions{})
It("should be possible to delete", func() {
err := f.Client.Pods(f.Namespace.Name).Delete(podName, &api.DeleteOptions{})
Expect(err).To(BeNil(), fmt.Sprintf("Error deleting Pod %v", err))
})
AfterEach(func() {
cl.Pods(namespace).Delete(podName, &api.DeleteOptions{})
Eventually(func() bool {
_, err := cl.Pods(namespace).Get(podName)
if err != nil && apierrs.IsNotFound(err) {
return true
}
return false
}, time.Minute, time.Second*4).Should(BeTrue())
})
})
})
......
......@@ -19,9 +19,6 @@ package e2e_node
import (
"time"
"k8s.io/kubernetes/pkg/client/restclient"
client "k8s.io/kubernetes/pkg/client/unversioned"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
......@@ -34,20 +31,13 @@ const (
)
var _ = Describe("Image Container Conformance Test", func() {
var cl *client.Client
BeforeEach(func() {
// Setup the apiserver client
cl = client.NewOrDie(&restclient.Config{Host: *apiServerAddress})
})
Describe("[FLAKY] image conformance blackbox test", func() {
Context("when testing images that exist", func() {
var conformImages []ConformanceImage
BeforeEach(func() {
existImageTags := []string{
NoPullImagRegistry[pullTestExecHealthz],
NoPullImagRegistry[pullTestAlpineWithBash],
NoPullImageRegistry[pullTestExecHealthz],
NoPullImageRegistry[pullTestAlpineWithBash],
}
for _, existImageTag := range existImageTags {
conformImage, _ := NewConformanceImage("docker", existImageTag)
......
......@@ -38,9 +38,8 @@ import (
)
var _ = framework.KubeDescribe("Kubelet", func() {
f := NewDefaultFramework("kubelet-test")
Context("when scheduling a busybox command in a pod", func() {
// Setup the framework
f := NewDefaultFramework("pod-scheduling")
podName := "busybox-scheduling-" + string(util.NewUUID())
It("it should print the output to logs", func() {
podClient := f.Client.Pods(f.Namespace.Name)
......@@ -81,7 +80,6 @@ var _ = framework.KubeDescribe("Kubelet", func() {
})
Context("when scheduling a read only busybox container", func() {
f := NewDefaultFramework("pod-scheduling")
podName := "busybox-readonly-fs" + string(util.NewUUID())
It("it should not write to root filesystem", func() {
podClient := f.Client.Pods(f.Namespace.Name)
......@@ -123,8 +121,6 @@ var _ = framework.KubeDescribe("Kubelet", func() {
})
})
Describe("metrics api", func() {
// Setup the framework
f := NewDefaultFramework("kubelet-metrics-api")
Context("when querying /stats/summary", func() {
It("it should report resource usage through the stats api", func() {
podNamePrefix := "stats-busybox-" + string(util.NewUUID())
......
......@@ -24,25 +24,21 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/client/restclient"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/test/e2e/framework"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("MirrorPod", func() {
var cl *client.Client
BeforeEach(func() {
// Setup the apiserver client
cl = client.NewOrDie(&restclient.Config{Host: *apiServerAddress})
})
ns := "mirror-pod"
var _ = framework.KubeDescribe("MirrorPod", func() {
f := NewDefaultFramework("mirror-pod")
Context("when create a mirror pod ", func() {
var staticPodName, mirrorPodName string
BeforeEach(func() {
ns := f.Namespace.Name
staticPodName = "static-pod-" + string(util.NewUUID())
mirrorPodName = staticPodName + "-" + e2es.nodeName
......@@ -52,12 +48,13 @@ var _ = Describe("MirrorPod", func() {
By("wait for the mirror pod to be running")
Eventually(func() error {
return checkMirrorPodRunning(cl, mirrorPodName, ns)
return checkMirrorPodRunning(f.Client, mirrorPodName, ns)
}, 2*time.Minute, time.Second*4).Should(BeNil())
})
It("should be updated when static pod updated", func() {
ns := f.Namespace.Name
By("get mirror pod uid")
pod, err := cl.Pods(ns).Get(mirrorPodName)
pod, err := f.Client.Pods(ns).Get(mirrorPodName)
Expect(err).ShouldNot(HaveOccurred())
uid := pod.UID
......@@ -68,53 +65,56 @@ var _ = Describe("MirrorPod", func() {
By("wait for the mirror pod to be updated")
Eventually(func() error {
return checkMirrorPodRecreatedAndRunnig(cl, mirrorPodName, ns, uid)
return checkMirrorPodRecreatedAndRunnig(f.Client, mirrorPodName, ns, uid)
}, 2*time.Minute, time.Second*4).Should(BeNil())
By("check the mirror pod container image is updated")
pod, err = cl.Pods(ns).Get(mirrorPodName)
pod, err = f.Client.Pods(ns).Get(mirrorPodName)
Expect(err).ShouldNot(HaveOccurred())
Expect(len(pod.Spec.Containers)).Should(Equal(1))
Expect(pod.Spec.Containers[0].Image).Should(Equal(image))
})
It("should be recreated when mirror pod gracefully deleted", func() {
ns := f.Namespace.Name
By("get mirror pod uid")
pod, err := cl.Pods(ns).Get(mirrorPodName)
pod, err := f.Client.Pods(ns).Get(mirrorPodName)
Expect(err).ShouldNot(HaveOccurred())
uid := pod.UID
By("delete the mirror pod with grace period 30s")
err = cl.Pods(ns).Delete(mirrorPodName, api.NewDeleteOptions(30))
err = f.Client.Pods(ns).Delete(mirrorPodName, api.NewDeleteOptions(30))
Expect(err).ShouldNot(HaveOccurred())
By("wait for the mirror pod to be recreated")
Eventually(func() error {
return checkMirrorPodRecreatedAndRunnig(cl, mirrorPodName, ns, uid)
return checkMirrorPodRecreatedAndRunnig(f.Client, mirrorPodName, ns, uid)
}, 2*time.Minute, time.Second*4).Should(BeNil())
})
It("should be recreated when mirror pod forcibly deleted", func() {
ns := f.Namespace.Name
By("get mirror pod uid")
pod, err := cl.Pods(ns).Get(mirrorPodName)
pod, err := f.Client.Pods(ns).Get(mirrorPodName)
Expect(err).ShouldNot(HaveOccurred())
uid := pod.UID
By("delete the mirror pod with grace period 0s")
err = cl.Pods(ns).Delete(mirrorPodName, api.NewDeleteOptions(0))
err = f.Client.Pods(ns).Delete(mirrorPodName, api.NewDeleteOptions(0))
Expect(err).ShouldNot(HaveOccurred())
By("wait for the mirror pod to be recreated")
Eventually(func() error {
return checkMirrorPodRecreatedAndRunnig(cl, mirrorPodName, ns, uid)
return checkMirrorPodRecreatedAndRunnig(f.Client, mirrorPodName, ns, uid)
}, 2*time.Minute, time.Second*4).Should(BeNil())
})
AfterEach(func() {
ns := f.Namespace.Name
By("delete the static pod")
err := deleteStaticPod(e2es.kubeletStaticPodDir, staticPodName, ns)
Expect(err).ShouldNot(HaveOccurred())
By("wait for the mirror pod to disappear")
Eventually(func() error {
return checkMirrorPodDisappear(cl, mirrorPodName, ns)
return checkMirrorPodDisappear(f.Client, mirrorPodName, ns)
}, 2*time.Minute, time.Second*4).Should(BeNil())
})
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment