Skip to content

Commit

Permalink
re-add cert-manager
Browse files Browse the repository at this point in the history
Signed-off-by: Adem Baccara <71262172+Adembc@users.noreply.github.com>
  • Loading branch information
Adembc committed Aug 15, 2024
1 parent c832b27 commit f09dcf4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
6 changes: 6 additions & 0 deletions workspaces/controller/test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ var (
var _ = Describe("controller", Ordered, func() {

BeforeAll(func() {
By("installing the cert-manager")
Expect(utils.InstallCertManager()).To(Succeed())

projectDir, _ = utils.GetProjectDir()

By("creating the controller namespace")
Expand Down Expand Up @@ -117,6 +120,9 @@ var _ = Describe("controller", Ordered, func() {
By("deleting CRDs")
cmd = exec.Command("make", "uninstall")
_, _ = utils.Run(cmd)

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

Context("Operator", func() {
Expand Down
41 changes: 40 additions & 1 deletion workspaces/controller/test/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ import (
. "github.com/onsi/ginkgo/v2" //nolint:golint,revive
)

const (
// use LTS version of cert-manager

certManagerVersion = "v1.12.13"
certManagerURLTmpl = "https://github.com/jetstack/cert-manager/releases/download/%s/cert-manager.yaml"
)

func warnError(err error) {
fmt.Fprintf(GinkgoWriter, "warning: %v\n", err)
}

// Run executes the provided command within this context
func Run(cmd *exec.Cmd) ([]byte, error) {
dir, _ := GetProjectDir()
Expand All @@ -45,7 +56,35 @@ func Run(cmd *exec.Cmd) ([]byte, error) {
return output, nil
}

// LoadImageToKindCluster loads a local docker image to the kind cluster
// UninstallCertManager uninstalls the cert manager
func UninstallCertManager() {
url := fmt.Sprintf(certManagerURLTmpl, certManagerVersion)
cmd := exec.Command("kubectl", "delete", "-f", url)
if _, err := Run(cmd); err != nil {
warnError(err)
}
}

// InstallCertManager installs the cert manager bundle.
func InstallCertManager() error {
url := fmt.Sprintf(certManagerURLTmpl, certManagerVersion)
cmd := exec.Command("kubectl", "apply", "-f", url)
if _, err := Run(cmd); err != nil {
return err
}
// Wait for cert-manager-webhook to be ready, which can take time if cert-manager
// was re-installed after uninstalling on a cluster.
cmd = exec.Command("kubectl", "wait", "deployment.apps/cert-manager-webhook",
"--for", "condition=Available",
"--namespace", "cert-manager",
"--timeout", "5m",
)

_, err := Run(cmd)
return err
}

// LoadImageToKindClusterWithName loads a local docker image to the kind cluster
func LoadImageToKindClusterWithName(name string) error {
var cluster string
if v, ok := os.LookupEnv("KIND_CLUSTER"); ok {
Expand Down

0 comments on commit f09dcf4

Please sign in to comment.