Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vfkit: Enable timesync #3416

Merged
merged 3 commits into from Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Expand Up @@ -16,7 +16,7 @@ require (
github.com/coreos/go-systemd/v22 v22.3.2
github.com/crc-org/admin-helper v0.0.12-0.20221012143549-fd5acd1c478e
github.com/crc-org/machine v0.0.0-20221028075518-f9b43442196b
github.com/crc-org/vfkit v0.0.2-0.20221012144032-2e4961165b68
github.com/crc-org/vfkit v0.0.4
github.com/cucumber/godog v0.12.5
github.com/cucumber/messages-go/v10 v10.0.3
github.com/docker/go-units v0.4.0
Expand Down Expand Up @@ -53,7 +53,7 @@ require (
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa
golang.org/x/net v0.0.0-20220722155237-a158d28d115b
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
golang.org/x/sys v0.0.0-20221010170243-090e33056c14
golang.org/x/sys v0.1.0
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467
golang.org/x/text v0.3.7
gopkg.in/yaml.v2 v2.4.0
Expand Down
11 changes: 6 additions & 5 deletions go.sum
Expand Up @@ -88,7 +88,7 @@ github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBp
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/Code-Hex/vz/v2 v2.2.1-0.20221008022127-1b0b4ea5fd24/go.mod h1:khaAlXr1FemIPAjelaXANn0VPdFrHWDL8c8EtIstQNg=
github.com/Code-Hex/vz/v2 v2.2.1-0.20221024123315-d856144e4e72/go.mod h1:khaAlXr1FemIPAjelaXANn0VPdFrHWDL8c8EtIstQNg=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/MakeNowJust/heredoc v0.0.0-20170808103936-bb23615498cd/go.mod h1:64YHyfSL2R96J44Nlwm39UHepQbyR5q10x7iYa1ks2E=
github.com/Masterminds/glide v0.13.2/go.mod h1:STyF5vcenH/rUqTEv+/hBXlSTo7KYwg2oc2f4tzPWic=
Expand Down Expand Up @@ -367,8 +367,8 @@ github.com/crc-org/admin-helper v0.0.12-0.20221012143549-fd5acd1c478e h1:T6m4n9Z
github.com/crc-org/admin-helper v0.0.12-0.20221012143549-fd5acd1c478e/go.mod h1:CerKYGP0C/zPeDd6T/k8H7TmyKKBWhfhAzAupcSKPMU=
github.com/crc-org/machine v0.0.0-20221028075518-f9b43442196b h1:VPbW5D21B1WToPvEA/EGwhi4e3lXevmRff9M1lUTc5g=
github.com/crc-org/machine v0.0.0-20221028075518-f9b43442196b/go.mod h1:9bEsvgLE3LIPfvGATt9Mo73gG1CKKS6A/++VqOONKqc=
github.com/crc-org/vfkit v0.0.2-0.20221012144032-2e4961165b68 h1:BD25mjxOu/hnh2ajkMnyAJbAqvcFTS+YyEaqlwU2o/U=
github.com/crc-org/vfkit v0.0.2-0.20221012144032-2e4961165b68/go.mod h1:9Q+9eVp1Ygxi6Fss8Id6erZ1TKUpHEo2f7b2i7EOuG8=
github.com/crc-org/vfkit v0.0.4 h1:HzyjFDHwC2Nss00Rl92MBNyOgOZRf0ViRw1seq3GdJs=
github.com/crc-org/vfkit v0.0.4/go.mod h1:H2vW0lzCsINR2Fex9Et36Wn6yN//rhLvijAc+0RD0r0=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
Expand Down Expand Up @@ -1132,6 +1132,7 @@ github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSg
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw=
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
github.com/pquerna/cachecontrol v0.0.0-20171018203845-0dec1b30a021/go.mod h1:prYjPmNq4d1NPVmpShWobRqXY3q7Vp+80DqgxxUrUIA=
github.com/prashantgupta24/mac-sleep-notifier v1.0.1/go.mod h1:bcfTio1xW+rjjZzdF0kbMEs9mcCEmrOBOSK+Jeml7zM=
github.com/prometheus/client_golang v0.0.0-20180209125602-c332b6f63c06/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
Expand Down Expand Up @@ -1747,8 +1748,8 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20221010170243-090e33056c14 h1:k5II8e6QD8mITdi+okbbmR/cIyEbeXLBhy5Ha4nevyc=
golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201113234701-d7a72108b828/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY=
Expand Down
1 change: 1 addition & 0 deletions pkg/crc/constants/constants.go
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
1 change: 1 addition & 0 deletions pkg/crc/constants/constants_darwin.go
Expand Up @@ -11,6 +11,7 @@ const (
PodmanRemoteExecutableName = "podman"
TrayExecutableName = "Red Hat OpenShift Local.app"
DaemonAgentLabel = "com.redhat.crc.daemon"
QemuGuestAgentPort = 1234
)

var (
Expand Down
2 changes: 1 addition & 1 deletion pkg/crc/machine/vfkit/constants.go
Expand Up @@ -8,7 +8,7 @@ import (
)

const (
VfkitVersion = "0.0.2"
VfkitVersion = "0.0.4"
VfkitCommand = "vfkit"
)

Expand Down
4 changes: 4 additions & 0 deletions pkg/crc/machine/vfkit/driver_darwin.go
Expand Up @@ -22,7 +22,11 @@ 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.QemuGAVsockPort = constants.QemuGuestAgentPort

vfDriver.SharedDirs = configureShareDirs(machineConfig)

Expand Down
8 changes: 5 additions & 3 deletions pkg/crc/preflight/preflight_checks_linux.go
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
27 changes: 23 additions & 4 deletions pkg/drivers/vfkit/driver_darwin.go
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,10 @@ type Driver struct {
InitrdPath string
VfkitPath string
VirtioNet bool
// TODO: Add vsock port(s)
VsockPath string

VsockPath string
DaemonVsockPort uint
QemuGAVsockPort uint
}

func NewDriver(hostName, storePath string) *Driver {
Expand All @@ -62,6 +65,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 +247,7 @@ func (d *Driver) Start() error {
}

// virtio-vsock device
const vsockPort = 1024
dev, err = client.VirtioVsockNew(vsockPort, d.VsockPath)
dev, err = client.VirtioVsockNew(d.DaemonVsockPort, d.VsockPath, true)
if err != nil {
return err
}
Expand All @@ -251,6 +256,20 @@ func (d *Driver) Start() error {
return err
}

// when loading a VM created by a crc version predating this commit,
// d.QemuGAVsockPort will be missing from ~/.crc/machines/crc/config.json
// In such a case, assume the VM will not support time sync
if d.QemuGAVsockPort != 0 {
timesync, err := client.TimeSyncNew(d.QemuGAVsockPort)
if err != nil {
return err
}
err = vm.AddDevice(timesync)
if err != nil {
return err
}
}

args, err := vm.ToCmdLine()
if err != nil {
return err
Expand Down
191 changes: 191 additions & 0 deletions vendor/github.com/crc-org/vfkit/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.