Skip to content

Commit

Permalink
pkg/utils: Support host operating systems without VERSION_ID
Browse files Browse the repository at this point in the history
The VERSION_ID field in os-release(5) is optional [1].  It's absent on
Arch Linux, which follows a rolling-release model and uses the BUILD_ID
field instead:
  BUILD_ID=rolling

A subsequent commit will add built-in support for Arch Linux.  Hence,
the code to get the default release from the host operating system can
no longer assume the presence of the VERSION_ID field in os-release(5).

Note that the arch-toolbox image is tagged with 'latest', in accordance
with OCI conventions, not 'rolling' [2,3], which is the os-release(5)
BUILD_ID.  Therefore, it will be wise to use 'latest' as the default
release on Arch Linux, to simplify how the default release matches with
the default image's tag.  This means that a os-release(5) field can't be
used for the default release on Arch.

[1] https://www.freedesktop.org/software/systemd/man/os-release.html

[2] Commit 2568528
    containers#861

[3] Commit a4e5861
    containers#1308

containers#1303
  • Loading branch information
debarshiray committed Jun 12, 2023
1 parent 28913fa commit d14fd7b
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion src/pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ import (
"golang.org/x/sys/unix"
)

type GetDefaultReleaseFunc func() (string, error)
type GetFullyQualifiedImageFunc func(string, string) string
type ParseReleaseFunc func(string) (string, error)

type Distro struct {
ContainerNamePrefix string
ImageBasename string
GetDefaultRelease GetDefaultReleaseFunc
GetFullyQualifiedImage GetFullyQualifiedImageFunc
ParseRelease ParseReleaseFunc
}
Expand Down Expand Up @@ -100,18 +102,21 @@ var (
"fedora": {
"fedora-toolbox",
"fedora-toolbox",
getDefaultReleaseFedora,
getFullyQualifiedImageFedora,
parseReleaseFedora,
},
"rhel": {
"rhel-toolbox",
"toolbox",
getDefaultReleaseRHEL,
getFullyQualifiedImageRHEL,
parseReleaseRHEL,
},
"ubuntu": {
"ubuntu-toolbox",
"ubuntu-toolbox",
getDefaultReleaseUbuntu,
getFullyQualifiedImageUbuntu,
parseReleaseUbuntu,
},
Expand Down Expand Up @@ -140,7 +145,7 @@ func init() {
hostID, err := GetHostID()
if err == nil {
if distroObj, supportedDistro := supportedDistros[hostID]; supportedDistro {
release, err := getHostVersionID()
release, err := getDefaultReleaseForDistro(hostID)
if err == nil {
containerNamePrefixDefault = distroObj.ContainerNamePrefix
distroDefault = hostID
Expand Down Expand Up @@ -273,6 +278,52 @@ func getDefaultImageForDistro(distro, release string) string {
return image
}

func getDefaultReleaseForDistro(distro string) (string, error) {
if distro == "" {
panic("distro not specified")
}

distroObj, supportedDistro := supportedDistros[distro]
if !supportedDistro {
panicMsg := fmt.Sprintf("failed to find %s in the list of supported distributions", distro)
panic(panicMsg)
}

release, err := distroObj.GetDefaultRelease()
if err != nil {
return "", err
}

return release, nil
}

func getDefaultReleaseFedora() (string, error) {
release, err := getHostVersionID()
if err != nil {
return "", err
}

return release, nil
}

func getDefaultReleaseRHEL() (string, error) {
release, err := getHostVersionID()
if err != nil {
return "", err
}

return release, nil
}

func getDefaultReleaseUbuntu() (string, error) {
release, err := getHostVersionID()
if err != nil {
return "", err
}

return release, nil
}

func GetEnvOptionsForPreservedVariables() []string {
logrus.Debug("Creating list of environment variables to forward")

Expand Down

0 comments on commit d14fd7b

Please sign in to comment.