sparkles: Add reset hook (#723)

Signed-off-by: mudler <mudler@c3os.io>

Signed-off-by: mudler <mudler@c3os.io>
This commit is contained in:
Ettore Di Giacinto 2023-01-25 13:38:56 +01:00 committed by Itxaka
parent 9b16896a1a
commit 746135eede
3 changed files with 11 additions and 2 deletions

View File

@ -8,7 +8,7 @@ type Interface interface {
Run(c config.Config) error Run(c config.Config) error
} }
var All = []Interface{ var AfterInstall = []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{}, &BundleOption{},
@ -16,6 +16,10 @@ var All = []Interface{
&Lifecycle{}, // Handles poweroff/reboot by config options &Lifecycle{}, // Handles poweroff/reboot by config options
} }
var AfterReset = []Interface{
&Kcrypt{},
}
var FirstBoot = []Interface{ var FirstBoot = []Interface{
&BundlePostInstall{}, &BundlePostInstall{},
&GrubPostInstallOptions{}, &GrubPostInstallOptions{},

View File

@ -286,7 +286,7 @@ func RunInstall(options map[string]string) error {
os.Exit(1) os.Exit(1)
} }
if err := hook.Run(*c, hook.All...); err != nil { if err := hook.Run(*c, hook.AfterInstall...); err != nil {
return err return err
} }

View File

@ -8,6 +8,7 @@ import (
"sync" "sync"
"time" "time"
hook "github.com/kairos-io/kairos/internal/agent/hooks"
"github.com/kairos-io/kairos/internal/bus" "github.com/kairos-io/kairos/internal/bus"
"github.com/kairos-io/kairos/internal/cmd" "github.com/kairos-io/kairos/internal/cmd"
"github.com/kairos-io/kairos/pkg/config" "github.com/kairos-io/kairos/pkg/config"
@ -88,6 +89,10 @@ func Reset(dir ...string) error {
os.Exit(1) os.Exit(1)
} }
if err := hook.Run(*c, hook.AfterReset...); err != nil {
return err
}
bus.Manager.Publish(sdk.EventAfterReset, sdk.EventPayload{}) //nolint:errcheck bus.Manager.Publish(sdk.EventAfterReset, sdk.EventPayload{}) //nolint:errcheck
pterm.Info.Println("Rebooting in 60 seconds, press Enter to abort...") pterm.Info.Println("Rebooting in 60 seconds, press Enter to abort...")