Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load elemental config/spec from cloud config #82

Merged
merged 7 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

func LoadConfig(path ...string) (*Config, error) {
if len(path) == 0 {
path = append(path, "/etc/kairos/agent.yaml", "/etc/elemental/config.yaml")
path = append(path, "/etc/kairos/agent.yaml")

Check warning on line 34 in internal/agent/config.go

View check run for this annotation

Codecov / codecov/patch

internal/agent/config.go#L34

Added line #L34 was not covered by tests
}

cfg := &Config{}
Expand Down
8 changes: 6 additions & 2 deletions internal/agent/hooks/runstage.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ import (

type RunStage struct{}

func (r RunStage) Run(_ config.Config) error {
cfg, err := elementalConfig.ReadConfigRun("/etc/elemental")
func (r RunStage) Run(c config.Config) error {
cc, err := c.String()
if err != nil {
return err
}
cfg, err := elementalConfig.ReadConfigRunFromCloudConfig(cc)
if err != nil {
cfg.Logger.Errorf("Error reading config: %s\n", err)
}
Expand Down
34 changes: 18 additions & 16 deletions internal/agent/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
"syscall"
"time"

events "github.com/kairos-io/kairos-sdk/bus"
"github.com/kairos-io/kairos-sdk/collector"
"github.com/kairos-io/kairos-sdk/machine"
"github.com/kairos-io/kairos-sdk/utils"
hook "github.com/kairos-io/kairos-agent/v2/internal/agent/hooks"
"github.com/kairos-io/kairos-agent/v2/internal/bus"
"github.com/kairos-io/kairos-agent/v2/internal/cmd"
Expand All @@ -23,6 +19,10 @@
"github.com/kairos-io/kairos-agent/v2/pkg/elementalConfig"
v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1"
elementalUtils "github.com/kairos-io/kairos-agent/v2/pkg/utils"
events "github.com/kairos-io/kairos-sdk/bus"
"github.com/kairos-io/kairos-sdk/collector"
"github.com/kairos-io/kairos-sdk/machine"
"github.com/kairos-io/kairos-sdk/utils"
qr "github.com/mudler/go-nodepair/qrcode"
"github.com/mudler/go-pluggable"
"github.com/pterm/pterm"
Expand Down Expand Up @@ -96,13 +96,10 @@
}
}
}

// Load the installation Config from the system
installConfig, err := elementalConfig.ReadConfigRun("/etc/elemental")
installConfig, err := elementalConfig.ReadConfigRunFromCloudConfig(configStr)

Check warning on line 99 in internal/agent/install.go

View check run for this annotation

Codecov / codecov/patch

internal/agent/install.go#L99

Added line #L99 was not covered by tests
if err != nil {
return err
}

return RunInstall(installConfig, options)
}

Expand Down Expand Up @@ -130,12 +127,6 @@

ensureDataSourceReady()

// Load the installation Config from the system
installConfig, err := elementalConfig.ReadConfigRun("/etc/elemental")
if err != nil {
return err
}

// Reads config, and if present and offline is defined,
// runs the installation
cc, err := config.Scan(collector.Directories(dir...), collector.MergeBootLine, collector.NoLogs)
Expand All @@ -148,6 +139,12 @@
r["device"] = cc.Install.Device
mergeOption(configStr, r)

// Load the installation Config from the system
installConfig, err := elementalConfig.ReadConfigRunFromCloudConfig(configStr)
if err != nil {
return err
}

Check warning on line 146 in internal/agent/install.go

View check run for this annotation

Codecov / codecov/patch

internal/agent/install.go#L142-L146

Added lines #L142 - L146 were not covered by tests

