Refactor common pod patterns to e2e framework.

This commit is contained in:
Tim St. Clair
2016-06-28 17:20:08 -07:00
parent a0c4912648
commit 376b5f247a
12 changed files with 166 additions and 119 deletions

View File

@@ -42,14 +42,11 @@ var _ = framework.KubeDescribe("Kubelet", func() {
Context("when scheduling a busybox command in a pod", func() {
podName := "busybox-scheduling-" + string(util.NewUUID())
It("it should print the output to logs", func() {
podClient := f.Client.Pods(f.Namespace.Name)
pod := &api.Pod{
f.CreatePod(&api.Pod{
ObjectMeta: api.ObjectMeta{
Name: podName,
},
Spec: api.PodSpec{
// Force the Pod to schedule to the node without a scheduler running
NodeName: *nodeName,
// Don't restart the Pod since it is expected to exit
RestartPolicy: api.RestartPolicyNever,
Containers: []api.Container{
@@ -60,14 +57,10 @@ var _ = framework.KubeDescribe("Kubelet", func() {
},
},
},
}
defer podClient.Delete(pod.Name, nil)
_, err := podClient.Create(pod)
Expect(err).To(BeNil(), fmt.Sprintf("Error creating Pod %v", err))
framework.ExpectNoError(f.WaitForPodRunning(pod.Name))
})
Eventually(func() string {
sinceTime := apiUnversioned.NewTime(time.Now().Add(time.Duration(-1 * time.Hour)))
rc, err := podClient.GetLogs(podName, &api.PodLogOptions{SinceTime: &sinceTime}).Stream()
rc, err := f.PodClient().GetLogs(podName, &api.PodLogOptions{SinceTime: &sinceTime}).Stream()
if err != nil {
return ""
}
@@ -82,15 +75,12 @@ var _ = framework.KubeDescribe("Kubelet", func() {
Context("when scheduling a read only busybox container", func() {
podName := "busybox-readonly-fs" + string(util.NewUUID())
It("it should not write to root filesystem", func() {
podClient := f.Client.Pods(f.Namespace.Name)
isReadOnly := true
pod := &api.Pod{
f.CreatePod(&api.Pod{
ObjectMeta: api.ObjectMeta{
Name: podName,
},
Spec: api.PodSpec{
// Force the Pod to schedule to the node without a scheduler running
NodeName: *nodeName,
// Don't restart the Pod since it is expected to exit
RestartPolicy: api.RestartPolicyNever,
Containers: []api.Container{
@@ -104,12 +94,9 @@ var _ = framework.KubeDescribe("Kubelet", func() {
},
},
},
}
defer podClient.Delete(pod.Name, nil)
_, err := podClient.Create(pod)
Expect(err).To(BeNil(), fmt.Sprintf("Error creating Pod %v", err))
})
Eventually(func() string {
rc, err := podClient.GetLogs(podName, &api.PodLogOptions{}).Stream()
rc, err := f.PodClient().GetLogs(podName, &api.PodLogOptions{}).Stream()
if err != nil {
return ""
}
@@ -172,46 +159,38 @@ func createSummaryTestPods(f *framework.Framework, podNamePrefix string, count i
podNames.Insert(fmt.Sprintf("%s%v", podNamePrefix, i))
}
var pods []*api.Pod
for _, podName := range podNames.List() {
createPod(f, podName, []api.Container{
{
Image: ImageRegistry[busyBoxImage],
Command: []string{"sh", "-c", "while true; do echo 'hello world' | tee /test-empty-dir-mnt/file ; sleep 1; done"},
Name: podName + containerSuffix,
VolumeMounts: []api.VolumeMount{
{MountPath: "/test-empty-dir-mnt", Name: volumeNamePrefix},
pods = append(pods, &api.Pod{
ObjectMeta: api.ObjectMeta{
Name: podName,
},
Spec: api.PodSpec{
// Don't restart the Pod since it is expected to exit
RestartPolicy: api.RestartPolicyNever,
Containers: []api.Container{
{
Image: ImageRegistry[busyBoxImage],
Command: []string{"sh", "-c", "while true; do echo 'hello world' | tee /test-empty-dir-mnt/file ; sleep 1; done"},
Name: podName + containerSuffix,
VolumeMounts: []api.VolumeMount{
{MountPath: "/test-empty-dir-mnt", Name: volumeNamePrefix},
},
},
},
Volumes: []api.Volume{
// TODO: Test secret volumes
// TODO: Test hostpath volumes
{Name: volumeNamePrefix, VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}},
},
},
}, []api.Volume{
// TODO: Test secret volumes
// TODO: Test hostpath volumes
{Name: volumeNamePrefix, VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}},
})
}
f.CreatePods(pods)
return podNames, volumes
}
func createPod(f *framework.Framework, podName string, containers []api.Container, volumes []api.Volume) {
podClient := f.Client.Pods(f.Namespace.Name)
pod := &api.Pod{
ObjectMeta: api.ObjectMeta{
Name: podName,
},
Spec: api.PodSpec{
// Force the Pod to schedule to the node without a scheduler running
NodeName: *nodeName,
// Don't restart the Pod since it is expected to exit
RestartPolicy: api.RestartPolicyNever,
Containers: containers,
Volumes: volumes,
},
}
_, err := podClient.Create(pod)
Expect(err).To(BeNil(), fmt.Sprintf("Error creating Pod %v", err))
framework.ExpectNoError(f.WaitForPodRunning(pod.Name))
}
// Returns pods missing from summary.
func podsMissingFromSummary(s stats.Summary, expectedPods sets.String) sets.String {
expectedPods = sets.StringKeySet(expectedPods)
@@ -244,7 +223,7 @@ func testSummaryMetrics(s stats.Summary, podNamePrefix string) error {
nonNilValue = "expected %q to not be nil"
nonZeroValue = "expected %q to not be zero"
)
if s.Node.NodeName != *nodeName {
if s.Node.NodeName != framework.TestContext.NodeName {
return fmt.Errorf("unexpected node name - %q", s.Node.NodeName)
}
if s.Node.CPU.UsageCoreNanoSeconds == nil {