sparkles: enhancements (#263)

* 🎨 Do not need to prefix '.' on queries

*  Add recovery to stateapi

*  Add cloudconfig SDK

*  Unify post-install/firstboot hooks

This also adds capabilities to add grub option at first boot rather than
after installation as for bundles.

* 🤖 Optimize tests to wait for state to change
This commit is contained in:
Ettore Di Giacinto 2022-10-24 08:34:49 +02:00 committed by Itxaka
parent 5893294c54
commit 0af13f655f
4 changed files with 31 additions and 6 deletions

View File

@ -8,10 +8,10 @@ import (
events "github.com/kairos-io/kairos/sdk/bus"
hook "github.com/kairos-io/kairos/internal/agent/hooks"
"github.com/kairos-io/kairos/internal/bus"
config "github.com/kairos-io/kairos/pkg/config"
machine "github.com/kairos-io/kairos/pkg/machine"
bundles "github.com/kairos-io/kairos/sdk/bundles"
"github.com/nxadm/tail"
)
@ -60,16 +60,15 @@ func Run(opts ...Option) error {
}
}()
if !machine.SentinelExist("bundles") {
opts := c.Bundles.Options()
err := bundles.RunBundles(opts...)
if c.FailOnBundleErrors && err != nil {
if !machine.SentinelExist("firstboot") {
if err := hook.Run(*c, hook.FirstBoot...); err != nil {
return err
}
// Re-load providers
bus.Reload()
err = machine.CreateSentinel("bundles")
err = machine.CreateSentinel("firstboot")
if c.FailOnBundleErrors && err != nil {
return err
}

View File

@ -28,3 +28,14 @@ func (b BundleOption) Run(c config.Config) error {
return nil
}
type BundlePostInstall struct{}
func (b BundlePostInstall) Run(c config.Config) error {
opts := c.Bundles.Options()
err := bundles.RunBundles(opts...)
if c.FailOnBundleErrors && err != nil {
return err
}
return nil
}

View File

@ -16,3 +16,13 @@ func (b GrubOptions) Run(c config.Config) error {
}
return nil
}
type GrubPostInstallOptions struct{}
func (b GrubPostInstallOptions) Run(c config.Config) error {
err := system.Apply(system.SetGRUBOptions(c.GrubOptions))
if err != nil {
fmt.Println(err)
}
return nil
}

View File

@ -16,6 +16,11 @@ var All = []Interface{
&Lifecycle{}, // Handles poweroff/reboot by config options
}
var FirstBoot = []Interface{
&BundlePostInstall{},
&GrubPostInstallOptions{},
}
func Run(c config.Config, hooks ...Interface) error {
for _, h := range hooks {
if err := h.Run(c); err != nil {