|
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 | + |
| 12 | + "github.com/openshift/cluster-version-operator/test/utilities" |
6 | 13 | ) |
7 | 14 |
|
8 | | -var _ = Describe(`[Jira:"Cluster Version Operator"] cluster-version-operator-tests`, func() { |
9 | | - It("should support passing tests", func() { |
10 | | - Expect(true).To(BeTrue()) |
| 15 | +var _ = g.Describe(`[Jira:"Cluster Version Operator"] cluster-version-operator-tests`, g.Label("cvo"), func() { |
| 16 | + g.It("should support passing tests", func() { |
| 17 | + o.Expect(true).To(o.BeTrue()) |
| 18 | + }) |
| 19 | + |
| 20 | + g.It(`should not install resources annotated with release.openshift.io/delete=true`, g.Label("Conformance", "High", "42543"), func() { |
| 21 | + annotation := "release.openshift.io/delete" |
| 22 | + |
| 23 | + client := utilities.MustGetV1Client() |
| 24 | + auths, err := client.Authentications().List(context.TODO(), metav1.ListOptions{}) |
| 25 | + o.Expect(kerrors.IsNotFound(err)).To(o.BeFalse(), "The NotFound error should occur when lising authentications") |
| 26 | + |
| 27 | + fmt.Println("Test Authentication...") |
| 28 | + for _, auth := range auths.Items { |
| 29 | + if _, ok := auth.Annotations[annotation]; ok { |
| 30 | + o.Expect(ok).NotTo(o.BeTrue(), fmt.Sprintf("Unexpectedly installed authentication %s which has release.openshift.io/delete annotation", auth.Name)) |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + kubeclient := utilities.MustGetKubeClient() |
| 35 | + namespaces, err := kubeclient.CoreV1().Namespaces().List(context.TODO(), metav1.ListOptions{}) |
| 36 | + o.Expect(kerrors.IsNotFound(err)).To(o.BeFalse(), "The NotFound error should occur when lising namespaces") |
| 37 | + |
| 38 | + for _, ns := range namespaces.Items { |
| 39 | + namespace := ns.Name |
| 40 | + fmt.Printf("namespace: %s\n", namespace) |
| 41 | + |
| 42 | + fmt.Println(" - Test services...") |
| 43 | + services, err := kubeclient.CoreV1().Services(namespace).List(context.TODO(), metav1.ListOptions{}) |
| 44 | + o.Expect(kerrors.IsNotFound(err)).To(o.BeFalse(), "The NotFound error should occur when lising services") |
| 45 | + for _, service := range services.Items { |
| 46 | + if _, ok := service.Annotations[annotation]; ok { |
| 47 | + o.Expect(ok).NotTo(o.BeTrue(), fmt.Sprintf("Unexpectedly installed service %s which has release.openshift.io/delete annotation", service.Name)) |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + fmt.Println(" - Test RoleBinding...") |
| 52 | + rolebindings, err := kubeclient.RbacV1().RoleBindings(namespace).List(context.TODO(), metav1.ListOptions{}) |
| 53 | + o.Expect(kerrors.IsNotFound(err)).To(o.BeFalse(), "The NotFound error should occur when lising rolebindings") |
| 54 | + for _, rb := range rolebindings.Items { |
| 55 | + if _, ok := rb.Annotations[annotation]; ok { |
| 56 | + o.Expect(ok).NotTo(o.BeTrue(), fmt.Sprintf("Unexpectedly installed RoleBinding %s which has release.openshift.io/delete annotation", rb.Name)) |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + fmt.Println(" - Test CronJob...") |
| 61 | + cronjobs, err := kubeclient.BatchV1().CronJobs(namespace).List(context.TODO(), metav1.ListOptions{}) |
| 62 | + o.Expect(kerrors.IsNotFound(err)).To(o.BeFalse(), "The NotFound error should occur when lising cronjobs") |
| 63 | + for _, cj := range cronjobs.Items { |
| 64 | + if _, ok := cj.Annotations[annotation]; ok { |
| 65 | + o.Expect(ok).NotTo(o.BeTrue(), fmt.Sprintf("Unexpectedly installed CronJob %s which has release.openshift.io/delete annotation", cj.Name)) |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + fmt.Println("success") |
| 70 | + } |
11 | 71 | }) |
12 | 72 | }) |
0 commit comments