diff --git a/go.mod b/go.mod index bb05ce85..1d4cb905 100644 --- a/go.mod +++ b/go.mod @@ -12,14 +12,14 @@ require ( github.com/hashicorp/go-multierror v1.1.1 github.com/jaypipes/ghw v0.13.0 // indirect github.com/joho/godotenv v1.5.1 - github.com/kairos-io/kairos-sdk v0.4.6 + github.com/kairos-io/kairos-sdk v0.6.0 github.com/kairos-io/kcrypt v0.12.2 github.com/labstack/echo/v4 v4.12.0 github.com/mitchellh/mapstructure v1.5.0 github.com/mudler/go-nodepair v0.0.0-20221223092639-ba399a66fdfb github.com/mudler/go-pluggable v0.0.0-20230126220627-7710299a0ae5 github.com/mudler/go-processmanager v0.0.0-20240820160718-8b802d3ecf82 - github.com/mudler/yip v1.10.0 + github.com/mudler/yip v1.11.0 github.com/nxadm/tail v1.4.11 github.com/onsi/ginkgo/v2 v2.20.2 github.com/onsi/gomega v1.34.2 diff --git a/go.sum b/go.sum index 999a0876..6524a1ef 100644 --- a/go.sum +++ b/go.sum @@ -278,6 +278,8 @@ github.com/jzelinskie/whirlpool v0.0.0-20201016144138-0675e54bb004 h1:G+9t9cEtnC github.com/jzelinskie/whirlpool v0.0.0-20201016144138-0675e54bb004/go.mod h1:KmHnJWQrgEvbuy0vcvj00gtMqbvNn1L+3YUZLK/B92c= github.com/kairos-io/kairos-sdk v0.4.6 h1:6dbKozJTku99P2vytz9M0xAnpkKKiAggSMPfT2vpw68= github.com/kairos-io/kairos-sdk v0.4.6/go.mod h1:QXYmZ2BMrJ0Iyp7I3+rvCYpZRMvwOtK/6IGCLhNL4tY= +github.com/kairos-io/kairos-sdk v0.6.0 h1:A096lZVHE4rkvA5kG0Oss0085T0noUcf7AeppWGySR8= +github.com/kairos-io/kairos-sdk v0.6.0/go.mod h1:7Y6Y/McniCyAJcmQfoTfKd09cwmwS40URaIVbJn8V2k= github.com/kairos-io/kcrypt v0.12.2 h1:+lr8FGS0AW6D5dWSmaR3+AobL1TBTnOFgCSYctKY+5I= github.com/kairos-io/kcrypt v0.12.2/go.mod h1:7SPiHzNMYl4MlxeB30s1YlHDYByTusu7u1mU5Nvicm0= github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs= @@ -365,6 +367,8 @@ github.com/mudler/go-processmanager v0.0.0-20240820160718-8b802d3ecf82 h1:FVT07E github.com/mudler/go-processmanager v0.0.0-20240820160718-8b802d3ecf82/go.mod h1:Urp7LG5jylKoDq0663qeBh0pINGcRl35nXdKx82PSoU= github.com/mudler/yip v1.10.0 h1:MwEIySEfSRRwTUz2BmQQpRn6+M7jqVGf/OldsepBvz0= github.com/mudler/yip v1.10.0/go.mod h1:gwH7iGcr1Jimox2xKtN2AprEO00GzY7smvuycqCL7+Y= +github.com/mudler/yip v1.11.0 h1:h+npjzSKM9VbShHxa+ywWZzpGIolKvN/e2FOT+rxKkI= +github.com/mudler/yip v1.11.0/go.mod h1:gwH7iGcr1Jimox2xKtN2AprEO00GzY7smvuycqCL7+Y= github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI= github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo= github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA= diff --git a/internal/agent/upgrade.go b/internal/agent/upgrade.go index c9ef518e..16339965 100644 --- a/internal/agent/upgrade.go +++ b/internal/agent/upgrade.go @@ -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") diff --git a/pkg/action/upgrade_test.go b/pkg/action/upgrade_test.go index 98ea6f8d..3cea3829 100644 --- a/pkg/action/upgrade_test.go +++ b/pkg/action/upgrade_test.go @@ -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, ) @@ -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 @@ -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") @@ -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 @@ -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 @@ -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, ) @@ -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 diff --git a/pkg/config/config.go b/pkg/config/config.go index 131a68af..beb213b3 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -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() @@ -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") + } + } } } diff --git a/pkg/elemental/elemental.go b/pkg/elemental/elemental.go index ba76a1bc..27b47ff4 100644 --- a/pkg/elemental/elemental.go +++ b/pkg/elemental/elemental.go @@ -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 } diff --git a/pkg/elemental/elemental_test.go b/pkg/elemental/elemental_test.go index dc764851..05d5b9c8 100644 --- a/pkg/elemental/elemental_test.go +++ b/pkg/elemental/elemental_test.go @@ -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()) @@ -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()) diff --git a/pkg/utils/grub.go b/pkg/utils/grub.go index eb9f40e1..cb08ecb5 100644 --- a/pkg/utils/grub.go +++ b/pkg/utils/grub.go @@ -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) + } } if flavor == "" { // If os-release is gone with our vars, we dont know what flavor are we in, we should know if we are on ubuntu as we need @@ -200,7 +204,15 @@ 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 { + // Fallback into os-release + model, err = utils.OSRelease("KAIROS_MODEL", filepath.Join(cnst.ActiveDir, "etc/os-release")) + 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 { @@ -222,7 +234,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)