err = RunInstall(installConfig, r)
if err != nil {
return err
Expand Down Expand Up @@ -240,6 +237,12 @@

r["cc"] = config.AddHeader(header, string(out))

// Load the installation Config from the system
installConfig, err := elementalConfig.ReadConfigRunFromCloudConfig(r["cc"])
if err != nil {
return err
}

Check warning on line 244 in internal/agent/install.go

View check run for this annotation

Codecov / codecov/patch

internal/agent/install.go#L240-L244

Added lines #L240 - L244 were not covered by tests

pterm.Info.Println("Starting installation")

if err := RunInstall(installConfig, r); err != nil {
Expand Down Expand Up @@ -302,8 +305,7 @@
}

// Generate the installation spec
installSpec, _ := elementalConfig.ReadInstallSpec(installConfig)

installSpec, _ := elementalConfig.ReadInstallSpecFromCloudConfig(installConfig)

Check warning on line 308 in internal/agent/install.go

View check run for this annotation

Codecov / codecov/patch

internal/agent/install.go#L308

Added line #L308 was not covered by tests
installSpec.NoFormat = c.Install.NoFormat

// Set our cloud-init to the file we just created
Expand Down
4 changes: 2 additions & 2 deletions internal/agent/interactive_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@
// Set debug from here already, so it's loaded by the ReadConfigRun
viper.Set("debug", debug)

// Load the installation Config from the system
installConfig, err := elementalConfig.ReadConfigRun("/etc/elemental")
// Load the installation Config from the cloud-config data
installConfig, err := elementalConfig.ReadConfigRunFromCloudConfig(finalCloudConfig)

Check warning on line 284 in internal/agent/interactive_install.go

View check run for this annotation

Codecov / codecov/patch

internal/agent/interactive_install.go#L283-L284

Added lines #L283 - L284 were not covered by tests
if err != nil {
return err
}
Expand Down
21 changes: 12 additions & 9 deletions internal/agent/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@
import (
"encoding/json"
"fmt"
"github.com/sanity-io/litter"
"github.com/sirupsen/logrus"
"os"
"sync"
"time"

sdk "github.com/kairos-io/kairos-sdk/bus"
"github.com/kairos-io/kairos-sdk/collector"
"github.com/kairos-io/kairos-sdk/machine"
"github.com/kairos-io/kairos-sdk/utils"
hook "github.com/kairos-io/kairos-agent/v2/internal/agent/hooks"
"github.com/kairos-io/kairos-agent/v2/internal/bus"
"github.com/kairos-io/kairos-agent/v2/internal/cmd"
"github.com/kairos-io/kairos-agent/v2/pkg/action"
"github.com/kairos-io/kairos-agent/v2/pkg/config"
"github.com/kairos-io/kairos-agent/v2/pkg/elementalConfig"
sdk "github.com/kairos-io/kairos-sdk/bus"
"github.com/kairos-io/kairos-sdk/collector"
"github.com/kairos-io/kairos-sdk/machine"
"github.com/kairos-io/kairos-sdk/utils"

"github.com/mudler/go-pluggable"
"github.com/pterm/pterm"
Expand All @@ -43,7 +42,6 @@

// This loads yet another config ¬_¬
// TODO: merge this somehow with the rest so there is no 5 places to configure stuff?
// Also this reads the elemental config.yaml
agentConfig, err := LoadConfig()
if err != nil {
return err
Expand Down Expand Up @@ -83,15 +81,20 @@

utils.SetEnv(c.Env)

resetConfig, err := elementalConfig.ReadConfigRun("/etc/elemental")
cc, err := c.String()
if err != nil {
return err
}

Check warning on line 87 in internal/agent/reset.go

View check run for this annotation

Codecov / codecov/patch

internal/agent/reset.go#L84-L87

Added lines #L84 - L87 were not covered by tests
// Load the installation Config from the cloud-config data
resetConfig, err := elementalConfig.ReadConfigRunFromCloudConfig(cc)

Check warning on line 89 in internal/agent/reset.go

View check run for this annotation

Codecov / codecov/patch

internal/agent/reset.go#L89

Added line #L89 was not covered by tests
if err != nil {
return err
}

if debug {
resetConfig.Logger.SetLevel(logrus.DebugLevel)
}
resetConfig.Logger.Debugf("Full config: %s\n", litter.Sdump(resetConfig))
resetSpec, err := elementalConfig.ReadResetSpec(resetConfig)
resetSpec, err := elementalConfig.ReadResetSpecFromCloudConfig(resetConfig)

Check warning on line 97 in internal/agent/reset.go

View check run for this annotation

Codecov / codecov/patch

internal/agent/reset.go#L97

Added line #L97 was not covered by tests
if err != nil {
return err
}
Expand Down
17 changes: 9 additions & 8 deletions internal/agent/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@
"fmt"

"github.com/Masterminds/semver/v3"
events "github.com/kairos-io/kairos-sdk/bus"
"github.com/kairos-io/kairos-sdk/collector"
"github.com/kairos-io/kairos-sdk/utils"
"github.com/kairos-io/kairos-agent/v2/internal/bus"
"github.com/kairos-io/kairos-agent/v2/pkg/action"
"github.com/kairos-io/kairos-agent/v2/pkg/config"
"github.com/kairos-io/kairos-agent/v2/pkg/elementalConfig"
"github.com/kairos-io/kairos-agent/v2/pkg/github"
v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1"
events "github.com/kairos-io/kairos-sdk/bus"
"github.com/kairos-io/kairos-sdk/collector"
"github.com/kairos-io/kairos-sdk/utils"
"github.com/mudler/go-pluggable"
"github.com/sanity-io/litter"
log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -102,18 +101,20 @@
utils.SetEnv(c.Env)

// Load the upgrade Config from the system
upgradeConfig, err := elementalConfig.ReadConfigRun("/etc/elemental")
cc, err := c.String()
if err != nil {
return err
}
upgradeConfig, err := elementalConfig.ReadConfigRunFromCloudConfig(cc)

Check warning on line 108 in internal/agent/upgrade.go

View check run for this annotation

Codecov / codecov/patch

internal/agent/upgrade.go#L104-L108

Added lines #L104 - L108 were not covered by tests
if err != nil {
return err
}
if debug {
upgradeConfig.Logger.SetLevel(log.DebugLevel)
}

upgradeConfig.Logger.Debugf("Full config: %s\n", litter.Sdump(upgradeConfig))

// Generate the upgrade spec
upgradeSpec, _ := elementalConfig.ReadUpgradeSpec(upgradeConfig)
upgradeSpec, _ := elementalConfig.ReadUpgradeSpecFromCloudConfig(upgradeConfig)

Check warning on line 117 in internal/agent/upgrade.go

View check run for this annotation

Codecov / codecov/patch

internal/agent/upgrade.go#L117

Added line #L117 was not covered by tests
// Add the image source
imgSource, err := v1.NewSrcFromURI(img)
if err != nil {
Expand Down
22 changes: 19 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/kairos-io/kairos-agent/v2/pkg/utils"
"os"
"path/filepath"
"regexp"
Expand All @@ -17,7 +18,6 @@ import (
"github.com/kairos-io/kairos-agent/v2/pkg/config"
"github.com/kairos-io/kairos-agent/v2/pkg/elementalConfig"
v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1"
"github.com/kairos-io/kairos-agent/v2/pkg/utils"
"github.com/kairos-io/kairos-sdk/bundles"
"github.com/kairos-io/kairos-sdk/collector"
"github.com/kairos-io/kairos-sdk/machine"
Expand Down Expand Up @@ -535,7 +535,15 @@ The validate command expects a configuration file as its only argument. Local fi
},
Action: func(c *cli.Context) error {
stage := c.Args().First()
cfg, err := elementalConfig.ReadConfigRun("/etc/elemental")
config, err := config.Scan(collector.Directories(configScanDir...), collector.NoLogs)
if err != nil {
return err
}
cc, err := config.String()
if err != nil {
return err
}
cfg, err := elementalConfig.ReadConfigRunFromCloudConfig(cc)
Itxaka marked this conversation as resolved.
Show resolved Hide resolved
cfg.Strict = c.Bool("strict")

if len(c.StringSlice("cloud-init-paths")) > 0 {
Expand Down Expand Up @@ -582,7 +590,15 @@ The validate command expects a configuration file as its only argument. Local fi
if err != nil {
return fmt.Errorf("invalid path %s", destination)
}
cfg, err := elementalConfig.ReadConfigRun("/etc/elemental")
config, err := config.Scan(collector.Directories(configScanDir...), collector.NoLogs)
if err != nil {
return err
}
cc, err := config.String()
if err != nil {
return err
}
cfg, err := elementalConfig.ReadConfigRunFromCloudConfig(cc)
Itxaka marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
const (
GrubConf = "/etc/cos/grub.cfg"
GrubOEMEnv = "grub_oem_env"
GrubDefEntry = "cOS"
GrubDefEntry = "Kairos"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About time....

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😓 haha indeed, nice!

DefaultTty = "tty1"
BiosPartName = "bios"
EfiLabel = "COS_GRUB"
Expand Down
Loading