Skip to content

Commit e34d00d

Browse files
cleanup: cert-manager and prometheus installs into e2e tests
1 parent 9dd4fef commit e34d00d

File tree

3 files changed

+20
-50
lines changed

3 files changed

+20
-50
lines changed

test/e2e/utils/test_context.go

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ import (
2929
. "github.com/onsi/ginkgo/v2" //nolint:golint,revive
3030
)
3131

32+
const (
33+
certmanagerVersion = "v1.9.1"
34+
certmanagerURLTmpl = "https://github.com/jetstack/cert-manager/releases/download/%s/cert-manager.yaml"
35+
prometheusOperatorVersion = "0.51"
36+
prometheusOperatorURL = "https://raw.githubusercontent.com/prometheus-operator/" +
37+
"prometheus-operator/release-%s/bundle.yaml"
38+
)
39+
3240
// TestContext specified to run e2e tests
3341
type TestContext struct {
3442
*CmdContext
@@ -108,34 +116,15 @@ func (t *TestContext) Prepare() error {
108116
return os.MkdirAll(t.Dir, 0o755)
109117
}
110118

111-
const (
112-
certmanagerVersionWithv1beta2CRs = "v0.11.0"
113-
certmanagerLegacyVersion = "v1.0.4"
114-
certmanagerVersion = "v1.5.3"
115-
116-
certmanagerURLTmplLegacy = "https://github.com/jetstack/cert-manager/releases/download/%s/cert-manager-legacy.yaml"
117-
certmanagerURLTmpl = "https://github.com/jetstack/cert-manager/releases/download/%s/cert-manager.yaml"
118-
)
119-
120119
// makeCertManagerURL returns a kubectl-able URL for the cert-manager bundle.
121-
func (t *TestContext) makeCertManagerURL(hasv1beta1CRs bool) string {
122-
// Return a URL for the manifest bundle with v1beta1 CRs.
123-
if hasv1beta1CRs {
124-
return fmt.Sprintf(certmanagerURLTmpl, certmanagerVersionWithv1beta2CRs)
125-
}
126-
127-
// Determine which URL to use for a manifest bundle with v1 CRs.
128-
// The most up-to-date bundle uses v1 CRDs, which were introduced in k8s v1.16.
129-
if ver := t.K8sVersion.ServerVersion; ver.GetMajorInt() <= 1 && ver.GetMinorInt() < 16 {
130-
return fmt.Sprintf(certmanagerURLTmplLegacy, certmanagerLegacyVersion)
131-
}
120+
func (t *TestContext) makeCertManagerURL() string {
132121
return fmt.Sprintf(certmanagerURLTmpl, certmanagerVersion)
133122
}
134123

135124
// InstallCertManager installs the cert manager bundle. If hasv1beta1CRs is true,
136125
// the legacy version (which uses v1alpha2 CRs) is installed.
137-
func (t *TestContext) InstallCertManager(hasv1beta1CRs bool) error {
138-
url := t.makeCertManagerURL(hasv1beta1CRs)
126+
func (t *TestContext) InstallCertManager() error {
127+
url := t.makeCertManagerURL()
139128
if _, err := t.Kubectl.Apply(false, "-f", url, "--validate=false"); err != nil {
140129
return err
141130
}
@@ -149,43 +138,24 @@ func (t *TestContext) InstallCertManager(hasv1beta1CRs bool) error {
149138
return err
150139
}
151140

152-
// UninstallCertManager uninstalls the cert manager bundle. If hasv1beta1CRs is true,
153-
// the legacy version (which uses v1alpha2 CRs) is installed.
154-
func (t *TestContext) UninstallCertManager(hasv1beta1CRs bool) {
155-
url := t.makeCertManagerURL(hasv1beta1CRs)
141+
// UninstallCertManager uninstalls the cert manager bundle.
142+
func (t *TestContext) UninstallCertManager() {
143+
url := t.makeCertManagerURL()
156144
if _, err := t.Kubectl.Delete(false, "-f", url); err != nil {
157145
warnError(err)
158146
}
159147
}
160148

161-
const (
162-
prometheusOperatorLegacyVersion = "0.33"
163-
prometheusOperatorLegacyURL = "https://raw.githubusercontent.com/coreos/prometheus-operator/release-%s/bundle.yaml"
164-
prometheusOperatorVersion = "0.51"
165-
prometheusOperatorURL = "https://raw.githubusercontent.com/prometheus-operator/" +
166-
"prometheus-operator/release-%s/bundle.yaml"
167-
)
168-
169149
// InstallPrometheusOperManager installs the prometheus manager bundle.
170150
func (t *TestContext) InstallPrometheusOperManager() error {
171-
var url string
172-
if ver := t.K8sVersion.ServerVersion; ver.GetMajorInt() <= 1 && ver.GetMinorInt() < 16 {
173-
url = fmt.Sprintf(prometheusOperatorLegacyURL, prometheusOperatorLegacyVersion)
174-
} else {
175-
url = fmt.Sprintf(prometheusOperatorURL, prometheusOperatorVersion)
176-
}
151+
url := fmt.Sprintf(prometheusOperatorURL, prometheusOperatorVersion)
177152
_, err := t.Kubectl.Apply(false, "-f", url)
178153
return err
179154
}
180155

181156
// UninstallPrometheusOperManager uninstalls the prometheus manager bundle.
182157
func (t *TestContext) UninstallPrometheusOperManager() {
183-
var url string
184-
if ver := t.K8sVersion.ServerVersion; ver.GetMajorInt() <= 1 && ver.GetMinorInt() < 16 {
185-
url = fmt.Sprintf(prometheusOperatorLegacyURL, prometheusOperatorLegacyVersion)
186-
} else {
187-
url = fmt.Sprintf(prometheusOperatorURL, prometheusOperatorVersion)
188-
}
158+
url := fmt.Sprintf(prometheusOperatorURL, prometheusOperatorVersion)
189159
if _, err := t.Kubectl.Delete(false, "-f", url); err != nil {
190160
warnError(err)
191161
}

test/e2e/v3/plugin_cluster_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ var _ = Describe("kubebuilder", func() {
8282
// Use cert-manager with v1 CRs.
8383
BeforeEach(func() {
8484
By("installing the cert-manager bundle")
85-
Expect(kbc.InstallCertManager(false)).To(Succeed())
85+
Expect(kbc.InstallCertManager()).To(Succeed())
8686
})
8787
AfterEach(func() {
8888
By("uninstalling the cert-manager bundle")
89-
kbc.UninstallCertManager(false)
89+
kbc.UninstallCertManager()
9090
})
9191

9292
It("should generate a runnable project go/v3 with v1 CRDs and Webhooks", func() {

test/e2e/v4/plugin_cluster_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ var _ = Describe("kubebuilder", func() {
6262
Expect(kbc.Prepare()).To(Succeed())
6363

6464
By("installing the cert-manager bundle")
65-
Expect(kbc.InstallCertManager(false)).To(Succeed())
65+
Expect(kbc.InstallCertManager()).To(Succeed())
6666

6767
By("installing the Prometheus operator")
6868
Expect(kbc.InstallPrometheusOperManager()).To(Succeed())
@@ -76,7 +76,7 @@ var _ = Describe("kubebuilder", func() {
7676
kbc.UninstallPrometheusOperManager()
7777

7878
By("uninstalling the cert-manager bundle")
79-
kbc.UninstallCertManager(false)
79+
kbc.UninstallCertManager()
8080

8181
By("removing controller image and working dir")
8282
kbc.Destroy()

0 commit comments

Comments
 (0)