sparkles: Custom partitioning refactor config (#1180)

* Introduce config/collector package

to split the collection of config sources out of the config package.

Each consumer of the new package will take care of unmarshalling the
yaml to a specific Config struct, do validations etc.

* Add tests and remove garbage
* Follow all config_url chains and test it
* Add missing options file and refactor cmdline code
* Consolidate the way we merge configs no matter where they come from
* Allow and use only files with valid headers

Config is  specific to Kairos while Collector is generic. This
will allow us to do validations which are just related to Kairos at the
config level, while including every type of key and querying of the full
yaml at the Collector level splitting the responsibilities of each
package.

---------

Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com>
Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
This commit is contained in:
Mauro Morales 2023-03-29 16:25:38 +02:00 committed by Itxaka
parent 994c21fdc6
commit 582d84c1c7

View File

@ -15,6 +15,7 @@ import (
"github.com/kairos-io/kairos-sdk/utils"
"github.com/kairos-io/kairos/internal/common"
"github.com/kairos-io/kairos/pkg/config"
"github.com/kairos-io/kairos/pkg/config/collector"
"github.com/urfave/cli/v2"
)
@ -224,12 +225,16 @@ E.g. kairos-agent install-bundle container:quay.io/kairos/kairos...
Description: "Show the runtime configuration of the machine. It will scan the machine for all the configuration and will return the config file processed and found.",
Aliases: []string{"s"},
Action: func(c *cli.Context) error {
config, err := config.Scan(config.Directories(configScanDir...), config.NoLogs)
config, err := config.Scan(collector.Directories(configScanDir...), collector.NoLogs)
if err != nil {
return err
}
fmt.Printf("%s", config.String())
configStr, err := config.String()
if err != nil {
return err
}
fmt.Printf("%s", configStr)
return nil
},
},
@ -249,7 +254,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",
Aliases: []string{"g"},
Action: func(c *cli.Context) error {
config, err := config.Scan(config.Directories(configScanDir...), config.NoLogs, config.StrictValidation(c.Bool("strict-validation")))
config, err := config.Scan(collector.Directories(configScanDir...), collector.NoLogs, collector.StrictValidation(c.Bool("strict-validation")))
if err != nil {
return err
}