diff --git a/cmd/podman/compose.go b/cmd/podman/compose.go index 2d023c5b65..f11f28b3c3 100644 --- a/cmd/podman/compose.go +++ b/cmd/podman/compose.go @@ -187,7 +187,7 @@ func composeDockerHost() (string, error) { if info.State != define.Running { return "", fmt.Errorf("machine %s is not running but in state %s", item.Name, info.State) } - if machineProvider.VMType() == machine.WSLVirt { + if machineProvider.VMType() == define.WSLVirt { if info.ConnectionInfo.PodmanPipe == nil { return "", errors.New("pipe of machine is not set") } diff --git a/cmd/podman/machine/init.go b/cmd/podman/machine/init.go index f1ad1073d9..7deac5c5aa 100644 --- a/cmd/podman/machine/init.go +++ b/cmd/podman/machine/init.go @@ -11,6 +11,7 @@ import ( "github.com/containers/podman/v4/cmd/podman/registry" "github.com/containers/podman/v4/libpod/events" "github.com/containers/podman/v4/pkg/machine" + "github.com/containers/podman/v4/pkg/machine/define" "github.com/spf13/cobra" ) @@ -141,7 +142,7 @@ func initMachine(cmd *cobra.Command, args []string) error { } // The vmtype names need to be reserved and cannot be used for podman machine names - if _, err := machine.ParseVMType(initOpts.Name, machine.UnknownVirt); err == nil { + if _, err := define.ParseVMType(initOpts.Name, define.UnknownVirt); err == nil { return fmt.Errorf("cannot use %q for a machine name", initOpts.Name) } diff --git a/pkg/machine/applehv/config.go b/pkg/machine/applehv/config.go index 20518cd2c5..eb11c93e3b 100644 --- a/pkg/machine/applehv/config.go +++ b/pkg/machine/applehv/config.go @@ -13,6 +13,7 @@ import ( "github.com/containers/podman/v4/pkg/machine/compression" "github.com/containers/podman/v4/pkg/machine/define" "github.com/containers/podman/v4/pkg/machine/vmconfigs" + "github.com/containers/podman/v4/pkg/machine/ignition" vfConfig "github.com/crc-org/vfkit/pkg/config" "github.com/docker/go-units" "golang.org/x/sys/unix" @@ -55,7 +56,7 @@ func (v AppleHVVirtualization) CheckExclusiveActiveVM() (bool, string, error) { } func (v AppleHVVirtualization) IsValidVMName(name string) (bool, error) { - configDir, err := machine.GetConfDir(machine.AppleHvVirt) + configDir, err := machine.GetConfDir(define.AppleHvVirt) if err != nil { return false, err } @@ -93,7 +94,7 @@ func (v AppleHVVirtualization) List(opts machine.ListOptions) ([]*machine.ListRe Running: vmState == define.Running, Starting: vmState == define.Starting, Stream: mm.ImageStream, - VMType: machine.AppleHvVirt.String(), + VMType: define.AppleHvVirt.String(), CPUs: mm.CPUs, Memory: mm.Memory * units.MiB, DiskSize: mm.DiskSize * units.GiB, @@ -118,7 +119,7 @@ func (v AppleHVVirtualization) NewMachine(opts machine.InitOptions) (machine.VM, return nil, fmt.Errorf("USB host passthrough is not supported for applehv machines") } - configDir, err := machine.GetConfDir(machine.AppleHvVirt) + configDir, err := machine.GetConfDir(define.AppleHvVirt) if err != nil { return nil, err } @@ -129,12 +130,12 @@ func (v AppleHVVirtualization) NewMachine(opts machine.InitOptions) (machine.VM, } m.ConfigPath = *configPath - dataDir, err := machine.GetDataDir(machine.AppleHvVirt) + dataDir, err := machine.GetDataDir(define.AppleHvVirt) if err != nil { return nil, err } - if err := machine.SetIgnitionFile(&m.IgnitionFile, vmtype, m.Name); err != nil { + if err := ignition.SetIgnitionFile(&m.IgnitionFile, vmtype, m.Name, configDir); err != nil { return nil, err } @@ -161,7 +162,7 @@ func (v AppleHVVirtualization) RemoveAndCleanMachines() error { return machine.ErrNotImplemented } -func (v AppleHVVirtualization) VMType() machine.VMType { +func (v AppleHVVirtualization) VMType() define.VMType { return vmtype } diff --git a/pkg/machine/applehv/machine.go b/pkg/machine/applehv/machine.go index a2285330f0..91632fa7b4 100644 --- a/pkg/machine/applehv/machine.go +++ b/pkg/machine/applehv/machine.go @@ -24,6 +24,7 @@ import ( "github.com/containers/podman/v4/pkg/machine/define" "github.com/containers/podman/v4/pkg/machine/sockets" "github.com/containers/podman/v4/pkg/machine/vmconfigs" + "github.com/containers/podman/v4/pkg/machine/ignition" "github.com/containers/podman/v4/pkg/strongunits" "github.com/containers/podman/v4/pkg/util" "github.com/containers/podman/v4/utils" @@ -36,7 +37,7 @@ import ( var ( // vmtype refers to qemu (vs libvirt, krun, etc). - vmtype = machine.AppleHvVirt + vmtype = define.AppleHvVirt ) const ( @@ -160,7 +161,7 @@ func (m *MacMachine) Init(opts machine.InitOptions) (bool, error) { go callbackFuncs.CleanOnSignal() callbackFuncs.Add(m.ConfigPath.Delete) - dataDir, err := machine.GetDataDir(machine.AppleHvVirt) + dataDir, err := machine.GetDataDir(define.AppleHvVirt) if err != nil { return false, err } @@ -254,11 +255,11 @@ func (m *MacMachine) Init(opts machine.InitOptions) (bool, error) { callbackFuncs.Add(m.removeSSHKeys) } - builder := machine.NewIgnitionBuilder(machine.DynamicIgnition{ + builder := ignition.NewIgnitionBuilder(ignition.DynamicIgnition{ Name: opts.Username, Key: key, VMName: m.Name, - VMType: machine.AppleHvVirt, + VMType: define.AppleHvVirt, TimeZone: opts.TimeZone, WritePath: m.IgnitionFile.GetPath(), UID: m.UID, @@ -273,10 +274,10 @@ func (m *MacMachine) Init(opts machine.InitOptions) (bool, error) { return false, err } - builder.WithUnit(machine.Unit{ - Enabled: machine.BoolToPtr(true), + builder.WithUnit(ignition.Unit{ + Enabled: ignition.BoolToPtr(true), Name: "ready.service", - Contents: machine.StrToPtr(fmt.Sprintf(appleHVReadyUnit, "vsock")), + Contents: ignition.StrToPtr(fmt.Sprintf(appleHVReadyUnit, "vsock")), }) builder.WithUnit(generateSystemDFilesForVirtiofsMounts(virtiofsMnts)...) @@ -786,7 +787,7 @@ func loadMacMachineFromJSON(fqConfigPath string) (*MacMachine, error) { } func (m *MacMachine) jsonConfigPath() (string, error) { - configDir, err := machine.GetConfDir(machine.AppleHvVirt) + configDir, err := machine.GetConfDir(define.AppleHvVirt) if err != nil { return "", err } @@ -817,7 +818,7 @@ func getVMInfos() ([]*machine.ListResponse, error) { listEntry.Name = vm.Name listEntry.Stream = vm.ImageStream - listEntry.VMType = machine.AppleHvVirt.String() + listEntry.VMType = define.AppleHvVirt.String() listEntry.CPUs = vm.CPUs listEntry.Memory = vm.Memory * units.MiB listEntry.DiskSize = vm.DiskSize * units.GiB @@ -1014,7 +1015,7 @@ func (m *MacMachine) setupAPIForwarding(cmd gvproxy.GvproxyCommand) (gvproxy.Gvp } func (m *MacMachine) dockerSock() (string, error) { - dd, err := machine.GetDataDir(machine.AppleHvVirt) + dd, err := machine.GetDataDir(define.AppleHvVirt) if err != nil { return "", err } @@ -1023,7 +1024,7 @@ func (m *MacMachine) dockerSock() (string, error) { func (m *MacMachine) forwardSocketPath() (*define.VMFile, error) { sockName := "podman.sock" - path, err := machine.GetDataDir(machine.AppleHvVirt) + path, err := machine.GetDataDir(define.AppleHvVirt) if err != nil { return nil, fmt.Errorf("Resolving data dir: %s", err.Error()) } @@ -1060,7 +1061,7 @@ func (m *MacMachine) isFirstBoot() (bool, error) { } func (m *MacMachine) getIgnitionSock() (*define.VMFile, error) { - dataDir, err := machine.GetDataDir(machine.AppleHvVirt) + dataDir, err := machine.GetDataDir(define.AppleHvVirt) if err != nil { return nil, err } @@ -1087,7 +1088,7 @@ func (m *MacMachine) getRuntimeDir() (string, error) { } func (m *MacMachine) userGlobalSocketLink() (string, error) { - path, err := machine.GetDataDir(machine.AppleHvVirt) + path, err := machine.GetDataDir(define.AppleHvVirt) if err != nil { logrus.Errorf("Resolving data dir: %s", err.Error()) return "", err @@ -1100,12 +1101,12 @@ func (m *MacMachine) isIncompatible() bool { return m.UID == -1 } -func generateSystemDFilesForVirtiofsMounts(mounts []machine.VirtIoFs) []machine.Unit { +func generateSystemDFilesForVirtiofsMounts(mounts []machine.VirtIoFs) []ignition.Unit { // mounting in fcos with virtiofs is a bit of a dance. we need a unit file for the mount, a unit file // for automatic mounting on boot, and a "preparatory" service file that disables FCOS security, performs // the mkdir of the mount point, and then re-enables security. This must be done for each mount. - var unitFiles []machine.Unit + var unitFiles []ignition.Unit for _, mnt := range mounts { // Here we are looping the mounts and for each mount, we are adding two unit files // for virtiofs. One unit file is the mount itself and the second is to automount it @@ -1126,20 +1127,20 @@ Type=virtiofs [Install] WantedBy=multi-user.target ` - virtiofsAutomount := machine.Unit{ - Enabled: machine.BoolToPtr(true), + virtiofsAutomount := ignition.Unit{ + Enabled: ignition.BoolToPtr(true), Name: fmt.Sprintf("%s.automount", mnt.Tag), - Contents: machine.StrToPtr(fmt.Sprintf(autoMountUnit, mnt.Target, mnt.Target)), + Contents: ignition.StrToPtr(fmt.Sprintf(autoMountUnit, mnt.Target, mnt.Target)), } - virtiofsMount := machine.Unit{ - Enabled: machine.BoolToPtr(true), + virtiofsMount := ignition.Unit{ + Enabled: ignition.BoolToPtr(true), Name: fmt.Sprintf("%s.mount", mnt.Tag), - Contents: machine.StrToPtr(fmt.Sprintf(mountUnit, mnt.Tag, mnt.Target)), + Contents: ignition.StrToPtr(fmt.Sprintf(mountUnit, mnt.Tag, mnt.Target)), } // This "unit" simulates something like systemctl enable virtiofs-mount-prepare@ - enablePrep := machine.Unit{ - Enabled: machine.BoolToPtr(true), + enablePrep := ignition.Unit{ + Enabled: ignition.BoolToPtr(true), Name: fmt.Sprintf("virtiofs-mount-prepare@%s.service", mnt.Tag), } @@ -1163,8 +1164,8 @@ ExecStopPost=chattr +i / [Install] WantedBy=remote-fs.target ` - virtioFSChattr := machine.Unit{ - Contents: machine.StrToPtr(mountPrep), + virtioFSChattr := ignition.Unit{ + Contents: ignition.StrToPtr(mountPrep), Name: "virtiofs-mount-prepare@.service", } unitFiles = append(unitFiles, virtioFSChattr) diff --git a/pkg/machine/config.go b/pkg/machine/config.go index 5d8b7402c7..57491ab94f 100644 --- a/pkg/machine/config.go +++ b/pkg/machine/config.go @@ -14,7 +14,6 @@ import ( "strings" "time" - "github.com/containers/common/pkg/machine" "github.com/containers/podman/v4/pkg/machine/compression" "github.com/containers/podman/v4/pkg/machine/define" "github.com/containers/podman/v4/pkg/machine/vmconfigs" @@ -51,9 +50,8 @@ const ( type RemoteConnectionType string var ( - SSHRemoteConnection RemoteConnectionType = "ssh" - DefaultIgnitionUserName = "core" - ForwarderBinaryName = "gvproxy" + SSHRemoteConnection RemoteConnectionType = "ssh" + ForwarderBinaryName = "gvproxy" ) type Download struct { @@ -69,7 +67,7 @@ type Download struct { Sha256sum string Size int64 URL *url.URL - VMKind VMType + VMKind define.VMType VMName string } @@ -133,7 +131,7 @@ type VM interface { Stop(name string, opts StopOptions) error } -func GetLock(name string, vmtype VMType) (*lockfile.LockFile, error) { +func GetLock(name string, vmtype define.VMType) (*lockfile.LockFile, error) { // FIXME: there's a painful amount of `GetConfDir` calls scattered // across the code base. This should be done once and stored // somewhere instead. @@ -191,7 +189,7 @@ func (rc RemoteConnectionType) MakeSSHURL(host, path, port, userName string) url } // GetCacheDir returns the dir where VM images are downloaded into when pulled -func GetCacheDir(vmType VMType) (string, error) { +func GetCacheDir(vmType define.VMType) (string, error) { dataDir, err := GetDataDir(vmType) if err != nil { return "", err @@ -205,7 +203,7 @@ func GetCacheDir(vmType VMType) (string, error) { // GetDataDir returns the filepath where vm images should // live for podman-machine. -func GetDataDir(vmType VMType) (string, error) { +func GetDataDir(vmType define.VMType) (string, error) { dataDirPrefix, err := DataDirPrefix() if err != nil { return "", err @@ -241,7 +239,7 @@ func DataDirPrefix() (string, error) { // GetConfigDir returns the filepath to where configuration // files for podman-machine should live -func GetConfDir(vmType VMType) (string, error) { +func GetConfDir(vmType define.VMType) (string, error) { confDirPrefix, err := ConfDirPrefix() if err != nil { return "", err @@ -283,28 +281,6 @@ type ConnectionConfig struct { PodmanPipe *define.VMFile `json:"PodmanPipe"` } -type VMType int64 - -const ( - QemuVirt VMType = iota - WSLVirt - AppleHvVirt - HyperVVirt - UnknownVirt -) - -func (v VMType) String() string { - switch v { - case WSLVirt: - return machine.Wsl - case AppleHvVirt: - return machine.AppleHV - case HyperVVirt: - return machine.HyperV - } - return machine.Qemu -} - type APIForwardingState int const ( @@ -315,23 +291,6 @@ const ( DockerGlobal ) -func ParseVMType(input string, emptyFallback VMType) (VMType, error) { - switch strings.TrimSpace(strings.ToLower(input)) { - case "qemu": - return QemuVirt, nil - case "wsl": - return WSLVirt, nil - case "applehv": - return AppleHvVirt, nil - case "hyperv": - return HyperVVirt, nil - case "": - return emptyFallback, nil - default: - return UnknownVirt, fmt.Errorf("unknown VMType `%s`", input) - } -} - type VirtProvider interface { //nolint:interfacebloat Artifact() define.Artifact CheckExclusiveActiveVM() (bool, string, error) @@ -343,14 +302,14 @@ type VirtProvider interface { //nolint:interfacebloat NewMachine(opts InitOptions) (VM, error) NewDownload(vmName string) (Download, error) RemoveAndCleanMachines() error - VMType() VMType + VMType() define.VMType } type Virtualization struct { artifact define.Artifact compression compression.ImageCompression format define.ImageFormat - vmKind VMType + vmKind define.VMType } func (p *Virtualization) Artifact() define.Artifact { @@ -365,7 +324,7 @@ func (p *Virtualization) Format() define.ImageFormat { return p.format } -func (p *Virtualization) VMType() VMType { +func (p *Virtualization) VMType() define.VMType { return p.vmKind } @@ -391,7 +350,7 @@ func (p *Virtualization) NewDownload(vmName string) (Download, error) { }, nil } -func NewVirtualization(artifact define.Artifact, compression compression.ImageCompression, format define.ImageFormat, vmKind VMType) Virtualization { +func NewVirtualization(artifact define.Artifact, compression compression.ImageCompression, format define.ImageFormat, vmKind define.VMType) Virtualization { return Virtualization{ artifact, compression, diff --git a/pkg/machine/define/vmtype.go b/pkg/machine/define/vmtype.go new file mode 100644 index 0000000000..fccb709fac --- /dev/null +++ b/pkg/machine/define/vmtype.go @@ -0,0 +1,54 @@ +package define + +import ( + "fmt" + "strings" +) + +type VMType int64 + +const ( + QemuVirt VMType = iota + WSLVirt + AppleHvVirt + HyperVVirt + UnknownVirt +) + +// these constants are not exported due to a conflict with the constants defined +// in define/machine_artifact.go +const ( + wsl = "wsl" + qemu = "qemu" + appleHV = "applehv" + hyperV = "hyperv" +) + +func (v VMType) String() string { + switch v { + case WSLVirt: + return wsl + case AppleHvVirt: + return appleHV + case HyperVVirt: + return hyperV + } + return qemu +} + +func ParseVMType(input string, emptyFallback VMType) (VMType, error) { + switch strings.TrimSpace(strings.ToLower(input)) { + case qemu: + return QemuVirt, nil + case wsl: + return WSLVirt, nil + case appleHV: + return AppleHvVirt, nil + case hyperV: + return HyperVVirt, nil + case "": + return emptyFallback, nil + default: + return UnknownVirt, fmt.Errorf("unknown VMType `%s`", input) + } +} diff --git a/pkg/machine/define/vmtype_test.go b/pkg/machine/define/vmtype_test.go new file mode 100644 index 0000000000..77dfd904e9 --- /dev/null +++ b/pkg/machine/define/vmtype_test.go @@ -0,0 +1,58 @@ +//go:build (amd64 && !windows) || (arm64 && !windows) +// +build amd64,!windows arm64,!windows + +package define + +import "testing" + +func TestParseVMType(t *testing.T) { + type fields struct { + input string + fallback VMType + } + + tests := []struct { + name string + fields fields + want VMType + }{ + { + name: "Qemu input", + fields: fields{"qemu", QemuVirt}, + want: QemuVirt, + }, + { + name: "Applehv input", + fields: fields{"applehv", QemuVirt}, + want: AppleHvVirt, + }, + { + name: "Hyperv input", + fields: fields{"hyperv", QemuVirt}, + want: HyperVVirt, + }, + { + name: "WSL input", + fields: fields{"wsl", QemuVirt}, + want: WSLVirt, + }, + { + name: "Qemu empty fallback", + fields: fields{"", QemuVirt}, + want: QemuVirt, + }, + { + name: "Invalid input", + fields: fields{"riscv", AppleHvVirt}, + want: UnknownVirt, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got, _ := ParseVMType(tt.fields.input, tt.fields.fallback); got != tt.want { + t.Errorf("ParseVMType(%s, %v) = %v, want %v", tt.fields.input, tt.fields.fallback, got, tt.want) + } + }) + } +} diff --git a/pkg/machine/e2e/config_test.go b/pkg/machine/e2e/config_test.go index 10efea74d5..18b961a0d5 100644 --- a/pkg/machine/e2e/config_test.go +++ b/pkg/machine/e2e/config_test.go @@ -11,6 +11,7 @@ import ( "time" "github.com/containers/podman/v4/pkg/machine" + "github.com/containers/podman/v4/pkg/machine/define" "github.com/containers/podman/v4/pkg/util" "github.com/containers/storage/pkg/stringid" . "github.com/onsi/ginkgo/v2" @@ -210,29 +211,29 @@ func (matcher *ValidJSONMatcher) NegatedFailureMessage(actual interface{}) (mess return format.Message(actual, "to _not_ be valid JSON") } -func skipIfVmtype(vmType machine.VMType, message string) { +func skipIfVmtype(vmType define.VMType, message string) { if isVmtype(vmType) { Skip(message) } } -func skipIfNotVmtype(vmType machine.VMType, message string) { +func skipIfNotVmtype(vmType define.VMType, message string) { if !isVmtype(vmType) { Skip(message) } } func skipIfWSL(message string) { - skipIfVmtype(machine.WSLVirt, message) + skipIfVmtype(define.WSLVirt, message) } -func isVmtype(vmType machine.VMType) bool { +func isVmtype(vmType define.VMType) bool { return testProvider.VMType() == vmType } // isWSL is a simple wrapper to determine if the testprovider is WSL func isWSL() bool { - return isVmtype(machine.WSLVirt) + return isVmtype(define.WSLVirt) } func getFCOSDownloadLocation(p machine.VirtProvider) string { diff --git a/pkg/machine/e2e/config_windows_test.go b/pkg/machine/e2e/config_windows_test.go index c47bda043f..d82a7f022d 100644 --- a/pkg/machine/e2e/config_windows_test.go +++ b/pkg/machine/e2e/config_windows_test.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/containers/podman/v4/pkg/machine" + "github.com/containers/podman/v4/pkg/machine/define" "github.com/containers/podman/v4/pkg/machine/wsl" . "github.com/onsi/ginkgo/v2" ) @@ -13,10 +14,10 @@ import ( const podmanBinary = "../../../bin/windows/podman.exe" func getDownloadLocation(p machine.VirtProvider) string { - if p.VMType() == machine.HyperVVirt { + if p.VMType() == define.HyperVVirt { return getFCOSDownloadLocation(p) } - fd, err := wsl.NewFedoraDownloader(machine.WSLVirt, "", defaultStream.String()) + fd, err := wsl.NewFedoraDownloader(define.WSLVirt, "", defaultStream.String()) if err != nil { Fail("unable to get WSL virtual image") } diff --git a/pkg/machine/e2e/init_test.go b/pkg/machine/e2e/init_test.go index 4aab924466..84f064777b 100644 --- a/pkg/machine/e2e/init_test.go +++ b/pkg/machine/e2e/init_test.go @@ -8,7 +8,6 @@ import ( "strings" "time" - "github.com/containers/podman/v4/pkg/machine" "github.com/containers/podman/v4/pkg/machine/define" "github.com/containers/podman/v4/utils" . "github.com/onsi/ginkgo/v2" @@ -80,7 +79,7 @@ var _ = Describe("podman machine init", func() { testMachine := inspectBefore[0] Expect(testMachine.Name).To(Equal(mb.names[0])) - if testProvider.VMType() != machine.WSLVirt { // WSL hardware specs are hardcoded + if testProvider.VMType() != define.WSLVirt { // WSL hardware specs are hardcoded Expect(testMachine.Resources.CPUs).To(Equal(uint64(cpus))) Expect(testMachine.Resources.Memory).To(Equal(uint64(2048))) } @@ -136,7 +135,7 @@ var _ = Describe("podman machine init", func() { Expect(inspectBefore).ToNot(BeEmpty()) testMachine := inspectBefore[0] Expect(testMachine.Name).To(Equal(mb.names[0])) - if testProvider.VMType() != machine.WSLVirt { // memory and cpus something we cannot set with WSL + if testProvider.VMType() != define.WSLVirt { // memory and cpus something we cannot set with WSL Expect(testMachine.Resources.CPUs).To(Equal(uint64(cpus))) Expect(testMachine.Resources.Memory).To(Equal(uint64(2048))) } @@ -186,7 +185,7 @@ var _ = Describe("podman machine init", func() { }) It("machine init with volume", func() { - if testProvider.VMType() == machine.HyperVVirt { + if testProvider.VMType() == define.HyperVVirt { Skip("volumes are not supported on hyperv yet") } skipIfWSL("WSL volumes are much different. This test will not pass as is") @@ -262,7 +261,7 @@ var _ = Describe("podman machine init", func() { }) It("init with user mode networking", func() { - if testProvider.VMType() != machine.WSLVirt { + if testProvider.VMType() != define.WSLVirt { Skip("test is only supported by WSL") } i := new(initMachine) @@ -327,7 +326,7 @@ var _ = Describe("podman machine init", func() { Expect(err).To(HaveOccurred()) // WSL does not use ignition - if testProvider.VMType() != machine.WSLVirt { + if testProvider.VMType() != define.WSLVirt { _, err = os.Stat(ign) Expect(err).To(HaveOccurred()) } diff --git a/pkg/machine/e2e/inspect_test.go b/pkg/machine/e2e/inspect_test.go index 9645b42efb..6a60089acc 100644 --- a/pkg/machine/e2e/inspect_test.go +++ b/pkg/machine/e2e/inspect_test.go @@ -2,6 +2,7 @@ package e2e_test import ( "github.com/containers/podman/v4/pkg/machine" + "github.com/containers/podman/v4/pkg/machine/define" jsoniter "github.com/json-iterator/go" . "github.com/onsi/ginkgo/v2" @@ -66,7 +67,7 @@ var _ = Describe("podman inspect stop", func() { err = jsoniter.Unmarshal(inspectSession.Bytes(), &inspectInfo) Expect(err).ToNot(HaveOccurred()) switch testProvider.VMType() { - case machine.WSLVirt: + case define.WSLVirt: Expect(inspectInfo[0].ConnectionInfo.PodmanPipe.GetPath()).To(ContainSubstring("podman-")) default: Expect(inspectInfo[0].ConnectionInfo.PodmanSocket.GetPath()).To(HaveSuffix("podman.sock")) diff --git a/pkg/machine/e2e/proxy_test.go b/pkg/machine/e2e/proxy_test.go index 020fad5b0b..24e65e5e2d 100644 --- a/pkg/machine/e2e/proxy_test.go +++ b/pkg/machine/e2e/proxy_test.go @@ -3,7 +3,7 @@ package e2e_test import ( "os" - "github.com/containers/podman/v4/pkg/machine" + "github.com/containers/podman/v4/pkg/machine/define" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" . "github.com/onsi/gomega/gexec" @@ -24,7 +24,7 @@ var _ = Describe("podman machine proxy settings propagation", func() { It("ssh to running machine and check proxy settings", func() { // https://github.com/containers/podman/issues/20129 - if testProvider.VMType() == machine.HyperVVirt { + if testProvider.VMType() == define.HyperVVirt { Skip("proxy settings not yet supported") } name := randomString() diff --git a/pkg/machine/e2e/rm_test.go b/pkg/machine/e2e/rm_test.go index 35f3f8cc2c..a3a1ab6ef0 100644 --- a/pkg/machine/e2e/rm_test.go +++ b/pkg/machine/e2e/rm_test.go @@ -4,7 +4,7 @@ import ( "fmt" "os" - "github.com/containers/podman/v4/pkg/machine" + "github.com/containers/podman/v4/pkg/machine/define" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" . "github.com/onsi/gomega/gexec" @@ -120,7 +120,7 @@ var _ = Describe("podman machine rm", func() { Expect(err).ToNot(HaveOccurred()) // WSL does not use ignition - if testProvider.VMType() != machine.WSLVirt { + if testProvider.VMType() != define.WSLVirt { _, err = os.Stat(ign) Expect(err).ToNot(HaveOccurred()) } diff --git a/pkg/machine/e2e/set_test.go b/pkg/machine/e2e/set_test.go index a7f7602d77..5cc574fd44 100644 --- a/pkg/machine/e2e/set_test.go +++ b/pkg/machine/e2e/set_test.go @@ -6,7 +6,7 @@ import ( "strconv" "strings" - "github.com/containers/podman/v4/pkg/machine" + "github.com/containers/podman/v4/pkg/machine/define" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" . "github.com/onsi/gomega/gexec" @@ -76,7 +76,7 @@ var _ = Describe("podman machine set", func() { }) It("wsl cannot change disk, memory, processor", func() { - skipIfNotVmtype(machine.WSLVirt, "tests are only for WSL provider") + skipIfNotVmtype(define.WSLVirt, "tests are only for WSL provider") name := randomString() i := new(initMachine) session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run() @@ -168,7 +168,7 @@ var _ = Describe("podman machine set", func() { }) It("set user mode networking", func() { - if testProvider.VMType() != machine.WSLVirt { + if testProvider.VMType() != define.WSLVirt { Skip("Test is only for WSL") } name := randomString() diff --git a/pkg/machine/e2e/ssh_test.go b/pkg/machine/e2e/ssh_test.go index 5fedfea0f7..f36ceeb42a 100644 --- a/pkg/machine/e2e/ssh_test.go +++ b/pkg/machine/e2e/ssh_test.go @@ -1,7 +1,7 @@ package e2e_test import ( - "github.com/containers/podman/v4/pkg/machine" + "github.com/containers/podman/v4/pkg/machine/define" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" . "github.com/onsi/gomega/gexec" @@ -44,7 +44,7 @@ var _ = Describe("podman machine ssh", func() { }) It("ssh to running machine and check os-type", func() { - wsl := testProvider.VMType() == machine.WSLVirt + wsl := testProvider.VMType() == define.WSLVirt name := randomString() i := new(initMachine) session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath).withNow()).run() diff --git a/pkg/machine/hyperv/config.go b/pkg/machine/hyperv/config.go index fbc3abd7ab..fe09d46ca5 100644 --- a/pkg/machine/hyperv/config.go +++ b/pkg/machine/hyperv/config.go @@ -15,6 +15,7 @@ import ( "github.com/containers/podman/v4/pkg/machine" "github.com/containers/podman/v4/pkg/machine/compression" "github.com/containers/podman/v4/pkg/machine/define" + "github.com/containers/podman/v4/pkg/machine/ignition" "github.com/docker/go-units" "github.com/sirupsen/logrus" ) @@ -97,7 +98,7 @@ func (v HyperVVirtualization) List(opts machine.ListOptions) ([]*machine.ListRes Running: vm.State() == hypervctl.Enabled, Starting: mm.isStarting(), Stream: mm.ImageStream, - VMType: machine.HyperVVirt.String(), + VMType: define.HyperVVirt.String(), CPUs: mm.CPUs, Memory: mm.Memory * units.MiB, DiskSize: mm.DiskSize * units.GiB, @@ -126,7 +127,7 @@ func (v HyperVVirtualization) NewMachine(opts machine.InitOptions) (machine.VM, m.RemoteUsername = opts.Username - configDir, err := machine.GetConfDir(machine.HyperVVirt) + configDir, err := machine.GetConfDir(define.HyperVVirt) if err != nil { return nil, err } @@ -138,14 +139,14 @@ func (v HyperVVirtualization) NewMachine(opts machine.InitOptions) (machine.VM, m.ConfigPath = *configPath - if err := machine.SetIgnitionFile(&m.IgnitionFile, vmtype, m.Name); err != nil { + if err := ignition.SetIgnitionFile(&m.IgnitionFile, vmtype, m.Name, configDir); err != nil { return nil, err } // Set creation time m.Created = time.Now() - dataDir, err := machine.GetDataDir(machine.HyperVVirt) + dataDir, err := machine.GetDataDir(define.HyperVVirt) if err != nil { return nil, err } @@ -250,7 +251,7 @@ func (v HyperVVirtualization) RemoveAndCleanMachines() error { return prevErr } -func (v HyperVVirtualization) VMType() machine.VMType { +func (v HyperVVirtualization) VMType() define.VMType { return vmtype } diff --git a/pkg/machine/hyperv/machine.go b/pkg/machine/hyperv/machine.go index aa8983bcc4..f78b1fb894 100644 --- a/pkg/machine/hyperv/machine.go +++ b/pkg/machine/hyperv/machine.go @@ -22,6 +22,7 @@ import ( "github.com/containers/podman/v4/pkg/machine/define" "github.com/containers/podman/v4/pkg/machine/hyperv/vsock" "github.com/containers/podman/v4/pkg/machine/vmconfigs" + "github.com/containers/podman/v4/pkg/machine/ignition" "github.com/containers/podman/v4/pkg/strongunits" "github.com/containers/podman/v4/pkg/util" "github.com/containers/podman/v4/utils" @@ -32,7 +33,7 @@ import ( var ( // vmtype refers to qemu (vs libvirt, krun, etc). - vmtype = machine.HyperVVirt + vmtype = define.HyperVVirt ) const ( @@ -251,11 +252,11 @@ func (m *HyperVMachine) Init(opts machine.InitOptions) (bool, error) { } m.Rootful = opts.Rootful - builder := machine.NewIgnitionBuilder(machine.DynamicIgnition{ + builder := ignition.NewIgnitionBuilder(ignition.DynamicIgnition{ Name: m.RemoteUsername, Key: key, VMName: m.Name, - VMType: machine.HyperVVirt, + VMType: define.HyperVVirt, TimeZone: opts.TimeZone, WritePath: m.IgnitionFile.GetPath(), UID: m.UID, @@ -277,28 +278,28 @@ func (m *HyperVMachine) Init(opts machine.InitOptions) (bool, error) { return false, err } - builder.WithUnit(machine.Unit{ - Enabled: machine.BoolToPtr(true), + builder.WithUnit(ignition.Unit{ + Enabled: ignition.BoolToPtr(true), Name: "ready.service", - Contents: machine.StrToPtr(fmt.Sprintf(hyperVReadyUnit, m.ReadyHVSock.Port)), + Contents: ignition.StrToPtr(fmt.Sprintf(hyperVReadyUnit, m.ReadyHVSock.Port)), }) - builder.WithUnit(machine.Unit{ - Contents: machine.StrToPtr(fmt.Sprintf(hyperVVsockNetUnit, m.NetworkHVSock.Port)), - Enabled: machine.BoolToPtr(true), + builder.WithUnit(ignition.Unit{ + Contents: ignition.StrToPtr(fmt.Sprintf(hyperVVsockNetUnit, m.NetworkHVSock.Port)), + Enabled: ignition.BoolToPtr(true), Name: "vsock-network.service", }) - builder.WithFile(machine.File{ - Node: machine.Node{ + builder.WithFile(ignition.File{ + Node: ignition.Node{ Path: "/etc/NetworkManager/system-connections/vsock0.nmconnection", }, - FileEmbedded1: machine.FileEmbedded1{ + FileEmbedded1: ignition.FileEmbedded1{ Append: nil, - Contents: machine.Resource{ - Source: machine.EncodeDataURLPtr(hyperVVsockNMConnection), + Contents: ignition.Resource{ + Source: ignition.EncodeDataURLPtr(hyperVVsockNMConnection), }, - Mode: machine.IntToPtr(0600), + Mode: ignition.IntToPtr(0600), }, }) @@ -679,7 +680,7 @@ func (m *HyperVMachine) Stop(name string, opts machine.StopOptions) error { } func (m *HyperVMachine) jsonConfigPath() (string, error) { - configDir, err := machine.GetConfDir(machine.HyperVVirt) + configDir, err := machine.GetConfDir(define.HyperVVirt) if err != nil { return "", err } @@ -836,7 +837,7 @@ func (m *HyperVMachine) startHostNetworking() (int32, string, machine.APIForward } func logCommandToFile(c *exec.Cmd, filename string) error { - dir, err := machine.GetDataDir(machine.HyperVVirt) + dir, err := machine.GetDataDir(define.HyperVVirt) if err != nil { return fmt.Errorf("obtain machine dir: %w", err) } @@ -877,7 +878,7 @@ func (m *HyperVMachine) setupAPIForwarding(cmd gvproxy.GvproxyCommand) (gvproxy. } func (m *HyperVMachine) dockerSock() (string, error) { - dd, err := machine.GetDataDir(machine.HyperVVirt) + dd, err := machine.GetDataDir(define.HyperVVirt) if err != nil { return "", err } @@ -886,7 +887,7 @@ func (m *HyperVMachine) dockerSock() (string, error) { func (m *HyperVMachine) forwardSocketPath() (*define.VMFile, error) { sockName := "podman.sock" - path, err := machine.GetDataDir(machine.HyperVVirt) + path, err := machine.GetDataDir(define.HyperVVirt) if err != nil { return nil, fmt.Errorf("Resolving data dir: %s", err.Error()) } diff --git a/pkg/machine/ignition.go b/pkg/machine/ignition/ignition.go similarity index 98% rename from pkg/machine/ignition.go rename to pkg/machine/ignition/ignition.go index e52554a0d9..73bb830e3c 100644 --- a/pkg/machine/ignition.go +++ b/pkg/machine/ignition/ignition.go @@ -1,6 +1,6 @@ //go:build amd64 || arm64 -package machine +package ignition import ( "encoding/json" @@ -25,6 +25,7 @@ import ( const ( PodmanDockerTmpConfPath = "/etc/tmpfiles.d/podman-docker.conf" + DefaultIgnitionUserName = "core" ) // Convenience function to convert int to ptr @@ -56,7 +57,7 @@ type DynamicIgnition struct { TimeZone string UID int VMName string - VMType VMType + VMType define.VMType WritePath string Cfg Config Rootful bool @@ -215,7 +216,7 @@ WantedBy=sysinit.target }} // Only qemu has the qemu firmware environment setting - if ign.VMType == QemuVirt { + if ign.VMType == define.QemuVirt { qemuUnit := Unit{ Enabled: BoolToPtr(true), Name: "envset-fwcfg.service", @@ -295,7 +296,7 @@ func getDirs(usrName string) []Directory { return dirs } -func getFiles(usrName string, uid int, rootful bool, vmtype VMType) []File { +func getFiles(usrName string, uid int, rootful bool, vmtype define.VMType) []File { files := make([]File, 0) lingerExample := `[Unit] @@ -676,12 +677,7 @@ func GetPodmanDockerTmpConfig(uid int, rootful bool, newline bool) string { // SetIgnitionFile creates a new Machine File for the machine's ignition file // and assignes the handle to `loc` -func SetIgnitionFile(loc *define.VMFile, vmtype VMType, vmName string) error { - vmConfigDir, err := GetConfDir(vmtype) - if err != nil { - return err - } - +func SetIgnitionFile(loc *define.VMFile, vmtype define.VMType, vmName, vmConfigDir string) error { ignitionFile, err := define.NewMachineFile(filepath.Join(vmConfigDir, vmName+".ign"), nil) if err != nil { return err diff --git a/pkg/machine/ignition_darwin.go b/pkg/machine/ignition/ignition_darwin.go similarity index 93% rename from pkg/machine/ignition_darwin.go rename to pkg/machine/ignition/ignition_darwin.go index bf539f7fd7..322cf5a2e0 100644 --- a/pkg/machine/ignition_darwin.go +++ b/pkg/machine/ignition/ignition_darwin.go @@ -1,6 +1,6 @@ //go:build darwin -package machine +package ignition import ( "os" diff --git a/pkg/machine/ignition_freebsd.go b/pkg/machine/ignition/ignition_freebsd.go similarity index 82% rename from pkg/machine/ignition_freebsd.go rename to pkg/machine/ignition/ignition_freebsd.go index b574bf2496..040bd763ac 100644 --- a/pkg/machine/ignition_freebsd.go +++ b/pkg/machine/ignition/ignition_freebsd.go @@ -1,6 +1,6 @@ //go:build freebsd -package machine +package ignition func getLocalTimeZone() (string, error) { return "", nil diff --git a/pkg/machine/ignition_linux.go b/pkg/machine/ignition/ignition_linux.go similarity index 96% rename from pkg/machine/ignition_linux.go rename to pkg/machine/ignition/ignition_linux.go index 9f14647d15..c6cce2a90c 100644 --- a/pkg/machine/ignition_linux.go +++ b/pkg/machine/ignition/ignition_linux.go @@ -1,4 +1,4 @@ -package machine +package ignition import ( "errors" diff --git a/pkg/machine/ignition_schema.go b/pkg/machine/ignition/ignition_schema.go similarity index 99% rename from pkg/machine/ignition_schema.go rename to pkg/machine/ignition/ignition_schema.go index f583fa34bc..deebe89a9f 100644 --- a/pkg/machine/ignition_schema.go +++ b/pkg/machine/ignition/ignition_schema.go @@ -1,6 +1,6 @@ //go:build amd64 || arm64 -package machine +package ignition /* This file was taken from https://github.com/coreos/ignition/blob/master/config/v3_2/types/schema.go in an effort to diff --git a/pkg/machine/ignition_windows.go b/pkg/machine/ignition/ignition_windows.go similarity index 82% rename from pkg/machine/ignition_windows.go rename to pkg/machine/ignition/ignition_windows.go index c0ae1a2c9b..c41bf63ea4 100644 --- a/pkg/machine/ignition_windows.go +++ b/pkg/machine/ignition/ignition_windows.go @@ -1,6 +1,6 @@ //go:build windows -package machine +package ignition func getLocalTimeZone() (string, error) { return "", nil diff --git a/pkg/machine/provider/platform.go b/pkg/machine/provider/platform.go index a04a91ff3f..83d06bd0f9 100644 --- a/pkg/machine/provider/platform.go +++ b/pkg/machine/provider/platform.go @@ -8,6 +8,7 @@ import ( "github.com/containers/common/pkg/config" "github.com/containers/podman/v4/pkg/machine" + "github.com/containers/podman/v4/pkg/machine/define" "github.com/containers/podman/v4/pkg/machine/qemu" "github.com/sirupsen/logrus" ) @@ -21,14 +22,14 @@ func Get() (machine.VirtProvider, error) { if providerOverride, found := os.LookupEnv("CONTAINERS_MACHINE_PROVIDER"); found { provider = providerOverride } - resolvedVMType, err := machine.ParseVMType(provider, machine.QemuVirt) + resolvedVMType, err := define.ParseVMType(provider, define.QemuVirt) if err != nil { return nil, err } logrus.Debugf("Using Podman machine with `%s` virtualization provider", resolvedVMType.String()) switch resolvedVMType { - case machine.QemuVirt: + case define.QemuVirt: return qemu.VirtualizationProvider(), nil default: return nil, fmt.Errorf("unsupported virtualization provider: `%s`", resolvedVMType.String()) diff --git a/pkg/machine/provider/platform_darwin.go b/pkg/machine/provider/platform_darwin.go index fc515cdd3e..ffe8dc2377 100644 --- a/pkg/machine/provider/platform_darwin.go +++ b/pkg/machine/provider/platform_darwin.go @@ -7,6 +7,7 @@ import ( "github.com/containers/common/pkg/config" "github.com/containers/podman/v4/pkg/machine" "github.com/containers/podman/v4/pkg/machine/applehv" + "github.com/containers/podman/v4/pkg/machine/define" "github.com/containers/podman/v4/pkg/machine/qemu" "github.com/sirupsen/logrus" ) @@ -20,16 +21,16 @@ func Get() (machine.VirtProvider, error) { if providerOverride, found := os.LookupEnv("CONTAINERS_MACHINE_PROVIDER"); found { provider = providerOverride } - resolvedVMType, err := machine.ParseVMType(provider, machine.AppleHvVirt) + resolvedVMType, err := define.ParseVMType(provider, define.AppleHvVirt) if err != nil { return nil, err } logrus.Debugf("Using Podman machine with `%s` virtualization provider", resolvedVMType.String()) switch resolvedVMType { - case machine.QemuVirt: + case define.QemuVirt: return qemu.VirtualizationProvider(), nil - case machine.AppleHvVirt: + case define.AppleHvVirt: return applehv.VirtualizationProvider(), nil default: return nil, fmt.Errorf("unsupported virtualization provider: `%s`", resolvedVMType.String()) diff --git a/pkg/machine/provider/platform_windows.go b/pkg/machine/provider/platform_windows.go index ffa390aabd..a57f283e37 100644 --- a/pkg/machine/provider/platform_windows.go +++ b/pkg/machine/provider/platform_windows.go @@ -6,6 +6,7 @@ import ( "github.com/containers/common/pkg/config" "github.com/containers/podman/v4/pkg/machine" + "github.com/containers/podman/v4/pkg/machine/define" "github.com/containers/podman/v4/pkg/machine/hyperv" "github.com/containers/podman/v4/pkg/machine/wsl" "github.com/sirupsen/logrus" @@ -20,16 +21,16 @@ func Get() (machine.VirtProvider, error) { if providerOverride, found := os.LookupEnv("CONTAINERS_MACHINE_PROVIDER"); found { provider = providerOverride } - resolvedVMType, err := machine.ParseVMType(provider, machine.WSLVirt) + resolvedVMType, err := define.ParseVMType(provider, define.WSLVirt) if err != nil { return nil, err } logrus.Debugf("Using Podman machine with `%s` virtualization provider", resolvedVMType.String()) switch resolvedVMType { - case machine.WSLVirt: + case define.WSLVirt: return wsl.VirtualizationProvider(), nil - case machine.HyperVVirt: + case define.HyperVVirt: return hyperv.VirtualizationProvider(), nil default: return nil, fmt.Errorf("unsupported virtualization provider: `%s`", resolvedVMType.String()) diff --git a/pkg/machine/pull.go b/pkg/machine/pull.go index cd587ae6da..909425d070 100644 --- a/pkg/machine/pull.go +++ b/pkg/machine/pull.go @@ -28,7 +28,7 @@ type GenericDownload struct { } // NewGenericDownloader is used when the disk image is provided by the user -func NewGenericDownloader(vmType VMType, vmName, pullPath string) (DistributionDownload, error) { +func NewGenericDownloader(vmType define.VMType, vmName, pullPath string) (DistributionDownload, error) { var ( imageName string ) diff --git a/pkg/machine/qemu/config.go b/pkg/machine/qemu/config.go index a47b77fe2b..e15e7b0387 100644 --- a/pkg/machine/qemu/config.go +++ b/pkg/machine/qemu/config.go @@ -13,6 +13,7 @@ import ( "github.com/containers/podman/v4/pkg/machine" "github.com/containers/podman/v4/pkg/machine/compression" "github.com/containers/podman/v4/pkg/machine/define" + "github.com/containers/podman/v4/pkg/machine/ignition" "github.com/containers/podman/v4/pkg/machine/qemu/command" "github.com/containers/podman/v4/pkg/machine/sockets" "github.com/containers/podman/v4/pkg/machine/vmconfigs" @@ -84,8 +85,13 @@ func (p *QEMUVirtualization) NewMachine(opts machine.InitOptions) (machine.VM, e return nil, err } + confDir, err := machine.GetConfDir(vmtype) + if err != nil { + return nil, err + } + // set VM ignition file - if err := machine.SetIgnitionFile(&vm.IgnitionFile, vmtype, vm.Name); err != nil { + if err := ignition.SetIgnitionFile(&vm.IgnitionFile, vmtype, vm.Name, confDir); err != nil { return nil, err } @@ -330,7 +336,7 @@ func (p *QEMUVirtualization) RemoveAndCleanMachines() error { return prevErr } -func (p *QEMUVirtualization) VMType() machine.VMType { +func (p *QEMUVirtualization) VMType() define.VMType { return vmtype } diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go index 8b4f32d229..f3ee9206df 100644 --- a/pkg/machine/qemu/machine.go +++ b/pkg/machine/qemu/machine.go @@ -23,6 +23,7 @@ import ( gvproxy "github.com/containers/gvisor-tap-vsock/pkg/types" "github.com/containers/podman/v4/pkg/machine" "github.com/containers/podman/v4/pkg/machine/define" + "github.com/containers/podman/v4/pkg/machine/ignition" "github.com/containers/podman/v4/pkg/machine/qemu/command" "github.com/containers/podman/v4/pkg/machine/sockets" "github.com/containers/podman/v4/pkg/machine/vmconfigs" @@ -36,7 +37,7 @@ import ( var ( // vmtype refers to qemu (vs libvirt, krun, etc). // Could this be moved into Provider - vmtype = machine.QemuVirt + vmtype = define.QemuVirt ) const ( @@ -208,11 +209,11 @@ func (v *MachineVM) Init(opts machine.InitOptions) (bool, error) { logrus.Warn("ignoring init option to disable user-mode networking: this mode is not supported by the QEMU backend") } - builder := machine.NewIgnitionBuilder(machine.DynamicIgnition{ + builder := ignition.NewIgnitionBuilder(ignition.DynamicIgnition{ Name: opts.Username, Key: key, VMName: v.Name, - VMType: machine.QemuVirt, + VMType: define.QemuVirt, TimeZone: opts.TimeZone, WritePath: v.getIgnitionFile(), UID: v.UID, @@ -229,10 +230,10 @@ func (v *MachineVM) Init(opts machine.InitOptions) (bool, error) { return false, err } - readyUnit := machine.Unit{ - Enabled: machine.BoolToPtr(true), + readyUnit := ignition.Unit{ + Enabled: ignition.BoolToPtr(true), Name: "ready.service", - Contents: machine.StrToPtr(fmt.Sprintf(qemuReadyUnit, "vport1p1", "vport1p1")), + Contents: ignition.StrToPtr(fmt.Sprintf(qemuReadyUnit, "vport1p1", "vport1p1")), } builder.WithUnit(readyUnit) @@ -1222,7 +1223,7 @@ func (v *MachineVM) isIncompatible() bool { } func (v *MachineVM) userGlobalSocketLink() (string, error) { - path, err := machine.GetDataDir(machine.QemuVirt) + path, err := machine.GetDataDir(define.QemuVirt) if err != nil { logrus.Errorf("Resolving data dir: %s", err.Error()) return "", err @@ -1233,7 +1234,7 @@ func (v *MachineVM) userGlobalSocketLink() (string, error) { func (v *MachineVM) forwardSocketPath() (*define.VMFile, error) { sockName := "podman.sock" - path, err := machine.GetDataDir(machine.QemuVirt) + path, err := machine.GetDataDir(define.QemuVirt) if err != nil { logrus.Errorf("Resolving data dir: %s", err.Error()) return nil, err diff --git a/pkg/machine/update.go b/pkg/machine/update.go index 11c873ef2d..0f009a5e04 100644 --- a/pkg/machine/update.go +++ b/pkg/machine/update.go @@ -5,12 +5,13 @@ package machine import ( "fmt" + "github.com/containers/podman/v4/pkg/machine/ignition" "github.com/sirupsen/logrus" ) func UpdatePodmanDockerSockService(vm VM, name string, uid int, rootful bool) error { - content := GetPodmanDockerTmpConfig(uid, rootful, false) - command := fmt.Sprintf("'echo %q > %s'", content, PodmanDockerTmpConfPath) + content := ignition.GetPodmanDockerTmpConfig(uid, rootful, false) + command := fmt.Sprintf("'echo %q > %s'", content, ignition.PodmanDockerTmpConfPath) args := []string{"sudo", "bash", "-c", command} if err := vm.SSH(name, SSHOptions{Args: args}); err != nil { logrus.Warnf("Could not not update internal docker sock config") diff --git a/pkg/machine/wsl/config.go b/pkg/machine/wsl/config.go index 34fa3e7133..a522a77f52 100644 --- a/pkg/machine/wsl/config.go +++ b/pkg/machine/wsl/config.go @@ -230,6 +230,6 @@ func (p *WSLVirtualization) RemoveAndCleanMachines() error { return prevErr } -func (p *WSLVirtualization) VMType() machine.VMType { +func (p *WSLVirtualization) VMType() define.VMType { return vmtype } diff --git a/pkg/machine/wsl/fedora.go b/pkg/machine/wsl/fedora.go index 81cea04581..f1d31b6521 100644 --- a/pkg/machine/wsl/fedora.go +++ b/pkg/machine/wsl/fedora.go @@ -27,7 +27,7 @@ type FedoraDownload struct { machine.Download } -func NewFedoraDownloader(vmType machine.VMType, vmName, releaseStream string) (machine.DistributionDownload, error) { +func NewFedoraDownloader(vmType define.VMType, vmName, releaseStream string) (machine.DistributionDownload, error) { downloadURL, version, arch, size, err := getFedoraDownload() if err != nil { return nil, err diff --git a/pkg/machine/wsl/machine.go b/pkg/machine/wsl/machine.go index 2aaf0cc32c..efb5485239 100644 --- a/pkg/machine/wsl/machine.go +++ b/pkg/machine/wsl/machine.go @@ -20,6 +20,7 @@ import ( "github.com/containers/podman/v4/pkg/machine" "github.com/containers/podman/v4/pkg/machine/define" "github.com/containers/podman/v4/pkg/machine/vmconfigs" + "github.com/containers/podman/v4/pkg/machine/ignition" "github.com/containers/podman/v4/pkg/machine/wsl/wutil" "github.com/containers/podman/v4/pkg/util" "github.com/containers/podman/v4/utils" @@ -32,7 +33,7 @@ import ( var ( // vmtype refers to qemu (vs libvirt, krun, etc) - vmtype = machine.WSLVirt + vmtype = define.WSLVirt ) const ( @@ -717,9 +718,9 @@ func getBindMountFsTab(dist string) string { } func (v *MachineVM) setupPodmanDockerSock(dist string, rootful bool) error { - content := machine.GetPodmanDockerTmpConfig(1000, rootful, true) + content := ignition.GetPodmanDockerTmpConfig(1000, rootful, true) - if err := wslPipe(content, dist, "sh", "-c", "cat > "+machine.PodmanDockerTmpConfPath); err != nil { + if err := wslPipe(content, dist, "sh", "-c", "cat > "+ignition.PodmanDockerTmpConfPath); err != nil { return fmt.Errorf("could not create internal docker sock conf: %w", err) }