Skip to content

Commit

Permalink
pkg/utils: Clarify the default and fallback values
Browse files Browse the repository at this point in the history
The terms 'default' and 'fallback' are used to mean very specific
things in this context.

The 'default' values are those that are used when the 'create', 'enter'
and 'run' commands were used without any option.  These values are
picked to match the host operating system.

However, if there's no supported Toolbox image matching the host
operating system, and no options were provided to the 'create', 'enter'
and 'run' commands, then the 'fallback' values are used as a last
resort.

Consistently using this terminology leads to a clear mental model and
makes the code easier to read.

This rough arrangement of the code was already being used for
'release', and has now been been extended to 'container name prefix'
and 'distro'.  The suffix for the 'fallback' values was simplified to
'Fallback', instead of 'DefaultFallback'.

containers#937
containers#1080
  • Loading branch information
debarshiray committed Sep 1, 2022
1 parent 344dda6 commit f5bcd22
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ type Distro struct {
}

const (
idTruncLength = 12
releaseDefaultFallback = "34"
containerNamePrefixFallback = "fedora-toolbox"
distroFallback = "fedora"
idTruncLength = 12
releaseFallback = "34"
)

const (
Expand All @@ -61,9 +63,9 @@ const (
)

var (
containerNamePrefixDefault = "fedora-toolbox"
containerNamePrefixDefault string

distroDefault = "fedora"
distroDefault string

preservedEnvironmentVariables = []string{
"COLORTERM",
Expand Down Expand Up @@ -118,7 +120,9 @@ var (
)

func init() {
releaseDefault = releaseDefaultFallback
containerNamePrefixDefault = containerNamePrefixFallback
distroDefault = distroFallback
releaseDefault = releaseFallback

hostID, err := GetHostID()
if err == nil {
Expand Down Expand Up @@ -247,7 +251,7 @@ func getDefaultImageForDistro(distro, release string) string {
}

if _, supportedDistro := supportedDistros[distro]; !supportedDistro {
distro = "fedora"
distro = distroFallback
}

distroObj, supportedDistro := supportedDistros[distro]
Expand Down Expand Up @@ -614,7 +618,7 @@ func ParseRelease(distro, release string) (string, error) {
}

if _, supportedDistro := supportedDistros[distro]; !supportedDistro {
distro = "fedora"
distro = distroFallback
}

distroObj, supportedDistro := supportedDistros[distro]
Expand Down

0 comments on commit f5bcd22

Please sign in to comment.