Repository: kubernetes-sigs/security-profiles-operator
Pull request #309 (2021-02-16 12:47:02)

Pass pre-build operator image to e2e test
#### What type of PR is this?


/kind cleanup


#### What this PR does / why we need it:
We now pre-build the operators container image and pass it over to the
VM to speedup the CI.
#### 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?

<!--
If tests aren't applicable just write N/A.
-->
Yes
#### 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/309#" 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: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/kubernetes-sigs/security-profiles-operator/pull/309#pullrequestreview-591192547" title="LGTM">hasheddan</a>*, *<a href="https://github.com/kubernetes-sigs/security-profiles-operator/pull/309#" 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)~~ [hasheddan,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: New changes are detected. LGTM label has been removed.
codecov-io: # [Codecov](https://codecov.io/gh/kubernetes-sigs/security-profiles-operator/pull/309?src=pr&el=h1) Report
> Merging [#309](https://codecov.io/gh/kubernetes-sigs/security-profiles-operator/pull/309?src=pr&el=desc) (089c880) into [master](https://codecov.io/gh/kubernetes-sigs/security-profiles-operator/commit/7caf7bba3825cb317c63e42c16aca22dc85fbcb2?el=desc) (7caf7bb) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/kubernetes-sigs/security-profiles-operator/pull/309/graphs/tree.svg?width=650&height=150&src=pr&token=37VIWSZ1ZT)](https://codecov.io/gh/kubernetes-sigs/security-profiles-operator/pull/309?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master     #309   +/-   ##
=======================================
  Coverage   28.17%   28.17%           
=======================================
  Files           9        9           
  Lines         653      653           
=======================================
  Hits          184      184           
  Misses        450      450           
  Partials       19       19           
```

| Flag | Coverage Δ | |
|---|---|---|
| unittests | `28.17% <ø> (ø)` | |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more.


------

[Continue to review full report at Codecov](https://codecov.io/gh/kubernetes-sigs/security-profiles-operator/pull/309?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/kubernetes-sigs/security-profiles-operator/pull/309?src=pr&el=footer). Last update [7caf7bb...089c880](https://codecov.io/gh/kubernetes-sigs/security-profiles-operator/pull/309?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

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/309#pullrequestreview-591192547" title="LGTM">hasheddan</a>*, *<a href="https://github.com/kubernetes-sigs/security-profiles-operator/pull/309#pullrequestreview-591218117" title="Approved">JAORMX</a>*, *<a href="https://github.com/kubernetes-sigs/security-profiles-operator/pull/309#" 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)~~ [hasheddan,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: New changes are detected. LGTM label has been removed.
saschagrunert: :thinking: 
```
    default: ++ sudo podman load -i /vagrant/image.tar
    default:   open /vagrant/image.tar/manifest.json: no such file or directory
    default:   open /vagrant/image.tar/index.json: no such file or directory
    default: Error: error pulling "": Invalid image localhost/
```
saschagrunert: Ah it's the download artifacts path which will be converted into a directory… Now it should work :crossed_fingers: 
JAORMX: /lgtm

Patch:
diff --git a/.gitignore b/.gitignore
index b74770193..6e159c045 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,4 +4,5 @@
 .vagrant
 Vagrantfile
 build
+image.tar
 result
diff --git a/Makefile b/Makefile
index 909747372..687eb6eb6 100644
--- a/Makefile
+++ b/Makefile
@@ -169,6 +169,15 @@ update-mocks: ## Update all generated mocks
 		mv tmp $$f ;\
 	done
 
+.PHONY: vagrant-up
+vagrant-up: ## Boot the vagrant based test VM
+	if [ ! -f image.tar ]; then \
+		make image IMAGE=$(IMAGE) && \
+		$(CONTAINER_RUNTIME) save -o image.tar $(IMAGE); \
+	fi
+	ln -sf hack/ci/Vagrantfile .
+	vagrant up
+
 # Verification targets
 
 .PHONY: verify
diff --git a/hack/ci/Vagrantfile b/hack/ci/Vagrantfile
index 572a0370d..7e4ac410c 100644
--- a/hack/ci/Vagrantfile
+++ b/hack/ci/Vagrantfile
@@ -33,6 +33,13 @@ Vagrant.configure("2") do |config|
     SHELL
   end
 
+  config.vm.provision "load-test-image", type: "shell", run: "once" do |sh|
+    sh.inline = <<~SHELL
+      set -euxo pipefail
+      sudo podman load -i /vagrant/image.tar
+    SHELL
+  end
+
   config.vm.provision "install-cri-o", type: "shell", run: "once" do |sh|
     sh.inline = <<~SHELL
       set -euxo pipefail


Test patch:
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index c990d604b..6aa66ccd9 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -33,17 +33,31 @@ jobs:
           flags: unittests
           verbose: true
 
+  image:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v2
+      - run: make image
+      - run: podman save -o image.tar security-profiles-operator
+      - uses: actions/upload-artifact@v2
+        with:
+          name: image
+          path: image.tar
+
   e2e:
+    needs: image
     runs-on: macos-10.15
     timeout-minutes: 40
     env:
       RUN: ./hack/ci/run.sh
     steps:
       - uses: actions/checkout@v2
+      - uses: actions/download-artifact@v2
+        with:
+          name: image
+          path: .
       - name: Boot Virtual Machine
-        run: |
-          ln -sf hack/ci/Vagrantfile .
-          vagrant up
+        run: make vagrant-up
       - name: Show environment information
         run: $RUN kubectl get nodes -o wide
       - name: Run E2E tests
diff --git a/test/suite_test.go b/test/suite_test.go
index 21bc5fdbe..991f78692 100644
--- a/test/suite_test.go
+++ b/test/suite_test.go
@@ -358,12 +358,7 @@ func (e *vanilla) SetupSuite() {
 }
 
 func (e *vanilla) SetupTest() {
-	// Build and load the test image
-	e.logf("Building operator container image")
-	e.run("make", "image", "IMAGE="+e.testImage)
-	e.run(
-		containerRuntime, "pull", e.selinuxdImage,
-	)
+	e.run(containerRuntime, "pull", e.selinuxdImage)
 }
 
 func (e *vanilla) TearDownTest() {