Skip to content

Commit

Permalink
Merge pull request #5293 from rancher-sandbox/5016-refer-to-limactl.v…
Browse files Browse the repository at this point in the history
…entura

Return .../limactl.ventura when on MacOS Ventura+.
  • Loading branch information
ericpromislow authored Aug 4, 2023
2 parents 0eb88bf + 59b8e76 commit 0d751b7
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/go/rdctl/pkg/directories/lima_home.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ package directories
import (
"fmt"
"os"
"os/exec"
"path"
"path/filepath"
"runtime"
"strconv"
"strings"
)

func SetupLimaHome() error {
Expand Down Expand Up @@ -54,6 +57,20 @@ func SetupLimaHome() error {
return nil
}

func getOSMajorVersion() (int, error) {
// syscall.Uname isn't available on macOS, so we need to shell out.
// This is only called once by `rdctl shutdown` and once by `rdctl shell` so there's no need to memoize the result
version, err := exec.Command("uname", "-r").CombinedOutput()
if err != nil {
return -1, err
}
before, _, found := strings.Cut(string(version), ".")
if !found || len(before) == 0 {
return -1, fmt.Errorf("Expected a version string, got: %s", string(version))
}
return strconv.Atoi(before)
}

func GetLimactlPath() (string, error) {
execPath, err := os.Executable()
if err != nil {
Expand All @@ -63,5 +80,13 @@ func GetLimactlPath() (string, error) {
if err != nil {
return "", err
}
if runtime.GOOS == "darwin" {
majorVersion, err := getOSMajorVersion()
if err == nil && majorVersion >= 22 {
// https://en.wikipedia.org/wiki/MacOS_version_history: maps darwin versions to macOS release version numbers and names
// macOS 13 | Ventura | 22
return path.Join(path.Dir(path.Dir(execPath)), "lima", "bin", "limactl.ventura"), nil
}
}
return path.Join(path.Dir(path.Dir(execPath)), "lima", "bin", "limactl"), nil
}

0 comments on commit 0d751b7

Please sign in to comment.