From 2d4f82bb3f4e9c9c639b5f942e4a0c24cd622ef4 Mon Sep 17 00:00:00 2001 From: danj-replicated Date: Tue, 9 Jan 2024 16:19:46 +0000 Subject: [PATCH 1/5] add basic config command --- cmd/embedded-cluster/config.go | 65 ++++++++++++++++++++++++++++++++++ cmd/embedded-cluster/main.go | 1 + 2 files changed, 66 insertions(+) create mode 100644 cmd/embedded-cluster/config.go diff --git a/cmd/embedded-cluster/config.go b/cmd/embedded-cluster/config.go new file mode 100644 index 000000000..92b992a50 --- /dev/null +++ b/cmd/embedded-cluster/config.go @@ -0,0 +1,65 @@ +package main + +import ( + "fmt" + "os" + + "github.com/urfave/cli/v2" + "gopkg.in/yaml.v2" + + "github.com/replicatedhq/embedded-cluster/pkg/addons" + "github.com/replicatedhq/embedded-cluster/pkg/config" +) + +var configCommand = &cli.Command{ + Name: "config", + Usage: "Dumps generated config to stdout", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "overrides", + Usage: "File with an EmbeddedClusterConfig object to override the default configuration", + Hidden: true, + }, + &cli.BoolFlag{ + Name: "no-prompt", + Usage: "Do not prompt user when it is not necessary", + Value: false, + }, + }, + Action: func(c *cli.Context) error { + multi := false + + cfg, err := config.RenderClusterConfig(c.Context, multi) + if err != nil { + return fmt.Errorf("unable to render config: %w", err) + } + + if c.String("overrides") != "" { + eucfg, err := parseEndUserConfig(c.String("overrides")) + if err != nil { + return fmt.Errorf("unable to process overrides file: %w", err) + } + if err := config.ApplyEmbeddedUnsupportedOverrides( + cfg, eucfg.Spec.UnsupportedOverrides.K0s, + ); err != nil { + return fmt.Errorf("unable to apply overrides: %w", err) + } + } + opts := []addons.Option{} + if c.Bool("no-prompt") { + opts = append(opts, addons.WithoutPrompt()) + } + for _, addon := range c.StringSlice("disable-addon") { + opts = append(opts, addons.WithoutAddon(addon)) + } + if err := config.UpdateHelmConfigs(cfg, opts...); err != nil { + return fmt.Errorf("unable to update helm configs: %w", err) + } + + if err := yaml.NewEncoder(os.Stdout).Encode(cfg); err != nil { + return fmt.Errorf("unable to write config file: %w", err) + } + + return nil + }, +} diff --git a/cmd/embedded-cluster/main.go b/cmd/embedded-cluster/main.go index 2d42293ac..80a55f32d 100644 --- a/cmd/embedded-cluster/main.go +++ b/cmd/embedded-cluster/main.go @@ -37,6 +37,7 @@ func main() { shellCommand, nodeCommands, versionCommand, + configCommand, }, } if err := app.Run(os.Args); err != nil { From 923659686c8dfb2f8100491c6e4c5ab4c8b7c9e0 Mon Sep 17 00:00:00 2001 From: danj-replicated Date: Tue, 9 Jan 2024 16:25:33 +0000 Subject: [PATCH 2/5] fmt --- cmd/embedded-cluster/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/embedded-cluster/main.go b/cmd/embedded-cluster/main.go index 80a55f32d..723c2d763 100644 --- a/cmd/embedded-cluster/main.go +++ b/cmd/embedded-cluster/main.go @@ -37,7 +37,7 @@ func main() { shellCommand, nodeCommands, versionCommand, - configCommand, + configCommand, }, } if err := app.Run(os.Args); err != nil { From 2341490965dea27d4da1191ac410eb5ccd1b83b0 Mon Sep 17 00:00:00 2001 From: danj-replicated Date: Wed, 10 Jan 2024 09:35:22 +0000 Subject: [PATCH 3/5] fix overrides --- cmd/embedded-cluster/config.go | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/cmd/embedded-cluster/config.go b/cmd/embedded-cluster/config.go index 92b992a50..b23ea9faa 100644 --- a/cmd/embedded-cluster/config.go +++ b/cmd/embedded-cluster/config.go @@ -33,18 +33,6 @@ var configCommand = &cli.Command{ if err != nil { return fmt.Errorf("unable to render config: %w", err) } - - if c.String("overrides") != "" { - eucfg, err := parseEndUserConfig(c.String("overrides")) - if err != nil { - return fmt.Errorf("unable to process overrides file: %w", err) - } - if err := config.ApplyEmbeddedUnsupportedOverrides( - cfg, eucfg.Spec.UnsupportedOverrides.K0s, - ); err != nil { - return fmt.Errorf("unable to apply overrides: %w", err) - } - } opts := []addons.Option{} if c.Bool("no-prompt") { opts = append(opts, addons.WithoutPrompt()) @@ -55,7 +43,9 @@ var configCommand = &cli.Command{ if err := config.UpdateHelmConfigs(cfg, opts...); err != nil { return fmt.Errorf("unable to update helm configs: %w", err) } - + if err := applyUnsupportedOverrides(c, cfg); err != nil { + return fmt.Errorf("unable to apply unsupported overrides: %w", err) + } if err := yaml.NewEncoder(os.Stdout).Encode(cfg); err != nil { return fmt.Errorf("unable to write config file: %w", err) } From 8d112bcef92a056135859d0a6fc8d946371504c7 Mon Sep 17 00:00:00 2001 From: danj-replicated Date: Wed, 10 Jan 2024 10:23:45 +0000 Subject: [PATCH 4/5] format --- cmd/embedded-cluster/config.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/embedded-cluster/config.go b/cmd/embedded-cluster/config.go index b23ea9faa..33eb2d3ac 100644 --- a/cmd/embedded-cluster/config.go +++ b/cmd/embedded-cluster/config.go @@ -43,9 +43,9 @@ var configCommand = &cli.Command{ if err := config.UpdateHelmConfigs(cfg, opts...); err != nil { return fmt.Errorf("unable to update helm configs: %w", err) } - if err := applyUnsupportedOverrides(c, cfg); err != nil { - return fmt.Errorf("unable to apply unsupported overrides: %w", err) - } + if err := applyUnsupportedOverrides(c, cfg); err != nil { + return fmt.Errorf("unable to apply unsupported overrides: %w", err) + } if err := yaml.NewEncoder(os.Stdout).Encode(cfg); err != nil { return fmt.Errorf("unable to write config file: %w", err) } From a30aabea961ee2694ce435ec94d8c155e4bcf36d Mon Sep 17 00:00:00 2001 From: danj-replicated Date: Wed, 10 Jan 2024 12:32:25 +0000 Subject: [PATCH 5/5] disable workflow cacheing --- .github/workflows/pull-request.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/pull-request.yaml b/.github/workflows/pull-request.yaml index fcd013e09..a5e5ab531 100644 --- a/.github/workflows/pull-request.yaml +++ b/.github/workflows/pull-request.yaml @@ -12,6 +12,7 @@ jobs: uses: actions/setup-go@v5 with: go-version: "1.21.0" + cache: false - name: Go vet run: | make vet @@ -29,6 +30,7 @@ jobs: uses: actions/setup-go@v5 with: go-version: "1.21.0" + cache: false - name: Go vet run: | make vet @@ -56,6 +58,7 @@ jobs: uses: actions/setup-go@v5 with: go-version: "1.21.0" + cache: false - name: Build Linux AMD64 run: | make embedded-cluster-linux-amd64 VERSION=dev-$SHORT_SHA