Skip to content

Commit d14fd7b

Browse files
committed
pkg/utils: Support host operating systems without VERSION_ID
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
1 parent 28913fa commit d14fd7b

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

src/pkg/utils/utils.go

+52-1
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@ import (
3939
"golang.org/x/sys/unix"
4040
)
4141

42+
type GetDefaultReleaseFunc func() (string, error)
4243
type GetFullyQualifiedImageFunc func(string, string) string
4344
type ParseReleaseFunc func(string) (string, error)
4445

4546
type Distro struct {
4647
ContainerNamePrefix string
4748
ImageBasename string
49+
GetDefaultRelease GetDefaultReleaseFunc
4850
GetFullyQualifiedImage GetFullyQualifiedImageFunc
4951
ParseRelease ParseReleaseFunc
5052
}
@@ -100,18 +102,21 @@ var (
100102
"fedora": {
101103
"fedora-toolbox",
102104
"fedora-toolbox",
105+
getDefaultReleaseFedora,
103106
getFullyQualifiedImageFedora,
104107
parseReleaseFedora,
105108
},
106109
"rhel": {
107110
"rhel-toolbox",
108111
"toolbox",
112+
getDefaultReleaseRHEL,
109113
getFullyQualifiedImageRHEL,
110114
parseReleaseRHEL,
111115
},
112116
"ubuntu": {
113117
"ubuntu-toolbox",
114118
"ubuntu-toolbox",
119+
getDefaultReleaseUbuntu,
115120
getFullyQualifiedImageUbuntu,
116121
parseReleaseUbuntu,
117122
},
@@ -140,7 +145,7 @@ func init() {
140145
hostID, err := GetHostID()
141146
if err == nil {
142147
if distroObj, supportedDistro := supportedDistros[hostID]; supportedDistro {
143-
release, err := getHostVersionID()
148+
release, err := getDefaultReleaseForDistro(hostID)
144149
if err == nil {
145150
containerNamePrefixDefault = distroObj.ContainerNamePrefix
146151
distroDefault = hostID
@@ -273,6 +278,52 @@ func getDefaultImageForDistro(distro, release string) string {
273278
return image
274279
}
275280

281+
func getDefaultReleaseForDistro(distro string) (string, error) {
282+
if distro == "" {
283+
panic("distro not specified")
284+
}
285+
286+
distroObj, supportedDistro := supportedDistros[distro]
287+
if !supportedDistro {
288+
panicMsg := fmt.Sprintf("failed to find %s in the list of supported distributions", distro)
289+
panic(panicMsg)
290+
}
291+
292+
release, err := distroObj.GetDefaultRelease()
293+
if err != nil {
294+
return "", err
295+
}
296+
297+
return release, nil
298+
}
299+
300+
func getDefaultReleaseFedora() (string, error) {
301+
release, err := getHostVersionID()
302+
if err != nil {
303+
return "", err
304+
}
305+
306+
return release, nil
307+
}
308+
309+
func getDefaultReleaseRHEL() (string, error) {
310+
release, err := getHostVersionID()
311+
if err != nil {
312+
return "", err
313+
}
314+
315+
return release, nil
316+
}
317+
318+
func getDefaultReleaseUbuntu() (string, error) {
319+
release, err := getHostVersionID()
320+
if err != nil {
321+
return "", err
322+
}
323+
324+
return release, nil
325+
}
326+
276327
func GetEnvOptionsForPreservedVariables() []string {
277328
logrus.Debug("Creating list of environment variables to forward")
278329

0 commit comments

Comments
 (0)