Skip to content

Commit

Permalink
[uki] Set placeholder for actions,hooks and commands
Browse files Browse the repository at this point in the history
Signed-off-by: Itxaka <[email protected]>
  • Loading branch information
Itxaka committed Sep 18, 2023
1 parent 3e4693d commit b1ec485
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/agent/hooks/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ var FirstBoot = []Interface{
&GrubPostInstallOptions{},
}

// AfterUkiInstall sets which Hooks to run after uki runs the install action
var AfterUkiInstall = []Interface{}

// AfterUkiReset sets which Hooks to run after uki runs the install action
var AfterUkiReset = []Interface{}

// AfterUkiUpgrade sets which Hooks to run after uki runs the install action
var AfterUkiUpgrade = []Interface{}

func Run(c config.Config, spec v1.Spec, hooks ...Interface) error {
for _, h := range hooks {
if err := h.Run(c, spec); err != nil {
Expand Down
42 changes: 42 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/kairos-io/kairos-agent/v2/internal/webui"
agentConfig "github.com/kairos-io/kairos-agent/v2/pkg/config"
v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1"
"github.com/kairos-io/kairos-agent/v2/pkg/uki"
"github.com/kairos-io/kairos-sdk/bundles"
"github.com/kairos-io/kairos-sdk/collector"
"github.com/kairos-io/kairos-sdk/machine"
Expand Down Expand Up @@ -633,6 +634,47 @@ The validate command expects a configuration file as its only argument. Local fi
return nil
},
},
{
Name: "uki",
Description: "UKI subcommands",
Subcommands: []*cli.Command{
{
Name: "install",
Action: func(c *cli.Context) error {
config, err := agentConfig.Scan(collector.Directories(configScanDir...), collector.NoLogs)
if err != nil {
return err
}
installAction := uki.NewInstallAction(config, &v1.EmptySpec{})
return installAction.Run()
},
},
{
Name: "upgrade",
Action: func(c *cli.Context) error {
config, err := agentConfig.Scan(collector.Directories(configScanDir...), collector.NoLogs, collector.StrictValidation(c.Bool("strict-validation")))
if err != nil {
return err
}

upgradeAction := uki.NewUpgradeAction(config, &v1.EmptySpec{})
return upgradeAction.Run()
},
},
{
Name: "reset",
Action: func(c *cli.Context) error {
config, err := agentConfig.Scan(collector.Directories(configScanDir...), collector.NoLogs, collector.StrictValidation(c.Bool("strict-validation")))
if err != nil {
return err
}

resetAction := uki.NewResetAction(config, &v1.EmptySpec{})
return resetAction.Run()
},
},
},
},
}

func main() {
Expand Down
29 changes: 29 additions & 0 deletions pkg/uki/install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package uki

import (
hook "github.com/kairos-io/kairos-agent/v2/internal/agent/hooks"
"github.com/kairos-io/kairos-agent/v2/pkg/config"
v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1"
elementalUtils "github.com/kairos-io/kairos-agent/v2/pkg/utils"
events "github.com/kairos-io/kairos-sdk/bus"
)

type InstallAction struct {
cfg *config.Config
spec *v1.EmptySpec
}

func NewInstallAction(cfg *config.Config, spec *v1.EmptySpec) *InstallAction {
return &InstallAction{cfg: cfg, spec: spec}
}

func (i *InstallAction) Run() (err error) {
// Run pre-install stage
_ = elementalUtils.RunStage(i.cfg, "kairos-uki-install.pre")
_ = events.RunHookScript("/usr/bin/kairos-agent.uki.install.pre.hook")

_ = elementalUtils.RunStage(i.cfg, "kairos-uki-install.after")
_ = events.RunHookScript("/usr/bin/kairos-agent.uki.install.after.hook") //nolint:errcheck

return hook.Run(*i.cfg, i.spec, hook.AfterUkiInstall...)
}
29 changes: 29 additions & 0 deletions pkg/uki/reset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package uki

import (
hook "github.com/kairos-io/kairos-agent/v2/internal/agent/hooks"
"github.com/kairos-io/kairos-agent/v2/pkg/config"
v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1"
elementalUtils "github.com/kairos-io/kairos-agent/v2/pkg/utils"
events "github.com/kairos-io/kairos-sdk/bus"
)

type ResetAction struct {
cfg *config.Config
spec *v1.EmptySpec
}

func NewResetAction(cfg *config.Config, spec *v1.EmptySpec) *ResetAction {
return &ResetAction{cfg: cfg, spec: spec}
}

func (i *ResetAction) Run() (err error) {
// Run pre-install stage
_ = elementalUtils.RunStage(i.cfg, "kairos-uki-reset.pre")
_ = events.RunHookScript("/usr/bin/kairos-agent.uki.reset.pre.hook")

_ = elementalUtils.RunStage(i.cfg, "kairos-uki-reset.after")
_ = events.RunHookScript("/usr/bin/kairos-agent.uki.reset.after.hook") //nolint:errcheck

return hook.Run(*i.cfg, i.spec, hook.AfterUkiReset...)
}
29 changes: 29 additions & 0 deletions pkg/uki/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package uki

import (
hook "github.com/kairos-io/kairos-agent/v2/internal/agent/hooks"
"github.com/kairos-io/kairos-agent/v2/pkg/config"
v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1"
elementalUtils "github.com/kairos-io/kairos-agent/v2/pkg/utils"
events "github.com/kairos-io/kairos-sdk/bus"
)

type UpgradeAction struct {
cfg *config.Config
spec *v1.EmptySpec
}

func NewUpgradeAction(cfg *config.Config, spec *v1.EmptySpec) *UpgradeAction {
return &UpgradeAction{cfg: cfg, spec: spec}
}

func (i *UpgradeAction) Run() (err error) {
// Run pre-install stage
_ = elementalUtils.RunStage(i.cfg, "kairos-uki-upgrade.pre")
_ = events.RunHookScript("/usr/bin/kairos-agent.uki.upgrade.pre.hook")

_ = elementalUtils.RunStage(i.cfg, "kairos-uki-upgrade.after")
_ = events.RunHookScript("/usr/bin/kairos-agent.uki.upgrade.after.hook") //nolint:errcheck

return hook.Run(*i.cfg, i.spec, hook.AfterUkiUpgrade...)
}

0 comments on commit b1ec485

Please sign in to comment.