|
1 | | -// SPDX-License-Identifier: AGPL-3.0-only |
2 | | - |
3 | 1 | package e2e |
4 | 2 |
|
5 | | -import ( |
6 | | - "fmt" |
7 | | - "os/exec" |
8 | | - "time" |
9 | | - |
10 | | - . "github.com/onsi/ginkgo/v2" |
11 | | - . "github.com/onsi/gomega" |
12 | | - |
13 | | - "go.datum.net/workload-operator/test/utils" |
14 | | -) |
15 | | - |
16 | | -const namespace = "workload-operator-system" |
17 | | - |
18 | | -var _ = Describe("controller", Ordered, func() { |
19 | | - BeforeAll(func() { |
20 | | - By("installing prometheus operator") |
21 | | - Expect(utils.InstallPrometheusOperator()).To(Succeed()) |
22 | | - |
23 | | - By("installing the cert-manager") |
24 | | - Expect(utils.InstallCertManager()).To(Succeed()) |
25 | | - |
26 | | - By("creating manager namespace") |
27 | | - cmd := exec.Command("kubectl", "create", "ns", namespace) |
28 | | - _, _ = utils.Run(cmd) |
29 | | - }) |
30 | | - |
31 | | - AfterAll(func() { |
32 | | - By("uninstalling the Prometheus manager bundle") |
33 | | - utils.UninstallPrometheusOperator() |
34 | | - |
35 | | - By("uninstalling the cert-manager bundle") |
36 | | - utils.UninstallCertManager() |
37 | | - |
38 | | - By("removing manager namespace") |
39 | | - cmd := exec.Command("kubectl", "delete", "ns", namespace) |
40 | | - _, _ = utils.Run(cmd) |
41 | | - }) |
42 | | - |
43 | | - Context("Operator", func() { |
44 | | - It("should run successfully", func() { |
45 | | - var controllerPodName string |
46 | | - var err error |
47 | | - |
48 | | - // projectimage stores the name of the image used in the example |
49 | | - var projectimage = "example.com/workload-operator:v0.0.1" |
50 | | - |
51 | | - By("building the manager(Operator) image") |
52 | | - cmd := exec.Command("make", "docker-build", fmt.Sprintf("IMG=%s", projectimage)) |
53 | | - _, err = utils.Run(cmd) |
54 | | - ExpectWithOffset(1, err).NotTo(HaveOccurred()) |
55 | | - |
56 | | - By("loading the the manager(Operator) image on Kind") |
57 | | - err = utils.LoadImageToKindClusterWithName(projectimage) |
58 | | - ExpectWithOffset(1, err).NotTo(HaveOccurred()) |
59 | | - |
60 | | - By("installing CRDs") |
61 | | - cmd = exec.Command("make", "install") |
62 | | - _, err = utils.Run(cmd) |
63 | | - ExpectWithOffset(1, err).NotTo(HaveOccurred()) |
64 | | - |
65 | | - By("deploying the controller-manager") |
66 | | - cmd = exec.Command("make", "deploy", fmt.Sprintf("IMG=%s", projectimage)) |
67 | | - _, err = utils.Run(cmd) |
68 | | - ExpectWithOffset(1, err).NotTo(HaveOccurred()) |
69 | | - |
70 | | - By("validating that the controller-manager pod is running as expected") |
71 | | - verifyControllerUp := func() error { |
72 | | - // Get pod name |
73 | | - |
74 | | - cmd = exec.Command("kubectl", "get", |
75 | | - "pods", "-l", "control-plane=controller-manager", |
76 | | - "-o", "go-template={{ range .items }}"+ |
77 | | - "{{ if not .metadata.deletionTimestamp }}"+ |
78 | | - "{{ .metadata.name }}"+ |
79 | | - "{{ \"\\n\" }}{{ end }}{{ end }}", |
80 | | - "-n", namespace, |
81 | | - ) |
82 | | - |
83 | | - podOutput, err := utils.Run(cmd) |
84 | | - ExpectWithOffset(2, err).NotTo(HaveOccurred()) |
85 | | - podNames := utils.GetNonEmptyLines(string(podOutput)) |
86 | | - if len(podNames) != 1 { |
87 | | - return fmt.Errorf("expect 1 controller pods running, but got %d", len(podNames)) |
88 | | - } |
89 | | - controllerPodName = podNames[0] |
90 | | - ExpectWithOffset(2, controllerPodName).Should(ContainSubstring("controller-manager")) |
91 | | - |
92 | | - // Validate pod status |
93 | | - cmd = exec.Command("kubectl", "get", |
94 | | - "pods", controllerPodName, "-o", "jsonpath={.status.phase}", |
95 | | - "-n", namespace, |
96 | | - ) |
97 | | - status, err := utils.Run(cmd) |
98 | | - ExpectWithOffset(2, err).NotTo(HaveOccurred()) |
99 | | - if string(status) != "Running" { |
100 | | - return fmt.Errorf("controller pod in %s status", status) |
101 | | - } |
102 | | - return nil |
103 | | - } |
104 | | - EventuallyWithOffset(1, verifyControllerUp, time.Minute, time.Second).Should(Succeed()) |
105 | | - |
106 | | - }) |
107 | | - }) |
108 | | -}) |
| 3 | +// This file exists due to the inability to bypass e2e generation when using |
| 4 | +// kubebuilder to generate resources. |
| 5 | +// |
| 6 | +// See: https://github.com/kubernetes-sigs/kubebuilder/issues/4509 |
0 commit comments