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

feat: add basic config command #253

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 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
65 changes: 65 additions & 0 deletions cmd/embedded-cluster/config.go
Original file line number Diff line number Diff line change
@@ -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 {
danj-replicated marked this conversation as resolved.
Show resolved Hide resolved
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
},
}
1 change: 1 addition & 0 deletions cmd/embedded-cluster/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func main() {
shellCommand,
nodeCommands,
versionCommand,
configCommand,
},
}
if err := app.Run(os.Args); err != nil {
Expand Down
Loading