Skip to content

Commit

Permalink
fix and cleanup e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
camilamacedo86 committed Mar 31, 2024
1 parent cdc9c48 commit b75aa35
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 26 deletions.
4 changes: 1 addition & 3 deletions test/e2e/utils/test_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
)

const (
certmanagerVersion = "v1.5.3"
certmanagerVersion = "v1.14.4"
certmanagerURLTmpl = "https://github.com/cert-manager/cert-manager/releases/download/%s/cert-manager.yaml"
prometheusOperatorVersion = "0.51"
prometheusOperatorURL = "https://raw.githubusercontent.com/prometheus-operator/" +
Expand Down Expand Up @@ -274,8 +274,6 @@ func (t *TestContext) CreateManagerNamespace() error {
// if a warning with `Warning: would violate PodSecurity` will be raised when the manifests are applied
func (t *TestContext) LabelAllNamespacesToWarnAboutRestricted() error {
_, err := t.Kubectl.Command("label", "--overwrite", "ns", "--all",
"pod-security.kubernetes.io/audit=restricted",
"pod-security.kubernetes.io/enforce-version=v1.24",
"pod-security.kubernetes.io/warn=restricted")
return err
}
Expand Down
32 changes: 32 additions & 0 deletions test/e2e/v4/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import (
"fmt"
"testing"

"sigs.k8s.io/kubebuilder/v3/pkg/plugin/util"
"sigs.k8s.io/kubebuilder/v3/test/e2e/utils"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
Expand All @@ -30,3 +33,32 @@ func TestE2E(t *testing.T) {
fmt.Fprintf(GinkgoWriter, "Starting kubebuilder suite\n")
RunSpecs(t, "Kubebuilder e2e suite")
}

// BeforeSuite run before any specs are run to perform the required actions for all e2e Go tests.
var _ = BeforeSuite(func() {
var err error

kbc, err := utils.NewTestContext(util.KubebuilderBinName, "GO111MODULE=on")
Expect(err).NotTo(HaveOccurred())
Expect(kbc.Prepare()).To(Succeed())

By("installing the cert-manager bundle")
Expect(kbc.InstallCertManager()).To(Succeed())

By("installing the Prometheus operator")
Expect(kbc.InstallPrometheusOperManager()).To(Succeed())
})

// AfterSuite run after all the specs have run, regardless of whether any tests have failed to ensures that
// all be cleaned up
var _ = AfterSuite(func() {
kbc, err := utils.NewTestContext(util.KubebuilderBinName, "GO111MODULE=on")
Expect(err).NotTo(HaveOccurred())
Expect(kbc.Prepare()).To(Succeed())

By("uninstalling the Prometheus manager bundle")
kbc.UninstallPrometheusOperManager()

By("uninstalling the cert-manager bundle")
kbc.UninstallCertManager()
})
33 changes: 10 additions & 23 deletions test/e2e/v4/plugin_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,44 +60,31 @@ var _ = Describe("kubebuilder", func() {
kbc, err = utils.NewTestContext(util.KubebuilderBinName, "GO111MODULE=on")
Expect(err).NotTo(HaveOccurred())
Expect(kbc.Prepare()).To(Succeed())

By("installing the cert-manager bundle")
Expect(kbc.InstallCertManager()).To(Succeed())

By("installing the Prometheus operator")
Expect(kbc.InstallPrometheusOperManager()).To(Succeed())
})

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

By("uninstalling the Prometheus manager bundle")
kbc.UninstallPrometheusOperManager()

By("uninstalling the cert-manager bundle")
kbc.UninstallCertManager()

By("removing controller image and working dir")
kbc.Destroy()
})
It("should generate a runnable project"+
" with restricted pods", func() {
kbc.IsRestricted = true
It("should generate a runnable project", func() {
kbc.IsRestricted = false
GenerateV4(kbc)
Run(kbc, true, false)
})
It("should generate a runnable project without webhooks"+
" with restricted pods", func() {
It("should generate a runnable project with the Installer", func() {
kbc.IsRestricted = false
GenerateV4(kbc)
Run(kbc, false, true)
})
It("should generate a runnable project with the manager running "+
"as restricted and without webhooks", func() {
kbc.IsRestricted = true
GenerateV4WithoutWebhooks(kbc)
Run(kbc, false, false)
})
It("should generate a runnable project"+
" with the Installer", func() {
GenerateV4(kbc)
Run(kbc, false, true)
})
})
})

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

if kbc.IsRestricted && !isToUseInstaller {
if kbc.IsRestricted {
By("validating that manager Pod/container(s) are restricted")
ExpectWithOffset(1, output).NotTo(ContainSubstring("Warning: would violate PodSecurity"))
}
Expand Down

0 comments on commit b75aa35

Please sign in to comment.