Repository: kubernetes-sigs/security-profiles-operator
Pull request #420 (2021-04-27 08:23:24)

Do not re-deploy cert-manager within e2e tests
#### What type of PR is this?

/kind failing-test

#### What this PR does / why we need it:
We do not have to test the re-deployment of cert-manager any more since
it is a static dependency of the operator. This should speed-up the e2e
tests as well as make them a bit more robust.
#### Which issue(s) this PR fixes:

<!--
*Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.

Fixes #

or

None
-->
None
#### Does this PR have test?
None
<!--
If tests aren't applicable just write N/A.
-->

#### Special notes for your reviewer:
None
#### Does this PR introduce a user-facing change?

<!--
If no, just write "NONE" in the release-note block below.
If yes, a release note is required:
Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".

For more information on release notes see: https://git.k8s.io/community/contributors/guide/release-notes.md
-->

```release-note
None
```


k8s-ci-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/kubernetes-sigs/security-profiles-operator/pull/420#" title="Author self-approved">saschagrunert</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=kubernetes-sigs%2Fsecurity-profiles-operator).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/kubernetes-sigs/security-profiles-operator/blob/master/OWNERS)~~ [saschagrunert]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->
k8s-ci-robot: @saschagrunert: The following test **failed**, say `/retest` to rerun all failed tests:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-security-profiles-operator-verify | 23cf0cf27f84f6993c6d58d2ec108fedcd452af7 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_security-profiles-operator/420/pull-security-profiles-operator-verify/1386959153842360320) | `/test pull-security-profiles-operator-verify`

