|
1 | 1 | package cvo |
2 | 2 |
|
3 | 3 | import ( |
4 | | - . "github.com/onsi/ginkgo/v2" |
5 | | - . "github.com/onsi/gomega" |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + |
| 7 | + g "github.com/onsi/ginkgo/v2" |
| 8 | + o "github.com/onsi/gomega" |
| 9 | + kerrors "k8s.io/apimachinery/pkg/api/errors" |
| 10 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 11 | + "k8s.io/client-go/kubernetes" |
| 12 | + |
| 13 | + v1 "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1" |
| 14 | + "github.com/openshift/cluster-version-operator/test/utilities" |
6 | 15 | ) |
7 | 16 |
|
8 | | -var _ = Describe(`[Jira:"Cluster Version Operator"] cluster-version-operator-tests`, func() { |
9 | | - It("should support passing tests", func() { |
10 | | - Expect(true).To(BeTrue()) |
| 17 | +var _ = g.Describe(`[Jira:"Cluster Version Operator"] cluster-version-operator-tests`, func() { |
| 18 | + g.It("should support passing tests", func() { |
| 19 | + o.Expect(true).To(o.BeTrue()) |
| 20 | + }) |
| 21 | +}) |
| 22 | + |
| 23 | +var _ = g.Describe("[Jira:Cluster Version Operator] The cluster version operator", g.Ordered, g.Label("cvo"), func() { |
| 24 | + defer g.GinkgoRecover() |
| 25 | + var client *v1.ConfigV1Client |
| 26 | + var kubeclient *kubernetes.Clientset |
| 27 | + |
| 28 | + g.BeforeAll(func() { |
| 29 | + client = utilities.MustGetV1Client() |
| 30 | + kubeclient = utilities.MustGetKubeClient() |
| 31 | + }) |
| 32 | + |
| 33 | + g.It(`should not install resources annotated with release.openshift.io/delete=true`, g.Label("Conformance", "High", "42543"), func() { |
| 34 | + annotation := "release.openshift.io/delete" |
| 35 | + |
| 36 | + auths, err := client.Authentications().List(context.TODO(), metav1.ListOptions{}) |
| 37 | + o.Expect(kerrors.IsNotFound(err)).To(o.BeFalse(), "The NotFound error should occur when listing authentications") |
| 38 | + |
| 39 | + g.By(fmt.Sprintf("checking if authentication with %s annotation exists", annotation)) |
| 40 | + for _, auth := range auths.Items { |
| 41 | + if _, ok := auth.Annotations[annotation]; ok { |
| 42 | + o.Expect(ok).NotTo(o.BeTrue(), fmt.Sprintf("Unexpectedly installed authentication %s which has '%s' annotation", auth.Name, annotation)) |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + namespaces, err := kubeclient.CoreV1().Namespaces().List(context.TODO(), metav1.ListOptions{}) |
| 47 | + o.Expect(kerrors.IsNotFound(err)).To(o.BeFalse(), "The NotFound error should occur when listing namespaces") |
| 48 | + |
| 49 | + g.By(fmt.Sprintf("checking if special resources with %s annotation exist in all namespaces", annotation)) |
| 50 | + for _, ns := range namespaces.Items { |
| 51 | + namespace := ns.Name |
| 52 | + fmt.Printf("namespace: %s\n", namespace) |
| 53 | + |
| 54 | + fmt.Println(" - Test services...") |
| 55 | + services, err := kubeclient.CoreV1().Services(namespace).List(context.TODO(), metav1.ListOptions{}) |
| 56 | + o.Expect(kerrors.IsNotFound(err)).To(o.BeFalse(), "The NotFound error should occur when listing services") |
| 57 | + for _, service := range services.Items { |
| 58 | + if _, ok := service.Annotations[annotation]; ok { |
| 59 | + o.Expect(ok).NotTo(o.BeTrue(), fmt.Sprintf("Unexpectedly installed service %s which has '%s' annotation", service.Name, annotation)) |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + fmt.Println(" - Test RoleBinding...") |
| 64 | + rolebindings, err := kubeclient.RbacV1().RoleBindings(namespace).List(context.TODO(), metav1.ListOptions{}) |
| 65 | + o.Expect(kerrors.IsNotFound(err)).To(o.BeFalse(), "The NotFound error should occur when listing rolebindings") |
| 66 | + for _, rb := range rolebindings.Items { |
| 67 | + if _, ok := rb.Annotations[annotation]; ok { |
| 68 | + o.Expect(ok).NotTo(o.BeTrue(), fmt.Sprintf("Unexpectedly installed RoleBinding %s which has '%s' annotation", rb.Name, annotation)) |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + fmt.Println(" - Test CronJob...") |
| 73 | + cronjobs, err := kubeclient.BatchV1().CronJobs(namespace).List(context.TODO(), metav1.ListOptions{}) |
| 74 | + o.Expect(kerrors.IsNotFound(err)).To(o.BeFalse(), "The NotFound error should occur when listing cronjobs") |
| 75 | + for _, cj := range cronjobs.Items { |
| 76 | + if _, ok := cj.Annotations[annotation]; ok { |
| 77 | + o.Expect(ok).NotTo(o.BeTrue(), fmt.Sprintf("Unexpectedly installed CronJob %s which has %s annotation", cj.Name, annotation)) |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + fmt.Println("success") |
| 82 | + } |
11 | 83 | }) |
12 | 84 | }) |
0 commit comments