Skip to content

Commit

Permalink
Merge pull request containers#21604 from baude/springclean
Browse files Browse the repository at this point in the history
Minor cleanup from podman 4
  • Loading branch information
openshift-merge-bot[bot] authored Feb 12, 2024
2 parents 7c7b443 + e74d268 commit 6d107a2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 118 deletions.
103 changes: 4 additions & 99 deletions pkg/machine/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,17 @@ package machine
import (
"context"
"errors"
"fmt"
"net"
"net/http"
"net/url"
"os"
"path/filepath"
"strings"
"time"

"github.com/containers/podman/v5/pkg/machine/compression"
"github.com/containers/podman/v5/pkg/machine/define"
"github.com/containers/podman/v5/pkg/machine/vmconfigs"
"github.com/containers/storage/pkg/homedir"
"github.com/containers/storage/pkg/lockfile"
"github.com/sirupsen/logrus"
)

Expand All @@ -28,8 +25,7 @@ const (
)

var (
DefaultIgnitionUserName = "core"
ForwarderBinaryName = "gvproxy"
ForwarderBinaryName = "gvproxy"
)

type Download struct {
Expand Down Expand Up @@ -88,6 +84,7 @@ type RemoveOptions struct {

type InspectOptions struct{}

// TODO This can be removed when WSL is refactored into podman 5
type VM interface {
Init(opts define.InitOptions) (bool, error)
Inspect() (*InspectInfo, error)
Expand Down Expand Up @@ -146,7 +143,7 @@ func GetDataDir(vmType define.VMType) (string, error) {
return dataDir, mkdirErr
}

// GetGLobalDataDir returns the root of all backends
// GetGlobalDataDir returns the root of all backends
// for shared machine data.
func GetGlobalDataDir() (string, error) {
dataDir, err := DataDirPrefix()
Expand Down Expand Up @@ -279,6 +276,7 @@ const (
DockerGlobal
)

// TODO THis should be able to be removed once WSL is refactored for podman5
type Virtualization struct {
artifact define.Artifact
compression compression.ImageCompression
Expand Down Expand Up @@ -357,96 +355,3 @@ func WaitAndPingAPI(sock string) {
logrus.Warn("API socket failed ping test")
}
}

func (dl Download) NewFcosDownloader(imageStream FCOSStream) (DistributionDownload, error) {
info, err := dl.GetFCOSDownload(imageStream)
if err != nil {
return nil, err
}
urlSplit := strings.Split(info.Location, "/")
dl.ImageName = urlSplit[len(urlSplit)-1]
downloadURL, err := url.Parse(info.Location)
if err != nil {
return nil, err
}

// Complete the download struct
dl.Arch = GetFcosArch()
// This could be eliminated as a struct and be a generated()
dl.LocalPath = filepath.Join(dl.CacheDir, dl.ImageName)
dl.Sha256sum = info.Sha256Sum
dl.URL = downloadURL
fcd := FcosDownload{
Download: dl,
}
dataDir, err := GetDataDir(dl.VMKind)
if err != nil {
return nil, err
}
fcd.Download.LocalUncompressedFile = fcd.GetLocalUncompressedFile(dataDir)
return fcd, nil
}

// AcquireVMImage determines if the image is already in a FCOS stream. If so,
// retrieves the image path of the uncompressed file. Otherwise, the user has
// provided an alternative image, so we set the image path and download the image.
func (dl Download) AcquireVMImage(imagePath string) (*define.VMFile, FCOSStream, error) {
var (
err error
imageLocation *define.VMFile
fcosStream FCOSStream
)

switch imagePath {
// TODO these need to be re-typed as FCOSStreams
case Testing.String(), Next.String(), Stable.String(), "":
// Get image as usual
fcosStream, err = FCOSStreamFromString(imagePath)
if err != nil {
return nil, 0, err
}

dd, err := dl.NewFcosDownloader(fcosStream)
if err != nil {
return nil, 0, err
}

imageLocation, err = define.NewMachineFile(dd.Get().LocalUncompressedFile, nil)
if err != nil {
return nil, 0, err
}

if err := DownloadImage(dd); err != nil {
return nil, 0, err
}
default:
// The user has provided an alternate image which can be a file path
// or URL.
fcosStream = CustomStream
imgPath, err := dl.AcquireAlternateImage(imagePath)
if err != nil {
return nil, 0, err
}
imageLocation = imgPath
}
return imageLocation, fcosStream, nil
}

// Deprecated: GetLock
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.
vmConfigDir, err := GetConfDir(vmtype)
if err != nil {
return nil, err
}

lockPath := filepath.Join(vmConfigDir, name+".lock")
lock, err := lockfile.GetLockFile(lockPath)
if err != nil {
return nil, fmt.Errorf("creating lockfile for VM: %w", err)
}

return lock, nil
}
20 changes: 1 addition & 19 deletions pkg/machine/fcos.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
const (
// Used for testing the latest podman in fcos
// special builds
podmanTesting = "podman-testing"
PodmanTestingHost = "fedorapeople.org"
PodmanTestingURL = "groups/podman/testing"
)
Expand Down Expand Up @@ -202,8 +201,6 @@ const (
Stable
// Podman-Testing
PodmanTesting
// Unknown
UnknownStream
// Custom
CustomStream
)
Expand All @@ -223,22 +220,7 @@ func (st FCOSStream) String() string {
return "custom"
}

func FCOSStreamFromString(s string) (FCOSStream, error) {
switch s {
case Testing.String():
return Testing, nil
case Next.String():
return Next, nil
case PodmanTesting.String():
return PodmanTesting, nil
case Stable.String():
return Stable, nil
case CustomStream.String():
return CustomStream, nil
}
return UnknownStream, fmt.Errorf("unknown fcos stream: %s", s)
}

// TODO can be removed when WSL is refactored into podman 5
func IsValidFCOSStreamString(s string) bool {
switch s {
case Testing.String():
Expand Down

0 comments on commit 6d107a2

Please sign in to comment.