Skip to content

Commit

Permalink
Use k0s config create/validate instead of the deprecated subcommands (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kke committed Jan 5, 2022
1 parent 610682e commit 79d76aa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -445,4 +445,4 @@ The version of k0s to deploy. When left out, k0sctl will default to using the la

Embedded k0s cluster configuration. See [k0s configuration documentation](https://docs.k0sproject.io/main/configuration/) for details.

When left out, the output of `k0s default-config` will be used.
When left out, the output of `k0s config create` will be used.
17 changes: 15 additions & 2 deletions phase/configure_k0s.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ func (p *ConfigureK0s) Run() error {
p.SetProp("default-config", true)
leader := p.Config.Spec.K0sLeader()
log.Warnf("%s: generating default configuration", leader)
cfg, err := leader.ExecOutput(leader.Configurer.K0sCmdf("default-config"), exec.Sudo(leader))

var cmd string
if leader.Exec(leader.Configurer.K0sCmdf("config create --help"), exec.Sudo(leader)) == nil {
cmd = leader.Configurer.K0sCmdf("config create")
}

cfg, err := leader.ExecOutput(cmd, exec.Sudo(leader))
if err != nil {
return err
}
Expand All @@ -47,7 +53,14 @@ func (p *ConfigureK0s) Run() error {

func (p *ConfigureK0s) validateConfig(h *cluster.Host) error {
log.Infof("%s: validating configuration", h)
output, err := h.ExecOutput(h.Configurer.K0sCmdf(`validate config --config "%s"`, h.K0sConfigPath()), exec.Sudo(h))
var cmd string
if h.Exec(h.Configurer.K0sCmdf("config validate --help"), exec.Sudo(h)) == nil {
cmd = h.Configurer.K0sCmdf(`config validate --config "%s"`, h.K0sConfigPath())
} else {
cmd = h.Configurer.K0sCmdf(`validate config --config "%s"`, h.K0sConfigPath())
}

output, err := h.ExecOutput(cmd, exec.Sudo(h))
if err != nil {
return fmt.Errorf("spec.k0s.config fails validation:\n%s", output)
}
Expand Down

0 comments on commit 79d76aa

Please sign in to comment.