Skip to content

Commit

Permalink
Move to use kairos-release (#567)
Browse files Browse the repository at this point in the history
  • Loading branch information
Itxaka authored Oct 7, 2024
1 parent ee0ae62 commit e8bb8cf
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 21 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
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
20 changes: 16 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)
}
}
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
Expand All @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit e8bb8cf

Please sign in to comment.