mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-08-14 22:43:18 +00:00
sparkles: Add bundles to post-install hooks (#171)
* 🤖 Add bundles and sysext test * ✨ Exec bundles also after install * 🤖 Adapt tests * 🎨 Create dir only if doesn't exist * 🎨 Return err on mount * 🎨 Make bundle errors failure as an option * 🎨 Minor fixups * debug * 🤖 Fix spec * 🤖 Get correct version for bundle test * 🎨 Fixups * 🤖 systemd-sysext is available only on opensuse for now
This commit is contained in:
parent
b1396c541b
commit
a8875f6b4f
@ -63,14 +63,14 @@ func Run(opts ...Option) error {
|
|||||||
if !machine.SentinelExist("bundles") {
|
if !machine.SentinelExist("bundles") {
|
||||||
opts := c.Bundles.Options()
|
opts := c.Bundles.Options()
|
||||||
err := bundles.RunBundles(opts...)
|
err := bundles.RunBundles(opts...)
|
||||||
if !c.IgnoreBundleErrors && err != nil {
|
if c.FailOnBundleErrors && err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Re-load providers
|
// Re-load providers
|
||||||
bus.Reload()
|
bus.Reload()
|
||||||
err = machine.CreateSentinel("bundles")
|
err = machine.CreateSentinel("bundles")
|
||||||
if !c.IgnoreBundleErrors && err != nil {
|
if c.FailOnBundleErrors && err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
30
internal/agent/hooks/bundles.go
Normal file
30
internal/agent/hooks/bundles.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package hook
|
||||||
|
|
||||||
|
import (
|
||||||
|
config "github.com/kairos-io/kairos/pkg/config"
|
||||||
|
"github.com/kairos-io/kairos/pkg/machine"
|
||||||
|
"github.com/kairos-io/kairos/sdk/bundles"
|
||||||
|
)
|
||||||
|
|
||||||
|
type BundleOption struct{}
|
||||||
|
|
||||||
|
func (b BundleOption) Run(c config.Config) error {
|
||||||
|
|
||||||
|
machine.Mount("COS_PERSISTENT", "/usr/local") //nolint:errcheck
|
||||||
|
defer func() {
|
||||||
|
machine.Umount("/usr/local")
|
||||||
|
}()
|
||||||
|
|
||||||
|
machine.Mount("COS_OEM", "/oem") //nolint:errcheck
|
||||||
|
defer func() {
|
||||||
|
machine.Umount("/oem")
|
||||||
|
}()
|
||||||
|
|
||||||
|
opts := c.Install.Bundles.Options()
|
||||||
|
err := bundles.RunBundles(opts...)
|
||||||
|
if c.FailOnBundleErrors && err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
@ -2,29 +2,20 @@ package hook
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
|
|
||||||
config "github.com/kairos-io/kairos/pkg/config"
|
config "github.com/kairos-io/kairos/pkg/config"
|
||||||
|
"github.com/kairos-io/kairos/pkg/machine"
|
||||||
"github.com/kairos-io/kairos/pkg/utils"
|
"github.com/kairos-io/kairos/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GrubOptions struct{}
|
type GrubOptions struct{}
|
||||||
|
|
||||||
func (b GrubOptions) Run(c config.Config) error {
|
func (b GrubOptions) Run(c config.Config) error {
|
||||||
oem, _ := utils.SH("blkid -L COS_OEM")
|
|
||||||
if oem == "" {
|
|
||||||
fmt.Println("OEM partition not found")
|
|
||||||
return nil // do not error out
|
|
||||||
}
|
|
||||||
|
|
||||||
oem = strings.TrimSuffix(oem, "\n")
|
|
||||||
|
|
||||||
oemMount, err := utils.SH(fmt.Sprintf("mkdir /tmp/oem && mount %s /tmp/oem", oem))
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("could not mount oem: %s\n", oemMount+err.Error())
|
|
||||||
return nil // do not error out
|
|
||||||
}
|
|
||||||
|
|
||||||
|
machine.Mount("COS_OEM", "/tmp/oem") //nolint:errcheck
|
||||||
|
defer func() {
|
||||||
|
machine.Umount("/tmp/oem")
|
||||||
|
}()
|
||||||
for k, v := range c.Install.GrubOptions {
|
for k, v := range c.Install.GrubOptions {
|
||||||
out, err := utils.SH(fmt.Sprintf("grub2-editenv /tmp/oem/grubenv set %s=%s", k, v))
|
out, err := utils.SH(fmt.Sprintf("grub2-editenv /tmp/oem/grubenv set %s=%s", k, v))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -33,6 +24,5 @@ func (b GrubOptions) Run(c config.Config) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.SH("umount /tmp/oem") //nolint:errcheck
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ type Interface interface {
|
|||||||
var All = []Interface{
|
var All = []Interface{
|
||||||
&RunStage{}, // Shells out to stages defined from the container image
|
&RunStage{}, // Shells out to stages defined from the container image
|
||||||
&GrubOptions{}, // Set custom GRUB options
|
&GrubOptions{}, // Set custom GRUB options
|
||||||
|
&BundleOption{},
|
||||||
&Lifecycle{}, // Handles poweroff/reboot by config options
|
&Lifecycle{}, // Handles poweroff/reboot by config options
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user