Skip to content

Commit

Permalink
Prepare to fix the empty config write
Browse files Browse the repository at this point in the history
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
  • Loading branch information
kke committed May 17, 2024
1 parent 7b922ea commit 4c95741
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions phase/configure_k0s.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ func (p *ConfigureK0s) Prepare(config *v1beta1.Cluster) error {
log.Debug("using provided k0s config")
p.configSource = configSourceProvided
p.newBaseConfig = p.Config.Spec.K0s.Config.Dup()
} else if p.leader.Metadata.K0sExistingConfig != "" {
log.Debug("using existing k0s config")
p.configSource = configSourceExisting
p.newBaseConfig = make(dig.Mapping)
err := yaml.Unmarshal([]byte(p.leader.Metadata.K0sExistingConfig), &p.newBaseConfig)
if err != nil {
return fmt.Errorf("failed to unmarshal existing k0s config: %w", err)
}
} else {
log.Debug("using generated default k0s config")
p.configSource = configSourceDefault
Expand Down Expand Up @@ -231,8 +223,8 @@ func (p *ConfigureK0s) configureK0s(h *cluster.Host) error {
}
}

log.Debugf("%s: writing k0s configuration", h)
tempConfigPath, err := h.Configurer.TempFile(h)
log.Debugf("%s: writing %d bytes of k0s configuration to %v", h, len(h.Metadata.K0sNewConfig), tempConfigPath)
if err != nil {
return fmt.Errorf("failed to create temporary file for config: %w", err)
}
Expand All @@ -241,11 +233,12 @@ func (p *ConfigureK0s) configureK0s(h *cluster.Host) error {
return err
}

log.Infof("%s: installing new configuration", h)
configPath := h.K0sConfigPath()
log.Infof("%s: installing new configuration to %v", h, configPath)
configDir := gopath.Dir(configPath)

if !h.Configurer.FileExist(h, configDir) {
log.Infof("%s: creating k0s configuration directory %v", h, configDir)
if err := h.Execf(`install -m 0750 -o root -g root -d "%s"`, configDir, exec.Sudo(h)); err != nil {
return fmt.Errorf("failed to create k0s configuration directory: %w", err)
}
Expand Down

0 comments on commit 4c95741

Please sign in to comment.