1
0
mirror of https://github.com/kairos-io/kairos-agent.git synced 2025-05-11 01:44:53 +00:00

Expose the Analize method of yip ()

This only shows for a given stage what steps would be run and in which
order

Signed-off-by: Itxaka <itxaka@kairos.io>
This commit is contained in:
Itxaka 2024-09-20 10:36:09 +02:00 committed by GitHub
parent 970eb1aa72
commit bd4dce015f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 49 additions and 9 deletions

View File

@ -667,6 +667,11 @@ The validate command expects a configuration file as its only argument. Local fi
Name: "cloud-init-paths",
Usage: "Extra paths to add to the run stage",
},
&cli.BoolFlag{
Name: "analyze",
Usage: "Only print the modules that would run in the order they would run",
Aliases: []string{"a"},
},
},
Before: func(c *cli.Context) error {
if c.Args().Len() != 1 {
@ -692,6 +697,9 @@ The validate command expects a configuration file as its only argument. Local fi
if err != nil {
config.Logger.Errorf("Error reading config: %s\n", err)
}
if c.Bool("analyze") {
return utils.RunStageAnalyze(config, stage)
}
return utils.RunStage(config, stage)
},
},

View File

@ -81,3 +81,7 @@ func (ci *YipCloudInitRunner) SetModifier(m schema.Modifier) {
func (ci *YipCloudInitRunner) SetFs(fs vfs.FS) {
ci.fs = fs
}
func (ci *YipCloudInitRunner) Analyze(stage string, args ...string) {
ci.exec.Analyze(stage, vfs.OSFS, ci.console, args...)
}

View File

@ -22,5 +22,6 @@ import (
type CloudInitRunner interface {
Run(string, ...string) error
Analyze(string, ...string)
SetModifier(schema.Modifier)
}

View File

@ -57,14 +57,26 @@ func checkYAMLError(cfg *agentConfig.Config, allErrors, err error) error {
return allErrors
}
// RunstageAnalyze
func RunStageAnalyze(cfg *agentConfig.Config, stage string) error {
return runstage(cfg, stage, true)
}
// RunStage will run yip
func RunStage(cfg *agentConfig.Config, stage string) error {
return runstage(cfg, stage, false)
}
func runstage(cfg *agentConfig.Config, stage string, analyze bool) error {
var cmdLineYipURI string
var allErrors error
var cloudInitPaths []string
cloudInitPaths = append(constants.GetCloudInitPaths(), cfg.CloudInitPaths...)
cfg.Logger.Debugf("Cloud-init paths set to %v", cloudInitPaths)
if analyze {
cfg.Logger.Info("Analyze mode, showing DAG")
}
// Make sure cloud init path specified are existing in the system
for _, cp := range cloudInitPaths {
@ -96,9 +108,13 @@ func RunStage(cfg *agentConfig.Config, stage string) error {
// Run all stages for each of the default cloud config paths + extra cloud config paths
for _, s := range []string{stageBefore, stage, stageAfter} {
err = cfg.CloudInitRunner.Run(s, cloudInitPaths...)
if err != nil {
allErrors = multierror.Append(allErrors, err)
if analyze {
cfg.CloudInitRunner.Analyze(s, cloudInitPaths...)
} else {
err = cfg.CloudInitRunner.Run(s, cloudInitPaths...)
if err != nil {
allErrors = multierror.Append(allErrors, err)
}
}
}
@ -106,9 +122,13 @@ func RunStage(cfg *agentConfig.Config, stage string) error {
if cmdLineYipURI != "" {
cmdLineArgs := []string{cmdLineYipURI}
for _, s := range []string{stageBefore, stage, stageAfter} {
err = cfg.CloudInitRunner.Run(s, cmdLineArgs...)
if err != nil {
allErrors = multierror.Append(allErrors, err)
if analyze {
cfg.CloudInitRunner.Analyze(s, cloudInitPaths...)
} else {
err = cfg.CloudInitRunner.Run(s, cmdLineArgs...)
if err != nil {
allErrors = multierror.Append(allErrors, err)
}
}
}
}
@ -117,10 +137,15 @@ func RunStage(cfg *agentConfig.Config, stage string) error {
cfg.CloudInitRunner.SetModifier(schema.DotNotationModifier)
for _, s := range []string{stageBefore, stage, stageAfter} {
err = cfg.CloudInitRunner.Run(s, string(cmdLineOut))
if err != nil {
allErrors = checkYAMLError(cfg, allErrors, err)
if analyze {
cfg.CloudInitRunner.Analyze(s, cloudInitPaths...)
} else {
err = cfg.CloudInitRunner.Run(s, string(cmdLineOut))
if err != nil {
allErrors = checkYAMLError(cfg, allErrors, err)
}
}
}
cfg.CloudInitRunner.SetModifier(nil)

View File

@ -37,3 +37,5 @@ func (ci *FakeCloudInitRunner) Run(stage string, args ...string) error {
func (ci *FakeCloudInitRunner) SetModifier(modifier schema.Modifier) {
}
func (ci *FakeCloudInitRunner) Analyze(stage string, args ...string) {}