Skip to content

Commit 39bcb9b

Browse files
committed
Preflight: remove check and fix for vsock
It was initially added as part of ed9342 but since now we are moving to consume gvproxy and there is no virtual network running as part of crc daemon so this is no more required.
1 parent e3a3276 commit 39bcb9b

File tree

2 files changed

+14
-89
lines changed

2 files changed

+14
-89
lines changed

pkg/crc/preflight/preflight_linux.go

Lines changed: 2 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package preflight
22

33
import (
4-
"errors"
54
"fmt"
6-
"os"
75
"strings"
86

97
"github.com/crc-org/crc/v2/pkg/crc/constants"
@@ -13,8 +11,6 @@ import (
1311
crcpreset "github.com/crc-org/crc/v2/pkg/crc/preset"
1412
crcos "github.com/crc-org/crc/v2/pkg/os"
1513
"github.com/crc-org/crc/v2/pkg/os/linux"
16-
17-
"golang.org/x/sys/unix"
1814
)
1915

2016
func qemuPreflightChecks(distro *linux.OsRelease) []Check {
@@ -98,15 +94,11 @@ func qemuPreflightChecks(distro *linux.OsRelease) []Check {
9894
}
9995

10096
var vsockPreflightCheck = Check{
101-
configKeySuffix: "check-vsock",
102-
checkDescription: "Checking if vsock is correctly configured",
103-
check: checkVsock,
104-
fixDescription: "Setting up vsock support",
105-
fix: fixVsock,
10697
cleanupDescription: "Removing vsock configuration",
10798
cleanup: removeVsockCrcSettings,
99+
flags: CleanUpOnly,
108100

109-
labels: labels{Os: Linux, NetworkMode: User},
101+
labels: labels{Os: Linux},
110102
}
111103

112104
var wsl2PreflightCheck = Check{
@@ -125,81 +117,6 @@ const (
125117
vsockModuleAutoLoadConfPath = "/etc/modules-load.d/vhost_vsock.conf"
126118
)
127119

128-
func checkVsock() error {
129-
executable, err := os.Executable()
130-
if err != nil {
131-
return err
132-
}
133-
134-
// Check for cap_net_bind_service capability with inheritable flag (+eip or =eip)
135-
if err := checkCapabilities(executable, "cap_net_bind_service+eip", "cap_net_bind_service=eip"); err != nil {
136-
return err
137-
}
138-
139-
// This test is needed in order to trigger the move of the udev rule to its new location.
140-
// The old location was used in the 1.21 release.
141-
if !crcos.FileExists(vsockUdevLocalAdminRulesPath) {
142-
return errors.New("vsock udev rule does not exist")
143-
}
144-
145-
err = unix.Access("/dev/vsock", unix.R_OK|unix.W_OK)
146-
if err != nil {
147-
return errors.New("/dev/vsock is not readable by the current user")
148-
}
149-
return nil
150-
}
151-
152-
func fixVsock() error {
153-
executable, err := os.Executable()
154-
if err != nil {
155-
return err
156-
}
157-
158-
// Set cap_net_bind_service with inheritable flag for the CRC daemon
159-
if err := setCapabilities(executable, "cap_net_bind_service=+eip"); err != nil {
160-
return err
161-
}
162-
163-
// Remove udev rule which was used in crc 1.21 - it's been moved to a new location
164-
err = crcos.RemoveFileAsRoot(
165-
fmt.Sprintf("Removing udev rule in %s", vsockUdevSystemRulesPath),
166-
vsockUdevSystemRulesPath,
167-
)
168-
if err != nil {
169-
return err
170-
}
171-
udevRule := `KERNEL=="vsock", MODE="0660", OWNER="root", GROUP="kvm"`
172-
if crcos.FileContentMatches(vsockUdevLocalAdminRulesPath, []byte(udevRule)) != nil {
173-
err = crcos.WriteToFileAsRoot("Creating udev rule for /dev/vsock", udevRule, vsockUdevLocalAdminRulesPath, 0644)
174-
if err != nil {
175-
return err
176-
}
177-
_, _, err = crcos.RunPrivileged("Reloading udev rules database", "udevadm", "control", "--reload")
178-
if err != nil {
179-
return err
180-
}
181-
}
182-
if crcos.FileExists("/dev/vsock") && unix.Access("/dev/vsock", unix.R_OK|unix.W_OK) != nil {
183-
_, _, err = crcos.RunPrivileged("Applying udev rule to /dev/vsock", "udevadm", "trigger", "/dev/vsock")
184-
if err != nil {
185-
return err
186-
}
187-
} else {
188-
_, _, err = crcos.RunPrivileged("Loading vhost_vsock kernel module", "modprobe", "vhost_vsock")
189-
if err != nil {
190-
return err
191-
}
192-
}
193-
194-
if crcos.FileContentMatches(vsockModuleAutoLoadConfPath, []byte("vhost_vsock")) != nil {
195-
err = crcos.WriteToFileAsRoot(fmt.Sprintf("Creating file %s", vsockModuleAutoLoadConfPath), "vhost_vsock", vsockModuleAutoLoadConfPath, 0644)
196-
if err != nil {
197-
return err
198-
}
199-
}
200-
return nil
201-
}
202-
203120
func removeVsockCrcSettings() error {
204121
var mErr crcErrors.MultiError
205122
err := crcos.RemoveFileAsRoot(fmt.Sprintf("Removing udev rule in %s", vsockUdevSystemRulesPath), vsockUdevSystemRulesPath)

pkg/crc/preflight/preflight_linux_test.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ var checkListForDistros = []checkListForDistro{
9191
{check: checkCrcDnsmasqAndNetworkManagerConfigFile},
9292
{check: checkSystemdResolvedIsRunning},
9393
{check: checkCrcNetworkManagerDispatcherFile},
94+
{cleanup: removeVsockCrcSettings},
9495
{configKeySuffix: "check-bundle-extracted"},
9596
},
9697
},
@@ -125,6 +126,7 @@ var checkListForDistros = []checkListForDistro{
125126
{check: checkNetworkManagerIsRunning},
126127
{check: checkCrcNetworkManagerConfig},
127128
{check: checkCrcDnsmasqConfigFile},
129+
{cleanup: removeVsockCrcSettings},
128130
{configKeySuffix: "check-bundle-extracted"},
129131
},
130132
},
@@ -154,7 +156,7 @@ var checkListForDistros = []checkListForDistro{
154156
{cleanup: removeCrcVM},
155157
{check: checkDaemonSystemdService},
156158
{check: checkDaemonSystemdSockets},
157-
{check: checkVsock},
159+
{cleanup: removeVsockCrcSettings},
158160
{configKeySuffix: "check-bundle-extracted"},
159161
},
160162
},
@@ -190,6 +192,7 @@ var checkListForDistros = []checkListForDistro{
190192
{check: checkCrcDnsmasqAndNetworkManagerConfigFile},
191193
{check: checkSystemdResolvedIsRunning},
192194
{check: checkCrcNetworkManagerDispatcherFile},
195+
{cleanup: removeVsockCrcSettings},
193196
{configKeySuffix: "check-bundle-extracted"},
194197
},
195198
},
@@ -224,6 +227,7 @@ var checkListForDistros = []checkListForDistro{
224227
{check: checkNetworkManagerIsRunning},
225228
{check: checkCrcNetworkManagerConfig},
226229
{check: checkCrcDnsmasqConfigFile},
230+
{cleanup: removeVsockCrcSettings},
227231
{configKeySuffix: "check-bundle-extracted"},
228232
},
229233
},
@@ -253,7 +257,7 @@ var checkListForDistros = []checkListForDistro{
253257
{cleanup: removeCrcVM},
254258
{check: checkDaemonSystemdService},
255259
{check: checkDaemonSystemdSockets},
256-
{check: checkVsock},
260+
{cleanup: removeVsockCrcSettings},
257261
{configKeySuffix: "check-bundle-extracted"},
258262
},
259263
},
@@ -289,6 +293,7 @@ var checkListForDistros = []checkListForDistro{
289293
{check: checkCrcDnsmasqAndNetworkManagerConfigFile},
290294
{check: checkSystemdResolvedIsRunning},
291295
{check: checkCrcNetworkManagerDispatcherFile},
296+
{cleanup: removeVsockCrcSettings},
292297
{configKeySuffix: "check-bundle-extracted"},
293298
},
294299
},
@@ -323,6 +328,7 @@ var checkListForDistros = []checkListForDistro{
323328
{check: checkNetworkManagerIsRunning},
324329
{check: checkCrcNetworkManagerConfig},
325330
{check: checkCrcDnsmasqConfigFile},
331+
{cleanup: removeVsockCrcSettings},
326332
{configKeySuffix: "check-bundle-extracted"},
327333
},
328334
},
@@ -352,7 +358,7 @@ var checkListForDistros = []checkListForDistro{
352358
{cleanup: removeCrcVM},
353359
{check: checkDaemonSystemdService},
354360
{check: checkDaemonSystemdSockets},
355-
{check: checkVsock},
361+
{cleanup: removeVsockCrcSettings},
356362
{configKeySuffix: "check-bundle-extracted"},
357363
},
358364
},
@@ -389,6 +395,7 @@ var checkListForDistros = []checkListForDistro{
389395
{check: checkCrcDnsmasqAndNetworkManagerConfigFile},
390396
{check: checkSystemdResolvedIsRunning},
391397
{check: checkCrcNetworkManagerDispatcherFile},
398+
{cleanup: removeVsockCrcSettings},
392399
{configKeySuffix: "check-bundle-extracted"},
393400
},
394401
},
@@ -424,6 +431,7 @@ var checkListForDistros = []checkListForDistro{
424431
{check: checkNetworkManagerIsRunning},
425432
{check: checkCrcNetworkManagerConfig},
426433
{check: checkCrcDnsmasqConfigFile},
434+
{cleanup: removeVsockCrcSettings},
427435
{configKeySuffix: "check-bundle-extracted"},
428436
},
429437
},
@@ -454,7 +462,7 @@ var checkListForDistros = []checkListForDistro{
454462
{check: checkDaemonSystemdService},
455463
{check: checkDaemonSystemdSockets},
456464
{configKeySuffix: "check-apparmor-profile-setup"},
457-
{check: checkVsock},
465+
{cleanup: removeVsockCrcSettings},
458466
{configKeySuffix: "check-bundle-extracted"},
459467
},
460468
},

0 commit comments

Comments
 (0)