Skip to content

Commit

Permalink
constants: Add DaemonVsockPort constant
Browse files Browse the repository at this point in the history
It's currently hardcoded in the libvirt and vfkit drivers.
This centralizes its value in a single place
  • Loading branch information
cfergeau authored and praveenkumar committed Dec 1, 2022
1 parent 8c66328 commit a3aca7b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions pkg/crc/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
CRCWindowsTrayDownloadURL = "https://github.com/crc-org/tray-electron/releases/download/%s/crc-tray-windows.zip"
DefaultContext = "admin"
DaemonHTTPEndpoint = "http://unix/api"
DaemonVsockPort = 1024
DefaultPodmanNamedPipe = `\\.\pipe\crc-podman`
RootlessPodmanSocket = "/run/user/1000/podman/podman.sock"
RootfulPodmanSocket = "/run/podman/podman.sock"
Expand Down
2 changes: 2 additions & 0 deletions pkg/crc/machine/vfkit/driver_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ func CreateHost(machineConfig config.MachineConfig) *vfkit.Driver {
vfDriver.VfkitPath = filepath.Join(constants.BinDir(), VfkitCommand)

vfDriver.VirtioNet = machineConfig.NetworkMode == network.SystemNetworkingMode

vfDriver.VsockPath = constants.TapSocketPath
vfDriver.DaemonVsockPort = constants.DaemonVsockPort

vfDriver.SharedDirs = configureShareDirs(machineConfig)

Expand Down
8 changes: 5 additions & 3 deletions pkg/crc/preflight/preflight_checks_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,12 @@ func systemdUnitRunning(sd *systemd.Commander, unitName string) bool {
}

const (
vsockUnitName = "crc-vsock.socket"
vsockUnit = `[Unit]
vsockUnitName = "crc-vsock.socket"
vsockUnitTemplate = `[Unit]
Description=CRC vsock socket
[Socket]
ListenStream=vsock::1024
ListenStream=vsock::%d
Service=crc-daemon.service
[Install]
Expand Down Expand Up @@ -322,6 +322,8 @@ ExecStart=%s daemon
`
)

var vsockUnit = fmt.Sprintf(vsockUnitTemplate, constants.DaemonVsockPort)

func checkSystemdUnit(unitName string, unitContent string, shouldBeRunning bool) error {
sd := systemd.NewHostSystemdCommander().User()

Expand Down
12 changes: 8 additions & 4 deletions pkg/drivers/vfkit/driver_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"time"

"github.com/Masterminds/semver/v3"
"github.com/crc-org/crc/pkg/crc/constants"
"github.com/crc-org/crc/pkg/crc/logging"
crcos "github.com/crc-org/crc/pkg/os"
"github.com/crc-org/machine/libmachine/drivers"
Expand All @@ -46,8 +47,9 @@ type Driver struct {
InitrdPath string
VfkitPath string
VirtioNet bool
// TODO: Add vsock port(s)
VsockPath string

VsockPath string
DaemonVsockPort uint
}

func NewDriver(hostName, storePath string) *Driver {
Expand All @@ -62,6 +64,9 @@ func NewDriver(hostName, storePath string) *Driver {
CPU: DefaultCPUs,
Memory: DefaultMemory,
},
// needed when loading a VM which was created before
// DaemonVsockPort was introduced
DaemonVsockPort: constants.DaemonVsockPort,
}
}

Expand Down Expand Up @@ -241,8 +246,7 @@ func (d *Driver) Start() error {
}

// virtio-vsock device
const vsockPort = 1024
dev, err = client.VirtioVsockNew(vsockPort, d.VsockPath, true)
dev, err = client.VirtioVsockNew(d.DaemonVsockPort, d.VsockPath, true)
if err != nil {
return err
}
Expand Down

0 comments on commit a3aca7b

Please sign in to comment.