Skip to content

Commit

Permalink
Attempt a fix for #1460
Browse files Browse the repository at this point in the history
This is ugly and hackish. We pass the provider's cloud config to the
collector so that it's is included in the `r["cc"]` that we pass to
the `RunInstall` method. That's what is uses as a cloud config.

Ideally, we should consolidate all those configurations and the
RunInstall should only take one argument which will be a struct that
holds all the information on how to perform the installation. This
refactoring will happen separately. This is just a quick fix for the
bug.

kairos-io/kairos#1460

Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
  • Loading branch information
jimmykarily committed May 30, 2023
1 parent ef1d464 commit a53d8a0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
13 changes: 12 additions & 1 deletion internal/agent/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ func Install(debug bool, dir ...string) error {
}
})

providerCC := ""
if cc, ok := r["cc"]; ok {
providerCC = config.AddHeader("#cloud-config", cc)
}

ensureDataSourceReady()

// Load the installation Config from the system
Expand All @@ -138,12 +143,18 @@ func Install(debug bool, dir ...string) error {

// Reads config, and if present and offline is defined,
// runs the installation
cc, err := config.Scan(collector.Directories(dir...), collector.MergeBootLine, collector.NoLogs)
cc, err := config.Scan(
collector.Directories(dir...),
collector.WithConfig(providerCC),
collector.MergeBootLine,
collector.NoLogs)
if err == nil && cc.Install != nil && cc.Install.Auto {
configStr, err := cc.String()
if err != nil {
return err
}
// This overwrites the original `cc` that was sent by the provider
// but we already merged that back using the collector.
r["cc"] = configStr
r["device"] = cc.Install.Device
mergeOption(configStr, r)
Expand Down
16 changes: 16 additions & 0 deletions pkg/config/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ func Scan(o *Options, filter func(d []byte) ([]byte, error)) (*Config, error) {
configs := Configs{}

configs = append(configs, parseFiles(o.ScanDir, o.NoLogs)...)
configs = append(configs, parseDirectConfigs(o.DirectConfigs, o.NoLogs)...)

if o.MergeBootCMDLine {
cConfig, err := ParseCmdLine(o.BootCMDLineFile, filter)
Expand All @@ -255,6 +256,21 @@ func allFiles(dir []string) []string {
return files
}

func parseDirectConfigs(configStrings []string, nologs bool) Configs {
result := Configs{}

for _, s := range configStrings {
var newConfig Config
err := yaml.Unmarshal([]byte(s), &newConfig)
if err != nil && !nologs {
fmt.Printf("warning: failed to parse direct config:\n%s\n", err.Error())
}
result = append(result, &newConfig)
}

return result
}

// parseFiles returns a list of Configs parsed from files.
func parseFiles(dir []string, nologs bool) Configs {
result := Configs{}
Expand Down
10 changes: 9 additions & 1 deletion pkg/config/collector/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package collector
import "fmt"

type Options struct {
ScanDir []string
ScanDir []string // Directories in which to look up cloud config files
DirectConfigs []string // Cloud configs defined as plain string (not files)
BootCMDLineFile string
MergeBootCMDLine bool
NoLogs bool
Expand Down Expand Up @@ -61,3 +62,10 @@ func Directories(d ...string) Option {
return nil
}
}

func WithConfig(s string) Option {
return func(o *Options) error {
o.DirectConfigs = append(o.DirectConfigs, s)
return nil
}
}

0 comments on commit a53d8a0

Please sign in to comment.