[Full PR test history](https://prow.k8s.io/pr-history?org=kubernetes-sigs&repo=security-profiles-operator&pr=420). [Your PR dashboard](https://prow.k8s.io/pr?query=is%3Apr%20state%3Aopen%20author%3Asaschagrunert). Please help us cut down on flakes by [linking to](https://git.k8s.io/community/contributors/devel/sig-testing/flaky-tests.md#filing-issues-for-flaky-tests) an [open issue](https://github.com/kubernetes-sigs/security-profiles-operator/issues?q=is:issue+is:open) when you hit one in your PR.

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
codecov-commenter: # [Codecov](https://codecov.io/gh/kubernetes-sigs/security-profiles-operator/pull/420?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
> Merging [#420](https://codecov.io/gh/kubernetes-sigs/security-profiles-operator/pull/420?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (23cf0cf) into [master](https://codecov.io/gh/kubernetes-sigs/security-profiles-operator/commit/e90060e9b386b1f0ccccce50c8413d1e9004f9be?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (e90060e) will **not change** coverage.
> The diff coverage is `n/a`.

> :exclamation: Current head 23cf0cf differs from pull request most recent head 5c5fce4. Consider uploading reports for the commit 5c5fce4 to get more accurate results

```diff
@@           Coverage Diff           @@
##           master     #420   +/-   ##
=======================================
  Coverage   38.00%   38.00%           
=======================================
  Files          20       20           
  Lines         950      950           
=======================================
  Hits          361      361           
  Misses        574      574           
  Partials       15       15           
```


Patch:
diff --git a/hack/ci/install-kubernetes.sh b/hack/ci/install-kubernetes.sh
index 0ea44966b..dcdb76f51 100755
--- a/hack/ci/install-kubernetes.sh
+++ b/hack/ci/install-kubernetes.sh
@@ -19,7 +19,7 @@ ENVFILE=$(dirname "${BASH_SOURCE[0]}")/env.sh
 . "$ENVFILE"
 
 K8SPATH="$GOPATH/src/k8s.io"
-VERSION=v1.20.2
+VERSION=v1.21.0
 
 download-kubernetes() {
     export KUBERNETES_RELEASE=$VERSION


Test patch:
diff --git a/test/e2e_test.go b/test/e2e_test.go
index f3582a6fc..2737fb74f 100644
--- a/test/e2e_test.go
+++ b/test/e2e_test.go
@@ -45,6 +45,9 @@ const (
 )
 
 func (e *e2e) TestSecurityProfilesOperator() {
+	// Deploy prerequisites
+	e.deployCertManager()
+
 	// Deploy the operator
 	e.deployOperator(manifest)
 	defer e.run("git", "checkout", manifest)
@@ -139,12 +142,66 @@ func (e *e2e) TestSecurityProfilesOperator() {
 	}
 }
 
-func (e *e2e) deployOperator(manifest string) {
-	// Deploy prerequisites
+func (e *e2e) deployCertManager() {
 	e.logf("Deploying cert-manager")
 	e.kubectl("apply", "-f", certmanager)
-	e.verifyCertManager()
 
+	// https://cert-manager.io/docs/installation/kubernetes/#verifying-the-installation
+	e.waitFor(
+		"condition=ready",
+		"--namespace", "cert-manager",
+		"pod", "-l", "app.kubernetes.io/instance=cert-manager",
+	)
+
+	tries := 20
+	certManifest := `
+apiVersion: v1
+kind: Namespace
+metadata:
+  name: cert-manager-test
+---
+apiVersion: cert-manager.io/v1
+kind: Issuer
+metadata:
+  name: test-selfsigned
+  namespace: cert-manager-test
+spec:
+  selfSigned: {}
+---
+apiVersion: cert-manager.io/v1
+kind: Certificate
+metadata:
+  name: selfsigned-cert
+  namespace: cert-manager-test
+spec:
+  dnsNames:
+    - example.com
+  secretName: selfsigned-cert-tls
+  issuerRef:
+    name: test-selfsigned
+`
+
+	file, err := ioutil.TempFile(os.TempDir(), "test-resource*.yaml")
+	e.Nil(err)
+	_, err = file.Write([]byte(certManifest))
+	e.Nil(err)
+	defer os.Remove(file.Name())
+	for i := 0; i < tries; i++ {
+		output, err := command.New(e.kubectlPath, "apply", "-f", file.Name()).Run()
+		e.Nil(err)
+		if output.Success() {
+			break
+		}
+		time.Sleep(defaultWaitTime)
+	}
+	e.waitFor(
+		"condition=Ready",
+		"certificate", "selfsigned-cert",
+		"--namespace", "cert-manager-test",
+	)
+}
+
+func (e *e2e) deployOperator(manifest string) {
 	// Ensure that we do not accidentally pull the image and use the pre-loaded
 	// ones from the nodes
 	e.logf("Setting imagePullPolicy to '%s' in manifest: %s", e.pullPolicy, manifest)
@@ -196,7 +253,6 @@ func (e *e2e) cleanupOperator(manifest string) {
 	e.logf("Cleaning up operator")
 	e.kubectl("delete", "seccompprofiles", "--all", "--all-namespaces")
 	e.kubectl("delete", "--ignore-not-found", "-f", manifest)
-	e.kubectl("delete", "--ignore-not-found", "-f", certmanager)
 }
 
 func (e *e2e) getWorkerNodes() []string {
@@ -298,59 +354,3 @@ func (e *e2e) retry(f func(iteration int) (abort bool)) {
 		time.Sleep(3 * time.Second)
 	}
 }
-
-// https://cert-manager.io/docs/installation/kubernetes/#verifying-the-installation
-func (e *e2e) verifyCertManager() {
-	e.waitFor(
-		"condition=ready",
-		"--namespace", "cert-manager",
-		"pod", "-l", "app.kubernetes.io/instance=cert-manager",
-	)
-
-	tries := 20
-	certManifest := `
-apiVersion: v1
-kind: Namespace
-metadata:
-  name: cert-manager-test
----
-apiVersion: cert-manager.io/v1
-kind: Issuer
-metadata:
-  name: test-selfsigned
-  namespace: cert-manager-test
-spec:
-  selfSigned: {}
----
-apiVersion: cert-manager.io/v1
-kind: Certificate
-metadata:
-  name: selfsigned-cert
-  namespace: cert-manager-test
-spec:
-  dnsNames:
-    - example.com
-  secretName: selfsigned-cert-tls
-  issuerRef:
-    name: test-selfsigned
-`
-
-	file, err := ioutil.TempFile(os.TempDir(), "test-resource*.yaml")
-	e.Nil(err)
-	_, err = file.Write([]byte(certManifest))
-	e.Nil(err)
-	defer os.Remove(file.Name())
-	for i := 0; i < tries; i++ {
-		output, err := command.New(e.kubectlPath, "apply", "-f", file.Name()).Run()
-		e.Nil(err)
-		if output.Success() {
-			break
-		}
-		time.Sleep(defaultWaitTime)
-	}
-	e.waitFor(
-		"condition=Ready",
-		"certificate", "selfsigned-cert",
-		"--namespace", "cert-manager-test",
-	)
-}