Skip to content

Commit

Permalink
vfkit: Add VfkitPath() helper
Browse files Browse the repository at this point in the history
This will limit the amount of code using filepath.Join(BinDir(),
VfkitCommand).
  • Loading branch information
cfergeau authored and praveenkumar committed Feb 3, 2023
1 parent 9801914 commit baebd65
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
4 changes: 3 additions & 1 deletion pkg/crc/cache/cache_darwin.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package cache

import (
"path/filepath"

"github.com/crc-org/crc/pkg/crc/machine/vfkit"
)

func NewVfkitCache() *Cache {
return New(vfkit.VfkitCommand, vfkit.VfkitDownloadURL, vfkit.VfkitVersion, getVfkitVersion)
return New(filepath.Base(vfkit.ExecutablePath()), vfkit.VfkitDownloadURL, vfkit.VfkitVersion, getVfkitVersion)
}

func getVfkitVersion(executablePath string) (string, error) {
Expand Down
11 changes: 9 additions & 2 deletions pkg/crc/machine/vfkit/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@ package vfkit

import (
"fmt"
"path/filepath"

"github.com/crc-org/crc/pkg/crc/constants"
)

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

var (
VfkitDownloadURL = fmt.Sprintf("https://github.com/crc-org/vfkit/releases/download/v%s/%s", VfkitVersion, VfkitCommand)
VfkitDownloadURL = fmt.Sprintf("https://github.com/crc-org/vfkit/releases/download/v%s/%s", VfkitVersion, vfkitCommand)
VfkitEntitlementsURL = fmt.Sprintf("https://raw.githubusercontent.com/crc-org/vfkit/v%s/vf.entitlements", VfkitVersion)
)

func ExecutablePath() string {
return filepath.Join(constants.BinDir(), vfkitCommand)
}
3 changes: 1 addition & 2 deletions pkg/crc/machine/vfkit/driver_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package vfkit

import (
"fmt"
"path/filepath"

"github.com/crc-org/crc/pkg/crc/constants"
"github.com/crc-org/crc/pkg/crc/machine/config"
Expand All @@ -19,7 +18,7 @@ func CreateHost(machineConfig config.MachineConfig) *vfkit.Driver {
vfDriver.Cmdline = machineConfig.KernelCmdLine
vfDriver.VmlinuzPath = machineConfig.Kernel
vfDriver.InitrdPath = machineConfig.Initramfs
vfDriver.VfkitPath = filepath.Join(constants.BinDir(), VfkitCommand)
vfDriver.VfkitPath = ExecutablePath()

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

Expand Down
5 changes: 3 additions & 2 deletions pkg/crc/preflight/preflight_checks_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/crc-org/crc/pkg/crc/cache"
"github.com/crc-org/crc/pkg/crc/constants"
"github.com/crc-org/crc/pkg/crc/logging"
"github.com/crc-org/crc/pkg/crc/machine/vfkit"
"github.com/crc-org/crc/pkg/crc/version"
crcos "github.com/crc-org/crc/pkg/os"
"github.com/crc-org/crc/pkg/os/launchd"
Expand Down Expand Up @@ -134,7 +135,7 @@ func killVfkitProcess() error {
if err != nil {
return fmt.Errorf("Could not find 'pgrep'. %w", err)
}
if _, _, err := crcos.RunWithDefaultLocale(pgrepPath, "-f", filepath.Join(constants.BinDir(), "vfkit")); err != nil {
if _, _, err := crcos.RunWithDefaultLocale(pgrepPath, "-f", vfkit.ExecutablePath()); err != nil {
var exitErr *exec.ExitError
if errors.As(err, &exitErr) {
/* 1: no processes matched */
Expand All @@ -151,7 +152,7 @@ func killVfkitProcess() error {
if err != nil {
return fmt.Errorf("Could not find 'pkill'. %w", err)
}
if _, _, err := crcos.RunWithDefaultLocale(pkillPath, "-SIGKILL", "-f", filepath.Join(constants.BinDir(), "vfkit")); err != nil {
if _, _, err := crcos.RunWithDefaultLocale(pkillPath, "-SIGKILL", "-f", vfkit.ExecutablePath()); err != nil {
return fmt.Errorf("Failed to kill 'vfkit' process. %w", err)
}
return nil
Expand Down

0 comments on commit baebd65

Please sign in to comment.