Skip to content

Add OS to lima.yaml for future guests #1735

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

Merged
merged 1 commit into from
Aug 12, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/limactl/hostagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func newHostagentCommand() *cobra.Command {
hostagentCommand.Flags().StringP("pidfile", "p", "", "write pid to file")
hostagentCommand.Flags().String("socket", "", "hostagent socket")
hostagentCommand.Flags().Bool("run-gui", false, "run gui synchronously within hostagent")
hostagentCommand.Flags().String("nerdctl-archive", "", "local file path (not URL) of nerdctl-full-VERSION-linux-GOARCH.tar.gz")
hostagentCommand.Flags().String("nerdctl-archive", "", "local file path (not URL) of nerdctl-full-VERSION-GOOS-GOARCH.tar.gz")
return hostagentCommand
}

Expand Down
2 changes: 1 addition & 1 deletion docs/internal.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ The directory contains the following files:
- `network-config`: [Cloud-init Networking Config Version 2](https://cloudinit.readthedocs.io/en/latest/topics/network-config-format-v2.html)
- `lima.env`: The `LIMA_CIDATA_*` environment variables (see below) available during `boot.sh` processing
- `lima-guestagent`: Lima guest agent binary
- `nerdctl-full.tgz`: [`nerdctl-full-<VERSION>-linux-<ARCH>.tar.gz`](https://github.com/containerd/nerdctl/releases)
- `nerdctl-full.tgz`: [`nerdctl-full-<VERSION>-<OS>-<ARCH>.tar.gz`](https://github.com/containerd/nerdctl/releases)
- `boot.sh`: Boot script
- `boot/*`: Boot script modules
- `util/*`: Utility command scripts, executed in the boot script modules
Expand Down
4 changes: 4 additions & 0 deletions examples/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
# 🟢 Builtin default: "qemu"
vmType: null

# OS: "Linux".
# 🟢 Builtin default: "Linux"
os: null

# Arch: "default", "x86_64", "aarch64".
# 🟢 Builtin default: "default" (corresponds to the host architecture)
arch: null
Expand Down
9 changes: 6 additions & 3 deletions pkg/cidata/cidata.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort
}
}

guestAgentBinary, err := GuestAgentBinary(*y.Arch)
guestAgentBinary, err := GuestAgentBinary(*y.OS, *y.Arch)
if err != nil {
return err
}
Expand All @@ -329,15 +329,18 @@ func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort
return iso9660util.Write(filepath.Join(instDir, filenames.CIDataISO), "cidata", layout)
}

