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 #567

Merged
merged 4 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion internal/agent/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
func CurrentImage() (string, error) {
artifact, err := versioneer.NewArtifactFromOSRelease()
if err != nil {
return "", fmt.Errorf("creating an Artifact from os-release: %w", err)
return "", fmt.Errorf("creating an Artifact from kairos-release: %w", err)
}

registryAndOrg, err := utils.OSRelease("REGISTRY_AND_ORG")
Expand Down
14 changes: 7 additions & 7 deletions pkg/action/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ var _ = Describe("Upgrade Actions test", func() {
Expect(err).ShouldNot(HaveOccurred())

err = fs.WriteFile(
filepath.Join(spec.Active.MountPoint, "etc", "os-release"),
filepath.Join(spec.Active.MountPoint, "etc", "kairos-release"),
[]byte("GRUB_ENTRY_NAME=TESTOS"),
constants.FilePerm,
)
Expand Down Expand Up @@ -253,7 +253,7 @@ var _ = Describe("Upgrade Actions test", func() {
err := upgrade.Run()
Expect(err).ToNot(HaveOccurred())

// Check that the rebrand worked with our os-release value
// Check that the rebrand worked with our kairos-release value
Expect(memLog).To(ContainSubstring("Setting default grub entry to TESTOS"), memLog.String())

// This should be the new image
Expand Down Expand Up @@ -285,7 +285,7 @@ var _ = Describe("Upgrade Actions test", func() {
err := upgrade.Run()
Expect(err).ToNot(HaveOccurred())
By("Checking the log")
// Check that the rebrand worked with our os-release value
// Check that the rebrand worked with our kairos-release value
Expect(memLog).To(ContainSubstring("Setting default grub entry to TESTOS"))

By("checking active image")
Expand Down Expand Up @@ -319,7 +319,7 @@ var _ = Describe("Upgrade Actions test", func() {
err := upgrade.Run()
Expect(err).ToNot(HaveOccurred())

// Check that the rebrand worked with our os-release value
// Check that the rebrand worked with our kairos-release value
Expect(memLog).To(ContainSubstring("Setting default grub entry to TESTOS"))

// This should be the new image
Expand Down Expand Up @@ -357,7 +357,7 @@ var _ = Describe("Upgrade Actions test", func() {
err = upgrade.Run()
Expect(err).ToNot(HaveOccurred())

// Check that the rebrand worked with our os-release value
// Check that the rebrand worked with our kairos-release value
Expect(memLog).To(ContainSubstring("Setting default grub entry to TESTOS"))

// Not much that we can create here as the dir copy was done on the real os, but we do the rest of the ops on a mem one
Expand Down Expand Up @@ -395,7 +395,7 @@ var _ = Describe("Upgrade Actions test", func() {
Expect(err).ShouldNot(HaveOccurred())

err = fs.WriteFile(
filepath.Join(spec.Active.MountPoint, "etc", "os-release"),
filepath.Join(spec.Active.MountPoint, "etc", "kairos-release"),
[]byte("GRUB_ENTRY_NAME=TESTOS"),
constants.FilePerm,
)
Expand Down Expand Up @@ -445,7 +445,7 @@ var _ = Describe("Upgrade Actions test", func() {
err := upgrade.Run()
Expect(err).ToNot(HaveOccurred())

// Check that the rebrand worked with our os-release value
// Check that the rebrand worked with our kairos-release value
Expect(memLog).To(ContainSubstring("Setting default grub entry to TESTOS"))

// This should be the new image
Expand Down
13 changes: 12 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ func scan(result *Config, opts ...collector.Option) (c *Config, err error) {
result.Logger.Logger.Info().Interface("version", version.GetVersion()).Msg("Kairos Agent")
result.Logger.Logger.Debug().Interface("version", version.Get()).Msg("Kairos Agent")

// Try to load the kairos version from the os-release file
// Try to load the kairos version from the kairos-release file
// Best effort, if it fails, we just ignore it
f, err := result.Fs.Open("/etc/os-release")
defer f.Close()
Expand All @@ -417,6 +417,17 @@ func scan(result *Config, opts ...collector.Option) (c *Config, err error) {
v := osRelease["KAIROS_VERSION"]
if v != "" {
result.Logger.Logger.Info().Str("version", v).Msg("Kairos System")
} else {
// Fallback into os-release
f, err = result.Fs.Open("/etc/os-release")
defer f.Close()
osRelease, err = godotenv.Parse(f)
if err == nil {
v = osRelease["KAIROS_VERSION"]
if v != "" {
result.Logger.Logger.Info().Str("version", v).Msg("Kairos System")
}
}
}
}

Expand Down
9 changes: 6 additions & 3 deletions pkg/elemental/elemental.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,13 +547,16 @@ func (e Elemental) UpdateSourcesFormDownloadedISO(workDir string, activeImg *v1.
return nil
}

// SetDefaultGrubEntry Sets the default_meny_entry value in Config.GrubOEMEnv file at in
// State partition mountpoint. If there is not a custom value in the os-release file, we do nothing
// SetDefaultGrubEntry Sets the default_menu_entry value in Config.GrubOEMEnv file at in
// State partition mountpoint. If there is not a custom value in the kairos-release file, we do nothing
// As the grub config already has a sane default
func (e Elemental) SetDefaultGrubEntry(partMountPoint string, imgMountPoint string, defaultEntry string) error {
if defaultEntry == "" {
osRelease, err := utils.LoadEnvFile(e.config.Fs, filepath.Join(imgMountPoint, "etc", "os-release"))
var osRelease map[string]string
osRelease, err := utils.LoadEnvFile(e.config.Fs, filepath.Join(imgMountPoint, "etc", "kairos-release"))
if err != nil {
// Fallback to os-release
osRelease, err = utils.LoadEnvFile(e.config.Fs, filepath.Join(imgMountPoint, "etc", "os-release"))
e.config.Logger.Warnf("Could not load os-release file: %v", err)
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/elemental/elemental_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ var _ = Describe("Elemental", Label("elemental"), func() {
Expect(err).To(BeNil())
Expect(varsParsed["default_menu_entry"]).To(Equal("dio"))
})
It("does nothing on empty default entry and no /etc/os-release", func() {
It("does nothing on empty default entry and no /etc/kairos-release", func() {
el := elemental.NewElemental(config)
Expect(config.Fs.Mkdir("/mountpoint", cnst.DirPerm)).To(BeNil())
Expect(el.SetDefaultGrubEntry("/mountpoint", "/imgMountPoint", "")).To(BeNil())
Expand All @@ -859,10 +859,10 @@ var _ = Describe("Elemental", Label("elemental"), func() {
_, err = config.Fs.Stat(filepath.Join("/tmp", cnst.GrubOEMEnv))
Expect(err).ToNot(BeNil())
})
It("loads /etc/os-release on empty default entry", func() {
It("loads /etc/kairos-release on empty default entry", func() {
err := fsutils.MkdirAll(config.Fs, "/imgMountPoint/etc", cnst.DirPerm)
Expect(err).ShouldNot(HaveOccurred())
err = config.Fs.WriteFile("/imgMountPoint/etc/os-release", []byte("GRUB_ENTRY_NAME=test"), cnst.FilePerm)
err = config.Fs.WriteFile("/imgMountPoint/etc/kairos-release", []byte("GRUB_ENTRY_NAME=test"), cnst.FilePerm)
Expect(err).ShouldNot(HaveOccurred())
Expect(config.Fs.Mkdir("/mountpoint", cnst.DirPerm)).To(BeNil())

Expand Down
19 changes: 15 additions & 4 deletions pkg/utils/grub.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,13 @@ func (g Grub) Install(target, rootDir, bootDir, grubConf, tty string, efi bool,
return err
}

flavor, err := utils.OSRelease("FLAVOR", filepath.Join(cnst.ActiveDir, "etc/os-release"))
flavor, err := utils.OSRelease("FLAVOR", filepath.Join(cnst.ActiveDir, "etc/kairos-release"))
if err != nil {
g.config.Logger.Warnf("Failed reading os-release from %s: %v", filepath.Join(cnst.ActiveDir, "etc/os-release"), err)
// Fallback to os-release
flavor, err = utils.OSRelease("FLAVOR", filepath.Join(cnst.ActiveDir, "os/kairos-release"))
if err != nil {
g.config.Logger.Warnf("Failed reading release info from %s and %s: %v", filepath.Join(cnst.ActiveDir, "etc/kairos-release"), filepath.Join(cnst.ActiveDir, "os/kairos-release"), err)
}
}
g.config.Logger.Debugf("Detected Flavor: %s", flavor)
// Copy needed files for efi boot
Expand All @@ -188,7 +192,14 @@ func (g Grub) Install(target, rootDir, bootDir, grubConf, tty string, efi bool,
// providing a generic package

// Shim is not available in Alpine + rpi
model, err := utils.OSRelease("KAIROS_MODEL", filepath.Join(cnst.ActiveDir, "etc/os-release"))
var model string
model, err = utils.OSRelease("KAIROS_MODEL", filepath.Join(cnst.ActiveDir, "etc/kairos-release"))
if err != nil {
model, err = utils.OSRelease("KAIROS_MODEL", filepath.Join(cnst.ActiveDir, "etc/os-release"))
mauromorales marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
g.config.Logger.Warnf("Failed reading model info from %s and %s: %v", filepath.Join(cnst.ActiveDir, "etc/kairos-release"), filepath.Join(cnst.ActiveDir, "os/kairos-release"), err)
}
}
if strings.Contains(strings.ToLower(flavor), "alpine") && strings.Contains(strings.ToLower(model), "rpi") {
g.config.Logger.Debug("Running on Alpine+RPI, not copying shim or grub.")
} else {
Expand All @@ -210,7 +221,7 @@ func (g Grub) Install(target, rootDir, bootDir, grubConf, tty string, efi bool,
}
// Ubuntu efi searches for the grub.cfg file under /EFI/ubuntu/grub.cfg while we store it under /boot/grub2/grub.cfg
// workaround this by copying it there as well
// read the os-release from the rootfs to know if we are creating a ubuntu based iso
// read the kairos-release from the rootfs to know if we are creating a ubuntu based iso
if strings.Contains(strings.ToLower(flavor), "ubuntu") {
g.config.Logger.Infof("Ubuntu based ISO detected, copying grub.cfg to /EFI/ubuntu/grub.cfg")
err = fsutils.MkdirAll(g.config.Fs, filepath.Join(cnst.EfiDir, "EFI/ubuntu/"), constants.DirPerm)
Expand Down