Skip to content

Commit

Permalink
Bug 1992596: e2e/cli: Move annotations.sh and basicresources.sh to pr…
Browse files Browse the repository at this point in the history
…oper e2e

Add annotation, label, and other basic tests

Added secret and status resources

Add project

Add service and statefulset resources

Formatting

Combine annotations.sh and image changes into PR

Migrate YAML list and probe tests

All new cli/compat tests passing

Add oauthaccesstoken validation

Last of basicresources.sh migrated, cleanup

Use e2e image for timeout test

Move larger tests to additional PRs

Remove AsAdmin for label and annotation tests

Remove newCreateOptions

Remove AsAdmin where not needed

status and explain

Added secret and status resources

Add service and statefulset resources

Formatting

Combine annotations.sh and image changes into PR

Migrate YAML list and probe tests

All new cli/compat tests passing

Add oauthaccesstoken validation

Last of basicresources.sh migrated, cleanup

Use e2e image for timeout test

Move larger tests to additional PRs

Cleanup after rebase
  • Loading branch information
deejross committed Sep 7, 2021
1 parent 1e66686 commit f572091
Show file tree
Hide file tree
Showing 18 changed files with 503 additions and 1,071 deletions.
65 changes: 65 additions & 0 deletions test/extended/cli/annotation.go
@@ -0,0 +1,65 @@
package cli

import (
"context"

g "github.com/onsi/ginkgo"
o "github.com/onsi/gomega"

exutil "github.com/openshift/origin/test/extended/util"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var _ = g.Describe("[sig-cli] oc annotate", func() {
defer g.GinkgoRecover()

const (
podAnnotationTemplate = `{{index .metadata.annotations "new-anno"}}`
)

var (
ctx = context.Background()
oc = exutil.NewCLI("oc-annotation")
)

g.It("pod", func() {
g.By("creating hello-openshift pod")
_, err := oc.KubeClient().CoreV1().Pods(oc.Namespace()).Create(
ctx,
newHelloPod(),
metav1.CreateOptions{},
)
o.Expect(err).NotTo(o.HaveOccurred())

g.By("setting a new annotation")
out, err := oc.Run("annotate").Args("pod", "hello-openshift", "new-anno=hello").Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(out).To(o.ContainSubstring("pod/hello-openshift annotated"))

g.By("validating new annotation")
out, err = oc.Run("get").Args("pod", "hello-openshift", "--template", podAnnotationTemplate).Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(out).To(o.Equal("hello"))

g.By("removing the annotation")
out, err = oc.Run("annotate").Args("pod", "hello-openshift", "new-anno-").Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(out).To(o.ContainSubstring("pod/hello-openshift annotated"))

g.By("validating missing annotation")
out, err = oc.Run("get").Args("pod", "hello-openshift", "--template", podAnnotationTemplate).Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(out).To(o.Equal("<no value>"))

g.By("setting empty annotation")
out, err = oc.Run("annotate").Args("pod", "hello-openshift", `new-anno=`).Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(out).To(o.ContainSubstring("pod/hello-openshift annotated"))

g.By("validating empty annotation")
out, err = oc.Run("get").Args("pod", "hello-openshift", "--template", podAnnotationTemplate).Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(out).To(o.BeEmpty())
})
})
61 changes: 8 additions & 53 deletions test/extended/cli/compat.go
Expand Up @@ -8,64 +8,13 @@ import (
g "github.com/onsi/ginkgo"
o "github.com/onsi/gomega"

kapiv1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

exutil "github.com/openshift/origin/test/extended/util"
"github.com/openshift/origin/test/extended/util/image"
)

func cliPod(cli *exutil.CLI, shell string) *kapiv1.Pod {
return &kapiv1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "cli-test",
},
Spec: kapiv1.PodSpec{
RestartPolicy: kapiv1.RestartPolicyNever,
Containers: []kapiv1.Container{
{
Name: "test",
Image: image.ShellImage(),
Command: []string{"/bin/bash", "-c", "set -euo pipefail; " + shell},
Env: []kapiv1.EnvVar{
{
Name: "HOME",
Value: "/tmp",
},
},
},
},
},
}
}

func cliPodWithImage(cli *exutil.CLI, shell string) *kapiv1.Pod {
return &kapiv1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "cli-test",
},
Spec: kapiv1.PodSpec{
ServiceAccountName: "builder",
RestartPolicy: kapiv1.RestartPolicyNever,
Containers: []kapiv1.Container{
{
Name: "test",
Image: image.ShellImage(),
Command: []string{"/bin/bash", "-c", shell},
Env: []kapiv1.EnvVar{
{
Name: "HOME",
Value: "/tmp",
},
},
},
},
},
}
}

