Skip to content

Commit b75aa35

Browse files
fix and cleanup e2e tests
1 parent cdc9c48 commit b75aa35

File tree

3 files changed

+43
-26
lines changed

3 files changed

+43
-26
lines changed

test/e2e/utils/test_context.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
)
3232

3333
const (
34-
certmanagerVersion = "v1.5.3"
34+
certmanagerVersion = "v1.14.4"
3535
certmanagerURLTmpl = "https://github.com/cert-manager/cert-manager/releases/download/%s/cert-manager.yaml"
3636
prometheusOperatorVersion = "0.51"
3737
prometheusOperatorURL = "https://raw.githubusercontent.com/prometheus-operator/" +
@@ -274,8 +274,6 @@ func (t *TestContext) CreateManagerNamespace() error {
274274
// if a warning with `Warning: would violate PodSecurity` will be raised when the manifests are applied
275275
func (t *TestContext) LabelAllNamespacesToWarnAboutRestricted() error {
276276
_, err := t.Kubectl.Command("label", "--overwrite", "ns", "--all",
277-
"pod-security.kubernetes.io/audit=restricted",
278-
"pod-security.kubernetes.io/enforce-version=v1.24",
279277
"pod-security.kubernetes.io/warn=restricted")
280278
return err
281279
}

test/e2e/v4/e2e_suite_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import (
2020
"fmt"
2121
"testing"
2222

23+
"sigs.k8s.io/kubebuilder/v3/pkg/plugin/util"
24+
"sigs.k8s.io/kubebuilder/v3/test/e2e/utils"
25+
2326
. "github.com/onsi/ginkgo/v2"
2427
. "github.com/onsi/gomega"
2528
)
@@ -30,3 +33,32 @@ func TestE2E(t *testing.T) {
3033
fmt.Fprintf(GinkgoWriter, "Starting kubebuilder suite\n")
3134
RunSpecs(t, "Kubebuilder e2e suite")
3235
}
36+
37+
// BeforeSuite run before any specs are run to perform the required actions for all e2e Go tests.
38+
var _ = BeforeSuite(func() {
39+
var err error
40+
41+
kbc, err := utils.NewTestContext(util.KubebuilderBinName, "GO111MODULE=on")
42+
Expect(err).NotTo(HaveOccurred())
43+
Expect(kbc.Prepare()).To(Succeed())
44+
45+
By("installing the cert-manager bundle")
46+
Expect(kbc.InstallCertManager()).To(Succeed())
47+
48+
By("installing the Prometheus operator")
49+
Expect(kbc.InstallPrometheusOperManager()).To(Succeed())
50+
})
51+
52+
// AfterSuite run after all the specs have run, regardless of whether any tests have failed to ensures that
53+
// all be cleaned up
54+
var _ = AfterSuite(func() {
55+
kbc, err := utils.NewTestContext(util.KubebuilderBinName, "GO111MODULE=on")
56+
Expect(err).NotTo(HaveOccurred())
57+
Expect(kbc.Prepare()).To(Succeed())
58+
59+
By("uninstalling the Prometheus manager bundle")
60+
kbc.UninstallPrometheusOperManager()
61+
62+
By("uninstalling the cert-manager bundle")
63+
kbc.UninstallCertManager()
64+
})

test/e2e/v4/plugin_cluster_test.go

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -60,44 +60,31 @@ var _ = Describe("kubebuilder", func() {
6060
kbc, err = utils.NewTestContext(util.KubebuilderBinName, "GO111MODULE=on")
6161
Expect(err).NotTo(HaveOccurred())
6262
Expect(kbc.Prepare()).To(Succeed())
63-
64-
By("installing the cert-manager bundle")
65-
Expect(kbc.InstallCertManager()).To(Succeed())
66-
67-
By("installing the Prometheus operator")
68-
Expect(kbc.InstallPrometheusOperManager()).To(Succeed())
6963
})
7064

7165
AfterEach(func() {
7266
By("clean up API objects created during the test")
7367
kbc.CleanupManifests(filepath.Join("config", "default"))
7468

75-
By("uninstalling the Prometheus manager bundle")
76-
kbc.UninstallPrometheusOperManager()
77-
78-
By("uninstalling the cert-manager bundle")
79-
kbc.UninstallCertManager()
80-
8169
By("removing controller image and working dir")
8270
kbc.Destroy()
8371
})
84-
It("should generate a runnable project"+
85-
" with restricted pods", func() {
86-
kbc.IsRestricted = true
72+
It("should generate a runnable project", func() {
73+
kbc.IsRestricted = false
8774
GenerateV4(kbc)
8875
Run(kbc, true, false)
8976
})
90-
It("should generate a runnable project without webhooks"+
91-
" with restricted pods", func() {
77+
It("should generate a runnable project with the Installer", func() {
78+
kbc.IsRestricted = false
79+
GenerateV4(kbc)
80+
Run(kbc, false, true)
81+
})
82+
It("should generate a runnable project with the manager running "+
83+
"as restricted and without webhooks", func() {
9284
kbc.IsRestricted = true
9385
GenerateV4WithoutWebhooks(kbc)
9486
Run(kbc, false, false)
9587
})
96-
It("should generate a runnable project"+
97-
" with the Installer", func() {
98-
GenerateV4(kbc)
99-
Run(kbc, false, true)
100-
})
10188
})
10289
})
10390

@@ -162,7 +149,7 @@ func Run(kbc *utils.TestContext, hasWebhook, isToUseInstaller bool) {
162149
ExpectWithOffset(1, err).NotTo(HaveOccurred())
163150
}
164151

165-
if kbc.IsRestricted && !isToUseInstaller {
152+
if kbc.IsRestricted {
166153
By("validating that manager Pod/container(s) are restricted")
167154
ExpectWithOffset(1, output).NotTo(ContainSubstring("Warning: would violate PodSecurity"))
168155
}

0 commit comments

Comments
 (0)