Repository: code-ready/crc
Pull request #3240 (2022-06-28 10:52:24)

ubuntu: Fix apparmor rule for podman preset
On Ubuntu, crc's preflights add an apparmor rule to allow the use of
cacheDir/*/crc.qcow2 by libvirt. With podman bundles, the file is named
`crc-podman.qcow2`, which causes `crc start` to fail with permission
errors.

openshift-ci[bot]: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by:
To complete the [pull request process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process), please ask for approval from **cfergeau** after the PR has been reviewed.

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=code-ready%2Fcrc).

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

- **[OWNERS](https://github.com/code-ready/crc/blob/main/OWNERS)**

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":["cfergeau"]} -->
praveenkumar: @cfergeau did you tested this on ubuntu or it need to be tested?
cfergeau: > @cfergeau did you tested this on ubuntu or it need to be tested?

I've tested it on Ubuntu 20.04
openshift-ci[bot]: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/code-ready/crc/pull/3240#pullrequestreview-1023644444" title="Approved">praveenkumar</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=code-ready%2Fcrc).

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/code-ready/crc/blob/main/OWNERS)~~ [praveenkumar]

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":[]} -->

Patch:
diff --git a/pkg/crc/preflight/preflight_ubuntu_linux.go b/pkg/crc/preflight/preflight_ubuntu_linux.go
index ae6fb3451..a1105c116 100644
--- a/pkg/crc/preflight/preflight_ubuntu_linux.go
+++ b/pkg/crc/preflight/preflight_ubuntu_linux.go
@@ -51,7 +51,7 @@ func checkAppArmorExceptionIsPresent(reader reader) func() error {
 	}
 }
 
-// Add the exception `cacheDir/*/crc.qcow2 rk` in AppArmor template
+// Add the exception `cacheDir/*/crc*.qcow2 rk` in AppArmor template
 func addAppArmorExceptionForQcowDisks(reader reader, writer writer) func() error {
 	return replaceInAppArmorTemplate(reader, writer, appArmorHeader, expectedLines())
 }
@@ -77,6 +77,6 @@ func replaceInAppArmorTemplate(reader reader, writer writer, before string, afte
 }
 
 func expectedLines() string {
-	line := fmt.Sprintf("  %s rk,", filepath.Join(constants.MachineCacheDir, "*", "crc.qcow2"))
+	line := fmt.Sprintf("  %s rk,", filepath.Join(constants.MachineCacheDir, "*", "crc*.qcow2"))
 	return fmt.Sprintf("%s\n%s\n", appArmorHeader, line)
 }


Test patch:
diff --git a/pkg/crc/preflight/preflight_ubuntu_linux_test.go b/pkg/crc/preflight/preflight_ubuntu_linux_test.go
index 17c29f6a5..5e8f6e242 100644
--- a/pkg/crc/preflight/preflight_ubuntu_linux_test.go
+++ b/pkg/crc/preflight/preflight_ubuntu_linux_test.go
@@ -19,7 +19,7 @@ profile LIBVIRT_TEMPLATE flags=(attach_disconnected) {
 }`
 	expected = `#include <tunables/global>
 profile LIBVIRT_TEMPLATE flags=(attach_disconnected) {
-  ` + constants.MachineCacheDir + `/*/crc.qcow2 rk,
+  ` + constants.MachineCacheDir + `/*/crc*.qcow2 rk,
 
   #include <abstractions/libvirt-qemu>
 }`