var _ = g.Describe("[sig-cli] CLI", func() {
var _ = g.Describe("[sig-cli] oc", func() {
defer g.GinkgoRecover()

var oc *exutil.CLI
Expand All @@ -92,7 +41,7 @@ var _ = g.Describe("[sig-cli] CLI", func() {
}, metav1.CreateOptions{})
o.Expect(err).NotTo(o.HaveOccurred())

pod := cli.Create(cliPodWithImage(oc, heredoc.Docf(`
pod := cli.Create(newShellPod(heredoc.Docf(`
set -x
# verify we can make API calls
Expand All @@ -101,4 +50,10 @@ var _ = g.Describe("[sig-cli] CLI", func() {
`)))
cli.WaitForSuccess(pod.Name, 5*time.Minute)
})

g.It("can get list of nodes", func() {
oc := oc.AsAdmin()
err := oc.Run("get").Args("nodes").Execute()
o.Expect(err).NotTo(o.HaveOccurred())
})
})
65 changes: 65 additions & 0 deletions test/extended/cli/label.go
@@ -0,0 +1,65 @@
package cli

import (
"context"

g "github.com/onsi/ginkgo"
o "github.com/onsi/gomega"

exutil "github.com/openshift/origin/test/extended/util"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
podLabelTemplate = `{{index .metadata.labels "new-label"}}`
)

var _ = g.Describe("[sig-cli] oc label", func() {
defer g.GinkgoRecover()

var (
ctx = context.Background()
oc = exutil.NewCLI("oc-label")
)

g.It("pod", func() {
g.By("creating hello-openshift pod")
_, err := oc.KubeClient().CoreV1().Pods(oc.Namespace()).Create(
ctx,
newHelloPod(),
metav1.CreateOptions{},
)
o.Expect(err).NotTo(o.HaveOccurred())

g.By("setting a new label")
out, err := oc.Run("label").Args("pod", "hello-openshift", "new-label=hello").Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(out).To(o.ContainSubstring("pod/hello-openshift labeled"))

g.By("validating new label")
out, err = oc.Run("get").Args("pod", "hello-openshift", "--template", podLabelTemplate).Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(out).To(o.Equal("hello"))

g.By("removing the label")
out, err = oc.Run("label").Args("pod", "hello-openshift", "new-label-").Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(out).To(o.ContainSubstring("pod/hello-openshift labeled"))

g.By("validating missing label")
out, err = oc.Run("get").Args("pod", "hello-openshift", "--template", podLabelTemplate).Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(out).To(o.Equal("<no value>"))

g.By("setting empty label")
out, err = oc.Run("label").Args("pod", "hello-openshift", `new-label=`).Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(out).To(o.ContainSubstring("pod/hello-openshift labeled"))

g.By("validating empty label")
out, err = oc.Run("get").Args("pod", "hello-openshift", "--template", podLabelTemplate).Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(out).To(o.BeEmpty())
})
})
26 changes: 26 additions & 0 deletions test/extended/cli/project.go
@@ -0,0 +1,26 @@
package cli

import (
g "github.com/onsi/ginkgo"
o "github.com/onsi/gomega"

exutil "github.com/openshift/origin/test/extended/util"
)

var _ = g.Describe("[sig-cli] oc project", func() {
defer g.GinkgoRecover()

var (
oc = exutil.NewCLI("oc-project").AsAdmin()
)

g.It("--show-labels works for projects", func() {
out, err := oc.Run("label").Args("namespace", oc.Namespace(), "foo=bar").Output()
o.Expect(out).To(o.ContainSubstring("labeled"))
o.Expect(err).NotTo(o.HaveOccurred())

out, err = oc.Run("get").Args("project", oc.Namespace(), "--show-labels").Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(out).To(o.ContainSubstring("foo=bar"))
})
})
144 changes: 144 additions & 0 deletions test/extended/cli/resources.go
@@ -0,0 +1,144 @@
package cli

import (
"github.com/openshift/origin/test/extended/util/image"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
k8simage "k8s.io/kubernetes/test/utils/image"
)

func newHelloPod() *corev1.Pod {
return &corev1.Pod{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "Pod",
},
ObjectMeta: metav1.ObjectMeta{
Name: "hello-openshift",
Labels: map[string]string{
"name": "hello-openshift",
},
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "hello-openshift",
Image: k8simage.GetE2EImage(k8simage.Agnhost),
Args: []string{"netexec"},
Ports: []corev1.ContainerPort{
{
ContainerPort: 8080,
Protocol: corev1.ProtocolTCP,
},
},
VolumeMounts: []corev1.VolumeMount{
{
Name: "tmp",
MountPath: "/tmp",
},
},
TerminationMessagePath: "/dev/termination-log",
ImagePullPolicy: corev1.PullIfNotPresent,
},
},
Volumes: []corev1.Volume{
{
Name: "tmp",
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{},
},
},
},
RestartPolicy: corev1.RestartPolicyAlways,
DNSPolicy: corev1.DNSClusterFirst,
},
}
}

func newShellPod(shell string) *corev1.Pod {
return &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "cli-test",
},
Spec: corev1.PodSpec{
ServiceAccountName: "builder",
RestartPolicy: corev1.RestartPolicyNever,
Containers: []corev1.Container{
{
Name: "test",
Image: image.ShellImage(),
Command: []string{"/bin/bash", "-c", shell},
Env: []corev1.EnvVar{
{
Name: "HOME",
Value: "/tmp",
},
},
},
},
},
}
}

func newFrontendService() *corev1.Service {
return &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "frontend",
Labels: map[string]string{
"name": "frontend",
},
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{
{
Protocol: corev1.ProtocolTCP,
Port: 9998,
TargetPort: intstr.FromInt(9998),
},
},
Selector: map[string]string{
"name": "frontend",
},
Type: "ClusterIP",
SessionAffinity: corev1.ServiceAffinityNone,
},
}
}

func newBusyBoxStatefulSet() *appsv1.StatefulSet {
var replicas = int32(1)

return &appsv1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
Name: "testapp",
},
Spec: appsv1.StatefulSetSpec{
Replicas: &replicas,
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"app": "testapp",
},
},
ServiceName: "frontend",
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app": "testapp",
},
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "testapp",
Image: k8simage.GetE2EImage(k8simage.BusyBox),
Command: []string{"/bin/sleep"},
Args: []string{"300"},
},
},
},
},
},
}
}

0 comments on commit f572091

Please sign in to comment.