Skip to content

Commit c4294c6

Browse files
Add e2e tests for support to Prometheus by Operator
1 parent 937688e commit c4294c6

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

test/e2e/utils/test_context.go

+14
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
)
2828

2929
const certmanagerVersion = "v0.10.1"
30+
const prometheusOperatorVersion= "0.33"
3031

3132
// KBTestContext specified to run e2e tests
3233
type KBTestContext struct {
@@ -94,6 +95,19 @@ func (kc *KBTestContext) InstallCertManager() error {
9495
return err
9596
}
9697

98+
// InstallPrometheusOperManager installs the prometheus manager bundle.
99+
func (kc *KBTestContext) InstallPrometheusOperManager() error {
100+
_, err := kc.Kubectl.Apply(false, "-f", fmt.Sprintf("https://raw.githubusercontent.com/coreos/prometheus-operator/release-%s/bundle.yaml", prometheusOperatorVersion))
101+
return err
102+
}
103+
104+
// UninstallPrometheusOperManager uninstalls the prometheus manager bundle.
105+
func (kc *KBTestContext) UninstallPrometheusOperManager() {
106+
if _, err := kc.Kubectl.Delete(false, "-f", fmt.Sprintf("https://github.com/coreos/prometheus-operator/blob/release-%s/bundle.yaml", prometheusOperatorVersion)); err != nil {
107+
fmt.Fprintf(GinkgoWriter, "error when running kubectl delete during cleaning up prometheus bundle: %v\n", err)
108+
}
109+
}
110+
97111
// UninstallCertManager uninstalls the cert manager bundle.
98112
func (kc *KBTestContext) UninstallCertManager() {
99113
if _, err := kc.Kubectl.Delete(false, "-f", fmt.Sprintf("https://github.com/jetstack/cert-manager/releases/download/%s/cert-manager.yaml", certmanagerVersion)); err != nil {

test/e2e/v2/e2e_suite.go

+23
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,18 @@ var _ = Describe("kubebuilder", func() {
4040

4141
By("installing cert manager bundle")
4242
Expect(kbc.InstallCertManager()).To(Succeed())
43+
44+
By("installing prometheus operator")
45+
Expect(kbc.InstallPrometheusOperManager()).To(Succeed())
4346
})
4447

4548
AfterEach(func() {
4649
By("clean up created API objects during test process")
4750
kbc.CleanupManifests(filepath.Join("config", "default"))
4851

52+
By("uninstalling prometheus manager bundle")
53+
kbc.UninstallPrometheusOperManager()
54+
4955
By("uninstalling cert manager bundle")
5056
kbc.UninstallCertManager()
5157

@@ -104,6 +110,9 @@ var _ = Describe("kubebuilder", func() {
104110
Expect(utils.UncommentCode(
105111
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
106112
"#- ../certmanager", "#")).To(Succeed())
113+
Expect(utils.UncommentCode(
114+
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
115+
"#- ../prometheus", "#")).To(Succeed())
107116
Expect(utils.UncommentCode(
108117
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
109118
"#- manager_webhook_patch.yaml", "#")).To(Succeed())
@@ -189,6 +198,20 @@ var _ = Describe("kubebuilder", func() {
189198
return err
190199
}, time.Minute, time.Second).Should(Succeed())
191200

201+
By("validate prometheus manager has provisioned the Service")
202+
Eventually(func() error {
203+
_, err := kbc.Kubectl.Get(
204+
false,
205+
"Service", "prometheus-operator")
206+
return err
207+
}, time.Minute, time.Second).Should(Succeed())
208+
209+
By("validate Service Monitor for Prometheus is applied in the namespace")
210+
_, err = kbc.Kubectl.Get(
211+
true,
212+
"ServiceMonitor")
213+
Expect(err).NotTo(HaveOccurred())
214+
192215
By("validate the mutating|validating webhooks have the CA injected")
193216
verifyCAInjection := func() error {
194217
mwhOutput, err := kbc.Kubectl.Get(

0 commit comments

Comments
 (0)