func GuestAgentBinary(arch string) (io.ReadCloser, error) {
func GuestAgentBinary(ostype limayaml.OS, arch limayaml.Arch) (io.ReadCloser, error) {
if ostype == "" {
return nil, errors.New("os must be set")
}
if arch == "" {
return nil, errors.New("arch must be set")
}
dir, err := usrlocalsharelima.Dir()
if err != nil {
return nil, err
}
gaPath := filepath.Join(dir, "lima-guestagent.Linux-"+arch)
gaPath := filepath.Join(dir, "lima-guestagent."+ostype+"-"+arch)
return os.Open(gaPath)
}

Expand Down
32 changes: 28 additions & 4 deletions pkg/limayaml/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ const (

func defaultContainerdArchives() []File {
const nerdctlVersion = "1.5.0"
location := func(goarch string) string {
return "https://github.com/containerd/nerdctl/releases/download/v" + nerdctlVersion + "/nerdctl-full-" + nerdctlVersion + "-linux-" + goarch + ".tar.gz"
location := func(goos string, goarch string) string {
return "https://github.com/containerd/nerdctl/releases/download/v" + nerdctlVersion + "/nerdctl-full-" + nerdctlVersion + "-" + goos + "-" + goarch + ".tar.gz"
}
return []File{
{
Location: location("amd64"),
Location: location("linux", "amd64"),
Arch: X8664,
Digest: "sha256:3f8c494e3c6a265fe2a3c41ef9d6bc859eeeb22095b3353d3558d8120833a23a",
},
{
Location: location("arm64"),
Location: location("linux", "arm64"),
Arch: AARCH64,
Digest: "sha256:32a2537e0a80e1493b5934ca56c3e237466606a1b720aef23b9c0a7fc3303bdb",
},
Expand Down Expand Up @@ -134,6 +134,13 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
y.VMType = o.VMType
}
y.VMType = pointer.String(ResolveVMType(y.VMType))
if y.OS == nil {
y.OS = d.OS
}
if o.OS != nil {
y.OS = o.OS
}
y.OS = pointer.String(ResolveOS(y.OS))
if y.Arch == nil {
y.Arch = d.Arch
}
Expand Down Expand Up @@ -768,6 +775,16 @@ func FillCopyToHostDefaults(rule *CopyToHost, instDir string) {
}
}

func NewOS(osname string) OS {
switch osname {
case "linux":
return LINUX
default:
logrus.Warnf("Unknown os: %s", osname)
return osname
}
}

func goarm() int {
if runtime.GOOS != "linux" {
return 0
Expand Down Expand Up @@ -824,6 +841,13 @@ func ResolveVMType(s *string) VMType {
return NewVMType(*s)
}

func ResolveOS(s *string) OS {
if s == nil || *s == "" || *s == "default" {
return NewOS("linux")
}
return *s
}

func ResolveArch(s *string) Arch {
if s == nil || *s == "" || *s == "default" {
return NewArch(runtime.GOARCH)
Expand Down
3 changes: 3 additions & 0 deletions pkg/limayaml/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func TestFillDefault(t *testing.T) {
// Builtin default values
builtin := LimaYAML{
VMType: pointer.String("qemu"),
OS: pointer.String(LINUX),
Arch: pointer.String(arch),
CPUType: map[Arch]string{
AARCH64: "cortex-a72",
Expand Down Expand Up @@ -266,6 +267,7 @@ func TestFillDefault(t *testing.T) {
// Choose values that are different from the "builtin" defaults
d = LimaYAML{
VMType: pointer.String("vz"),
OS: pointer.String("unknown"),
Arch: pointer.String("unknown"),
CPUType: map[Arch]string{
AARCH64: "arm64",
Expand Down Expand Up @@ -443,6 +445,7 @@ func TestFillDefault(t *testing.T) {

o = LimaYAML{
VMType: pointer.String("qemu"),
OS: pointer.String(LINUX),
Arch: pointer.String(arch),
CPUType: map[Arch]string{
AARCH64: "uber-arm",
Expand Down
4 changes: 4 additions & 0 deletions pkg/limayaml/limayaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

type LimaYAML struct {
VMType *VMType `yaml:"vmType,omitempty" json:"vmType,omitempty"`
OS *OS `yaml:"os,omitempty" json:"os,omitempty"`
Arch *Arch `yaml:"arch,omitempty" json:"arch,omitempty"`
Images []Image `yaml:"images" json:"images"` // REQUIRED
CPUType map[Arch]string `yaml:"cpuType,omitempty" json:"cpuType,omitempty"`
Expand Down Expand Up @@ -39,11 +40,14 @@ type LimaYAML struct {
Rosetta Rosetta `yaml:"rosetta,omitempty" json:"rosetta,omitempty"`
}

type OS = string
type Arch = string
type MountType = string
type VMType = string

const (
LINUX OS = "Linux"

X8664 Arch = "x86_64"
AARCH64 Arch = "aarch64"
ARMV7L Arch = "armv7l"
Expand Down
5 changes: 5 additions & 0 deletions pkg/limayaml/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ func validateFileObject(f File, fieldName string) error {
}

func Validate(y LimaYAML, warn bool) error {
switch *y.OS {
case LINUX:
default:
return fmt.Errorf("field `os` must be %q; got %q", LINUX, *y.OS)
}
switch *y.Arch {
case X8664, AARCH64, ARMV7L, RISCV64:
default:
Expand Down
2 changes: 1 addition & 1 deletion pkg/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
// to be running before timing out.
const DefaultWatchHostAgentEventsTimeout = 10 * time.Minute

// ensureNerdctlArchiveCache prefetches the nerdctl-full-VERSION-linux-GOARCH.tar.gz archive
// ensureNerdctlArchiveCache prefetches the nerdctl-full-VERSION-GOOS-GOARCH.tar.gz archive
// into the cache before launching the hostagent process, so that we can show the progress in tty.
// https://github.com/lima-vm/lima/issues/326
func ensureNerdctlArchiveCache(y *limayaml.LimaYAML) (string, error) {
Expand Down
9 changes: 5 additions & 4 deletions pkg/usrlocalsharelima/usrlocalsharelima.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func Dir() (string, error) {
}
}

ostype := limayaml.NewOS("linux")
arch := limayaml.NewArch(runtime.GOARCH)
if arch == "" {
return "", fmt.Errorf("failed to get arch for %q", runtime.GOARCH)
Expand All @@ -40,12 +41,12 @@ func Dir() (string, error) {
// - self: /Applications/Lima.app/Contents/MacOS/limactl
// - agent: /Applications/Lima.app/Contents/MacOS/lima-guestagent.Linux-x86_64
// - dir: /Applications/Lima.app/Contents/MacOS
filepath.Join(selfDir, "lima-guestagent.Linux-"+arch),
filepath.Join(selfDir, "lima-guestagent."+ostype+"-"+arch),
// candidate 1:
// - self: /usr/local/bin/limactl
// - agent: /usr/local/share/lima/lima-guestagent.Linux-x86_64
// - dir: /usr/local/share/lima
filepath.Join(selfDirDir, "share/lima/lima-guestagent.Linux-"+arch),
filepath.Join(selfDirDir, "share/lima/lima-guestagent."+ostype+"-"+arch),
// TODO: support custom path
}
for _, gaCandidate := range gaCandidates {
Expand All @@ -56,6 +57,6 @@ func Dir() (string, error) {
}
}

return "", fmt.Errorf("failed to find \"lima-guestagent.Linux-%s\" binary for %q, attempted %v",
arch, self, gaCandidates)
return "", fmt.Errorf("failed to find \"lima-guestagent.%s-%s\" binary for %q, attempted %v",
ostype, arch, self, gaCandidates)
}