From e74d268bf26e3d3f7299f67417429ca192ec5307 Mon Sep 17 00:00:00 2001 From: Brent Baude Date: Sun, 11 Feb 2024 09:15:07 -0600 Subject: [PATCH] Minor cleanup from podman 4 This PR is only a few cleanup items where code is no longer used. More to come I'm sure [NO NEW TESTS NEEDED] Signed-off-by: Brent Baude --- pkg/machine/config.go | 103 ++---------------------------------------- pkg/machine/fcos.go | 20 +------- 2 files changed, 5 insertions(+), 118 deletions(-) diff --git a/pkg/machine/config.go b/pkg/machine/config.go index 7730d5c525..e21b3fca26 100644 --- a/pkg/machine/config.go +++ b/pkg/machine/config.go @@ -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" ) @@ -28,8 +25,7 @@ const ( ) var ( - DefaultIgnitionUserName = "core" - ForwarderBinaryName = "gvproxy" + ForwarderBinaryName = "gvproxy" ) type Download struct { @@ -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) @@ -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() @@ -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 @@ -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 -} diff --git a/pkg/machine/fcos.go b/pkg/machine/fcos.go index a06daacdf5..5707ebbadb 100644 --- a/pkg/machine/fcos.go +++ b/pkg/machine/fcos.go @@ -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" ) @@ -202,8 +201,6 @@ const ( Stable // Podman-Testing PodmanTesting - // Unknown - UnknownStream // Custom CustomStream ) @@ -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():