check brew install paths for socket_vmnet
parent
a777c22409
commit
46e9cc24ee
|
@ -281,8 +281,8 @@ func initNetworkingFlags() {
|
|||
startCmd.Flags().Int(sshSSHPort, defaultSSHPort, "SSH port (ssh driver only)")
|
||||
|
||||
// socket vmnet
|
||||
startCmd.Flags().String(socketVMnetClientPath, "/opt/socket_vmnet/bin/socket_vmnet_client", "Path to the socket vmnet client binary")
|
||||
startCmd.Flags().String(socketVMnetPath, "/var/run/socket_vmnet", "Path to socket vmnet binary")
|
||||
startCmd.Flags().String(socketVMnetClientPath, "", "Path to the socket vmnet client binary")
|
||||
startCmd.Flags().String(socketVMnetPath, "", "Path to socket vmnet binary")
|
||||
}
|
||||
|
||||
// ClusterFlagValue returns the current cluster name based on flags
|
||||
|
@ -571,8 +571,8 @@ func generateNewConfigFromFlags(cmd *cobra.Command, k8sVersion string, rtime str
|
|||
DisableOptimizations: viper.GetBool(disableOptimizations),
|
||||
DisableMetrics: viper.GetBool(disableMetrics),
|
||||
CustomQemuFirmwarePath: viper.GetString(qemuFirmwarePath),
|
||||
SocketVMnetClientPath: viper.GetString(socketVMnetClientPath),
|
||||
SocketVMnetPath: viper.GetString(socketVMnetPath),
|
||||
SocketVMnetClientPath: detect.SocketVMNetClientPath(),
|
||||
SocketVMnetPath: detect.SocketVMNetPath(),
|
||||
StaticIP: viper.GetString(staticIP),
|
||||
KubernetesConfig: config.KubernetesConfig{
|
||||
KubernetesVersion: k8sVersion,
|
||||
|
|
|
@ -38,9 +38,9 @@ import (
|
|||
"github.com/docker/machine/libmachine/ssh"
|
||||
"github.com/docker/machine/libmachine/state"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
pkgdrivers "k8s.io/minikube/pkg/drivers"
|
||||
"k8s.io/minikube/pkg/minikube/detect"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -447,8 +447,8 @@ func (d *Driver) Start() error {
|
|||
// If socket network, start with socket_vmnet.
|
||||
startProgram := d.Program
|
||||
if d.Network == "socket_vmnet" {
|
||||
startProgram = viper.GetString("socket-vmnet-client-path")
|
||||
socketVMnetPath := viper.GetString("socket-vmnet-path")
|
||||
startProgram = detect.SocketVMNetClientPath()
|
||||
socketVMnetPath := detect.SocketVMNetPath()
|
||||
startCmd = append([]string{socketVMnetPath, d.Program}, startCmd...)
|
||||
}
|
||||
|
||||
|
|
|
@ -140,12 +140,46 @@ func SocketVMNetInstalled() bool {
|
|||
if runtime.GOOS != "darwin" {
|
||||
return false
|
||||
}
|
||||
_, err := os.Stat(viper.GetString("socket-vmnet-path"))
|
||||
return SocketVMNetPath() != "" && SocketVMNetClientPath() != ""
|
||||
}
|
||||
|
||||
// SocketVMNetPath returns the path of socket_vmnet
|
||||
func SocketVMNetPath() string {
|
||||
return checkSocketVMnetInstallLocations("socket-vmnet-path", "/var/run/socket_vmnet")
|
||||
}
|
||||
|
||||
// SocketVMNetClientPath returns the path of socket_vmnet_client
|
||||
func SocketVMNetClientPath() string {
|
||||
return checkSocketVMnetInstallLocations("socket-vmnet-client-path", "/opt/socket_vmnet/bin/socket_vmnet_client")
|
||||
}
|
||||
|
||||
// checkSocketVMnetInstallLocations accepts a flag name and relative file path
|
||||
// if the flag value is non-empty, returns the flag value
|
||||
// otherwise, checks the three possible socket_vmnet install locations for the binary
|
||||
// if the binary is found it returns the full path, otherwise if returns an empty string
|
||||
func checkSocketVMnetInstallLocations(flagName, path string) string {
|
||||
p := viper.GetString(flagName)
|
||||
if p != "" {
|
||||
return p
|
||||
}
|
||||
// source install, arm64 brew install, amd64 brew install
|
||||
prefixes := []string{"", "/opt/homebrew", "/usr/local"}
|
||||
for _, prefix := range prefixes {
|
||||
fullPath := prefix + path
|
||||
if fileExists(fullPath) {
|
||||
return fullPath
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func fileExists(filePath string) bool {
|
||||
_, err := os.Stat(filePath)
|
||||
if err == nil {
|
||||
return true
|
||||
}
|
||||
if !errors.Is(err, os.ErrNotExist) {
|
||||
klog.Warningf("failed to check for socket_vmnet: %v", err)
|
||||
klog.Warningf("failed to check for existance of %s: %v", filePath, err)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue