Skip to content

Commit

Permalink
Merge pull request #562 from kairos-io/split-yip-config-dirs
Browse files Browse the repository at this point in the history
Split yip config dirs from user config dirs
  • Loading branch information
jimmykarily authored Sep 26, 2024
2 parents 99e8509 + d3c864c commit cd5ab69
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
20 changes: 10 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ See https://kairos.io/docs/upgrade/manual/ for documentation.
}

return agent.Upgrade(source, c.Bool("force"),
c.Bool("strict-validation"), constants.GetConfigScanDirs(),
c.Bool("strict-validation"), constants.GetUserConfigDirs(),
upgradeEntry, c.Bool("pre"),
)
},
Expand Down Expand Up @@ -327,7 +327,7 @@ 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{"c"},
Action: func(c *cli.Context) error {
config, err := agentConfig.Scan(collector.Directories(constants.GetConfigScanDirs()...), collector.NoLogs)
config, err := agentConfig.Scan(collector.Directories(constants.GetUserConfigDirs()...), collector.NoLogs)
if err != nil {
return err
}
Expand All @@ -346,7 +346,7 @@ E.g. kairos-agent install-bundle container:quay.io/kairos/kairos...
Description: "WARNING this command will be deprecated in v3.2.0. Use `config` without a subcommand instead.\n\n 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{},
Action: func(c *cli.Context) error {
config, err := agentConfig.Scan(collector.Directories(constants.GetConfigScanDirs()...), collector.NoLogs)
config, err := agentConfig.Scan(collector.Directories(constants.GetUserConfigDirs()...), collector.NoLogs)
if err != nil {
return err
}
Expand Down Expand Up @@ -375,7 +375,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 := agentConfig.ScanNoLogs(collector.Directories(constants.GetConfigScanDirs()...), collector.NoLogs, collector.StrictValidation(c.Bool("strict-validation")))
config, err := agentConfig.ScanNoLogs(collector.Directories(constants.GetUserConfigDirs()...), collector.NoLogs, collector.StrictValidation(c.Bool("strict-validation")))
if err != nil {
return err
}
Expand Down Expand Up @@ -446,7 +446,7 @@ enabled: true`,
},
Action: func(c *cli.Context) error {

config, err := agentConfig.ScanNoLogs(collector.Directories(constants.GetConfigScanDirs()...), collector.NoLogs, collector.StrictValidation(c.Bool("strict-validation")))
config, err := agentConfig.ScanNoLogs(collector.Directories(constants.GetUserConfigDirs()...), collector.NoLogs, collector.StrictValidation(c.Bool("strict-validation")))
if err != nil {
return err
}
Expand Down Expand Up @@ -556,7 +556,7 @@ This command is meant to be used from the boot GRUB menu, but can be started man
Action: func(c *cli.Context) error {
source := c.String("source")

return agent.Install(source, constants.GetConfigScanDirs()...)
return agent.Install(source, constants.GetUserConfigDirs()...)
},
},
{
Expand Down Expand Up @@ -600,7 +600,7 @@ This command is meant to be used from the boot GRUB menu, but can likely be used
unattended := c.Bool("unattended")
resetOem := c.Bool("reset-oem")

return agent.Reset(reboot, unattended, resetOem, constants.GetConfigScanDirs()...)
return agent.Reset(reboot, unattended, resetOem, constants.GetUserConfigDirs()...)
},
Usage: "Starts kairos reset mode",
Description: `
Expand Down Expand Up @@ -684,7 +684,7 @@ The validate command expects a configuration file as its only argument. Local fi
},
Action: func(c *cli.Context) error {
stage := c.Args().First()
config, err := agentConfig.Scan(collector.Directories(constants.GetConfigScanDirs()...), collector.NoLogs)
config, err := agentConfig.Scan(collector.Directories(constants.GetYipConfigDirs()...), collector.NoLogs)
config.Strict = c.Bool("strict")

if len(c.StringSlice("cloud-init-paths")) > 0 {
Expand Down Expand Up @@ -730,7 +730,7 @@ The validate command expects a configuration file as its only argument. Local fi
if err != nil {
return fmt.Errorf("invalid path %s", destination)
}
config, err := agentConfig.Scan(collector.Directories(constants.GetConfigScanDirs()...), collector.NoLogs)
config, err := agentConfig.Scan(collector.Directories(constants.GetUserConfigDirs()...), collector.NoLogs)
if err != nil {
return err
}
Expand Down Expand Up @@ -784,7 +784,7 @@ The validate command expects a configuration file as its only argument. Local fi
return checkRoot()
},
Action: func(c *cli.Context) error {
cfg, err := agentConfig.Scan(collector.Directories(constants.GetConfigScanDirs()...), collector.NoLogs)
cfg, err := agentConfig.Scan(collector.Directories(constants.GetUserConfigDirs()...), collector.NoLogs)
if err != nil {
return err
}
Expand Down
19 changes: 15 additions & 4 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,25 @@ func GetGrubModules() []string {
return []string{"loopback.mod", "squash4.mod", "xzio.mod", "gzio.mod", "regexp.mod"}
}

func GetConfigScanDirs() []string {
// GetYipConfigDirs returns all the directories where "yip" configuration might
// live. These include the directories were we store our system overlay files:
// https://github.com/kairos-io/packages/tree/main/packages/static/kairos-overlay-files/files/system/oem
func GetYipConfigDirs() []string {
return append(GetUserConfigDirs(), "/system/oem")
}

// GetUserConfigDirs returns all the directories that might have configuration
// supplied by the user. They are in an order which allows the users to override
// baked-in configuration (e.g. in livecd, under /run/initramfs/live) with
// configuration coming from datasource (e.g. a datasource cdrom, written under /oem).
// That's why writable paths are last.
func GetUserConfigDirs() []string {
return []string{
"/oem",
"/system/oem",
"/usr/local/cloud-config",
"/run/initramfs/live",
"/etc/kairos", // Default system configuration file https://github.com/kairos-io/kairos/issues/2221
"/etc/elemental", // for backwards compatibility
"/usr/local/cloud-config",
"/oem",
}
}

Expand Down

0 comments on commit cd5ab69

Please sign in to comment.