mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-08-19 08:47:03 +00:00
sparkles: Integrate schema validation (#853)
* Change ValidationError to return the actual error Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Add validate command Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Warn validation errors when scanning configs Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Lint Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Add schema command to print config json schema Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Add strict-validations flag Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Lint and remove focus Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Rename command schema to print-schema Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Fix issue by reading originalData Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Lint Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Remove test from removed feature Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Add comments to exported functions Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Lint Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Add test for validate.go Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Remove focus Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Add more tests for root schema Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Add more tests Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> --------- Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> Co-authored-by: Itxaka <itxaka.garcia@spectrocloud.com>
This commit is contained in:
parent
21ab650dc3
commit
08feaf3e92
@ -79,7 +79,7 @@ See https://kairos.io/docs/upgrade/manual/ for documentation.
|
|||||||
if c.Args().Len() == 1 {
|
if c.Args().Len() == 1 {
|
||||||
v = c.Args().First()
|
v = c.Args().First()
|
||||||
}
|
}
|
||||||
return agent.Upgrade(v, c.String("image"), c.Bool("force"), c.Bool("debug"), configScanDir)
|
return agent.Upgrade(v, c.String("image"), c.Bool("force"), c.Bool("debug"), c.Bool("strict-validation"), configScanDir)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -237,7 +237,7 @@ enabled: true`,
|
|||||||
Description: "It allows to navigate the YAML config file by searching with 'yq' style keywords as `config get k3s` to retrieve the k3s config block",
|
Description: "It allows to navigate the YAML config file by searching with 'yq' style keywords as `config get k3s` to retrieve the k3s config block",
|
||||||
Aliases: []string{"g"},
|
Aliases: []string{"g"},
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
config, err := config.Scan(config.Directories(configScanDir...), config.NoLogs)
|
config, err := config.Scan(config.Directories(configScanDir...), config.NoLogs, config.StrictValidation(c.Bool("strict-validation")))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -348,7 +348,8 @@ This command is meant to be used from the boot GRUB menu, but can be also starte
|
|||||||
if c.Bool("reboot") {
|
if c.Bool("reboot") {
|
||||||
options["reboot"] = "true"
|
options["reboot"] = "true"
|
||||||
}
|
}
|
||||||
return agent.ManualInstall(config, options)
|
|
||||||
|
return agent.ManualInstall(config, options, c.Bool("strict-validation"))
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -402,12 +403,47 @@ See also https://kairos.io/after_install/reset_mode/ for documentation.
|
|||||||
|
|
||||||
This command is meant to be used from the boot GRUB menu, but can likely be used standalone`,
|
This command is meant to be used from the boot GRUB menu, but can likely be used standalone`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "validate",
|
||||||
|
Action: func(c *cli.Context) error {
|
||||||
|
config := c.Args().First()
|
||||||
|
return agent.Validate(config)
|
||||||
|
},
|
||||||
|
Usage: "Validates a cloud config file",
|
||||||
|
Description: `
|
||||||
|
The validate command expects a configuration file as its only argument. Local files and URLs are accepted.
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "print-schema",
|
||||||
|
Action: func(c *cli.Context) error {
|
||||||
|
|
||||||
|
json, err := agent.JSONSchema(common.VERSION)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(json)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
Usage: "Print out Kairos' Cloud Configuration JSON Schema",
|
||||||
|
Description: `Prints out Kairos' Cloud Configuration JSON Schema`,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
bus.Manager.Initialize()
|
bus.Manager.Initialize()
|
||||||
|
|
||||||
app := &cli.App{
|
app := &cli.App{
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "strict-validation",
|
||||||
|
Usage: "Fail instead of warn on validation errors.",
|
||||||
|
EnvVars: []string{"STRICT_VALIDATIONS"},
|
||||||
|
},
|
||||||
|
},
|
||||||
Name: "kairos-agent",
|
Name: "kairos-agent",
|
||||||
Version: common.VERSION,
|
Version: common.VERSION,
|
||||||
Authors: []*cli.Author{
|
Authors: []*cli.Author{
|
||||||
|
Loading…
Reference in New Issue
Block a user