Skip to content

Commit

Permalink
test(e2e): install cert-manager via helm
Browse files Browse the repository at this point in the history
  • Loading branch information
basti1302 committed May 22, 2024
1 parent e726d73 commit a5b6ed5
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 22 deletions.
9 changes: 8 additions & 1 deletion test-resources/cert-manager/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ set -euo pipefail

cd "$(dirname ${BASH_SOURCE})"

if [[ ! $(helm repo list | grep jetstack) ]]; then
echo "The helm repo for cert-manager has not been found, adding it now."
helm repo add jetstack https://charts.jetstack.io --force-update
echo "Running helm repo update."
helm repo update
fi

echo "removing any left-overs from previous cert-manager installations (if any)"
./undeploy.sh

Expand All @@ -17,4 +24,4 @@ helm install \
--create-namespace \
--version v1.14.5 \
--set installCRDs=true \
--timeout 5m
--timeout 5m
80 changes: 59 additions & 21 deletions test/e2e/e2e_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (

const (
certmanagerVersion = "v1.14.5"
certmanagerURLTmpl = "https://github.com/jetstack/cert-manager/releases/download/%s/cert-manager.yaml"
tracesJsonMaxLineLength = 1_048_576
verifyTelemetryTimeout = 60 * time.Second
verifyTelemetryPollingInterval = 500 * time.Millisecond
Expand Down Expand Up @@ -62,13 +61,50 @@ func EnsureCertManagerIsInstalled() bool {
}

func installCertManager() error {
url := fmt.Sprintf(certmanagerURLTmpl, certmanagerVersion)
if err := RunAndIgnoreOutput(exec.Command("kubectl", "apply", "-f", url)); err != nil {
repoList, err := Run(exec.Command("helm", "repo", "list"))
if err != nil {
return err
}
if !strings.Contains(string(repoList), "jetstack") {
fmt.Fprintf(GinkgoWriter, "The helm repo for cert-manager has not been found, adding it now.\n")
if err := RunAndIgnoreOutput(
exec.Command(
"helm",
"repo",
"add",
"jetstack",
"https://charts.jetstack.io",
"--force-update",
)); err != nil {
return err
}
fmt.Fprintf(GinkgoWriter, "Running helm repo update.\n")
if err = RunAndIgnoreOutput(exec.Command("helm", "repo", "update")); err != nil {
return err
}
}

if err := RunAndIgnoreOutput(exec.Command(
"helm",
"install",
"cert-manager",
"jetstack/cert-manager",
"--namespace",
"cert-manager",
"--create-namespace",
"--version",
certmanagerVersion,
"--set",
"installCRDs=true",
"--timeout",
"5m",
)); 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.
err := RunAndIgnoreOutput(
if err := RunAndIgnoreOutput(
exec.Command(
"kubectl",
"wait",
Expand All @@ -79,11 +115,10 @@ func installCertManager() error {
"cert-manager",
"--timeout",
"5m",
))
if err != nil {
)); err != nil {
return err
}
err = RunAndIgnoreOutput(
if err := RunAndIgnoreOutput(
exec.Command(
"kubectl",
"wait",
Expand All @@ -94,11 +129,10 @@ func installCertManager() error {
"cert-manager",
"--timeout",
"60s",
))
if err != nil {
)); err != nil {
return err
}
err = RunAndIgnoreOutput(
if err := RunAndIgnoreOutput(
exec.Command(
"kubectl",
"wait",
Expand All @@ -109,17 +143,9 @@ func installCertManager() error {
"cert-manager",
"--timeout",
"60s",
))
if err != nil {
)); err != nil {
return err
}

// Not sure what is going on with that, but if there is no wait time after the cert-manager deployment (even though
// we explicitly run kubectl wait for all three deployments), we sometimes run into
// tls: failed to verify certificate: x509: certificate signed by unknown authority
// during the "make deploy" step (which deploys the operator).-
fmt.Fprintf(GinkgoWriter, "waiting for cert-manager to _actually_ become ready (30 seconds wait time)\n")
time.Sleep(30 * time.Second)
return nil
}

Expand All @@ -135,8 +161,20 @@ func UninstallCertManagerIfApplicable(certManagerHasBeenInstalled bool) {
}

func uninstallCertManager() {
url := fmt.Sprintf(certmanagerURLTmpl, certmanagerVersion)
if err := RunAndIgnoreOutput(exec.Command("kubectl", "delete", "-f", url)); err != nil {
if err := RunAndIgnoreOutput(exec.Command(
"helm",
"uninstall",
"cert-manager",
"--namespace",
"cert-manager",
"--ignore-not-found",
)); err != nil {
warnError(err)
}

if err := RunAndIgnoreOutput(
exec.Command(
"kubectl", "delete", "namespace", "cert-manager", "--ignore-not-found")); err != nil {
warnError(err)
}
}
Expand Down

0 comments on commit a5b6ed5

Please sign in to comment.