Skip to content

Commit

Permalink
Merge pull request containers#21602 from baude/ociartdisk
Browse files Browse the repository at this point in the history
Allow podman machine to download from oci registry
  • Loading branch information
openshift-merge-bot[bot] authored Feb 13, 2024
2 parents 9bf3cf6 + 2430fc7 commit c88c689
Show file tree
Hide file tree
Showing 12 changed files with 470 additions and 236 deletions.
17 changes: 13 additions & 4 deletions pkg/machine/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,21 @@ func GetMachineDirs(vmType define.VMType) (*define.MachineDirs, error) {
return nil, err
}

imageCacheDir, err := dataDirFile.AppendToNewVMFile("cache", nil)
if err != nil {
return nil, err
}

rtDirFile, err := define.NewMachineFile(rtDir, nil)
if err != nil {
return nil, err
}

dirs := define.MachineDirs{
ConfigDir: configDirFile,
DataDir: dataDirFile,
RuntimeDir: rtDirFile,
ConfigDir: configDirFile,
DataDir: dataDirFile,
ImageCacheDir: imageCacheDir,
RuntimeDir: rtDirFile,
}

// make sure all machine dirs are present
Expand All @@ -199,7 +205,10 @@ func GetMachineDirs(vmType define.VMType) (*define.MachineDirs, error) {
if err := os.MkdirAll(configDir, 0755); err != nil {
return nil, err
}
err = os.MkdirAll(dataDir, 0755)

// Because this is a mkdirall, we make the image cache dir
// which is a subdir of datadir (so the datadir is made anyway)
err = os.MkdirAll(imageCacheDir.GetPath(), 0755)

return &dirs, err
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/machine/define/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ type CreateVMOpts struct {
}

type MachineDirs struct {
ConfigDir *VMFile
DataDir *VMFile
RuntimeDir *VMFile
ConfigDir *VMFile
DataDir *VMFile
ImageCacheDir *VMFile
RuntimeDir *VMFile
}
12 changes: 12 additions & 0 deletions pkg/machine/define/vmtype.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ func (v VMType) String() string {
return qemu
}

func (v VMType) ImageFormat() ImageFormat {
switch v {
case WSLVirt:
return Tar
case AppleHvVirt:
return Raw
case HyperVVirt:
return Vhdx
}
return Qcow
}

func ParseVMType(input string, emptyFallback VMType) (VMType, error) {
switch strings.TrimSpace(strings.ToLower(input)) {
case qemu:
Expand Down
36 changes: 36 additions & 0 deletions pkg/machine/define/vmtype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,39 @@ func TestParseVMType(t *testing.T) {
})
}
}

func TestVMType_ImageFormat(t *testing.T) {
tests := []struct {
name string
v VMType
want ImageFormat
}{
{
name: "wsl",
v: WSLVirt,
want: Tar,
},
{
name: "applehv",
v: AppleHvVirt,
want: Raw,
},
{
name: "qemu",
v: QemuVirt,
want: Qcow,
},
{
name: "hyperv",
v: HyperVVirt,
want: Vhdx,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.v.ImageFormat(); got != tt.want {
t.Errorf("ImageFormat() = %v, want %v", got, tt.want)
}
})
}
}
12 changes: 0 additions & 12 deletions pkg/machine/ocipull/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ import (
"github.com/sirupsen/logrus"
)

// quay.io/libpod/podman-machine-images:4.6

const (
diskImages = "podman-machine-images"
registry = "quay.io"
repo = "libpod"
)

type OSVersion struct {
*semver.Version
}
Expand Down Expand Up @@ -71,10 +63,6 @@ func (o *OSVersion) majorMinor() string {
return fmt.Sprintf("%d.%d", o.Major, o.Minor)
}

func (o *OSVersion) diskImage(vmType string) string {
return fmt.Sprintf("%s/%s/%s:%s-%s", registry, repo, diskImages, o.majorMinor(), vmType)
}

func unpackOCIDir(ociTb, machineImageDir string) (*define.VMFile, error) {
imageFileName, err := findTarComponent(ociTb)
if err != nil {
Expand Down
Loading

0 comments on commit c88c689

Please sign in to comment.