Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to use kairos-release instead of os-release #506

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,21 @@ func UUID() string {
return fmt.Sprintf("%s-%s", id, hostname)
}

// OSRelease finds the value of the specified key in the /etc/os-release file
// OSRelease finds the value of the specified key in the /etc/kairos-release file
// As a fallback on the /etc/os-release
// or, if a second argument is passed, on the file specified by the second argument.
// (optionally file argument is there for testing reasons).
func OSRelease(key string, file ...string) (string, error) {
var osReleaseFile string
osReleaseFallback := "/etc/os-release"

if len(file) > 1 {
return "", errors.New("too many arguments passed")
}
if len(file) > 0 {
osReleaseFile = file[0]
} else {
osReleaseFile = "/etc/os-release"
osReleaseFile = "/etc/kairos-release"
}
release, err := godotenv.Read(osReleaseFile)
if err != nil {
Expand All @@ -91,9 +93,23 @@ func OSRelease(key string, file ...string) (string, error) {
// We try with the old naming without the prefix in case the key wasn't found
v, exists = release[key]
if !exists {
return "", KeyNotFoundErr{Err: fmt.Errorf("%s key not found", kairosKey)}
// We try with fallback file
release, err = godotenv.Read(osReleaseFallback)
if err != nil {
return "", err
}
kairosKey = "KAIROS_" + key
v, exists = release[kairosKey]
if !exists {
// We try with the old naming without the prefix in case the key wasn't found
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's been a long time since we introduced the prefix. What is this trying to catch?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really old releases upgrading to newer ones

v, exists = release[key]
if !exists {
return "", KeyNotFoundErr{Err: fmt.Errorf("%s key not found", kairosKey)}
}
}
}
}

return v, nil
}

Expand Down
2 changes: 1 addition & 1 deletion versioneer/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func CliCommands() []*cli.Command {
},
{
Name: "os-release-variables",
Usage: "generates a set of variables to be appended in the /etc/os-release file",
Usage: "generates a set of variables to be appended in the /etc/kairos-release file",
Flags: []cli.Flag{
flavorFlag, flavorReleaseFlag, variantFlag, modelFlag, archFlag, versionFlag,
softwareVersionFlag, softwareVersionPrefixFlag, registryAndOrgFlag, bugReportURLFlag, projectHomeURLFlag,
Expand Down
2 changes: 1 addition & 1 deletion versioneer/new_from_os_release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var _ = Describe("NewArtifactFromOSRelease", func() {
var osReleaseContent string

BeforeEach(func() {
tmpOSReleaseFile, err = os.CreateTemp("", "os-release")
tmpOSReleaseFile, err = os.CreateTemp("", "kairos-release")
Expect(err).ToNot(HaveOccurred())

osReleaseContent = "KAIROS_FLAVOR=opensuse\n" +
Expand Down
8 changes: 4 additions & 4 deletions versioneer/versioneer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

const (
// KAIROS_VERSION was already used in os-release and we avoided breaking it
// KAIROS_VERSION was already used in kairos-release and we avoided breaking it
// for consumers by using a new variable KAIROS_RELEASE instead. But it's the
// "Artifact.Version".
EnvVarVersion = "RELEASE"
Expand Down Expand Up @@ -49,8 +49,8 @@ func NewArtifactFromJSON(jsonStr string) (*Artifact, error) {
return result, err
}

// NewArtifactFromOSRelease generates an artifact by inpecting the variables
// in the /etc/os-release file of a Kairos image. The variable should be
// NewArtifactFromOSRelease generates an artifact by inspecting the variables
// in the /etc/kairos-release file of a Kairos image. The variable should be
// prefixed with "KAIROS_". E.g. KAIROS_VARIANT would be used to set the Variant
// field. The function optionally takes an argument to specify a different file
// path (for testing reasons).
Expand Down Expand Up @@ -199,7 +199,7 @@ func (a *Artifact) SoftwareVersionForTag() string {
return strings.ReplaceAll(a.SoftwareVersion, "+", "-")
}

// OSReleaseVariables returns a set of variables to be appended in /etc/os-release
// OSReleaseVariables returns a set of variables to be appended in /etc/kairos-release
func (a *Artifact) OSReleaseVariables(registryAndOrg, githubRepo, bugURL, homeURL string) (string, error) {
if registryAndOrg == "" {
return "", errors.New("registry-and-org must be set")
Expand Down