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(nodeadm): add nodeadm config dump command #2107

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
47 changes: 47 additions & 0 deletions nodeadm/cmd/nodeadm/config/dump.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package config

import (
"encoding/json"
"os"

"github.com/awslabs/amazon-eks-ami/nodeadm/internal/cli"
"github.com/awslabs/amazon-eks-ami/nodeadm/internal/configprovider"
"github.com/integrii/flaggy"
"go.uber.org/zap"
)

type dumpCmd struct {
cmd *flaggy.Subcommand
}

func NewDumpCommand() cli.Command {
cmd := flaggy.NewSubcommand("dump")
cmd.Description = "Dump configuration"
return &dumpCmd{
cmd: cmd,
}
}

func (c *dumpCmd) Flaggy() *flaggy.Subcommand {
return c.cmd
}

func (c *dumpCmd) Run(log *zap.Logger, opts *cli.GlobalOptions) error {
log.Info("Dumping configuration", zap.String("source", opts.ConfigSource))
provider, err := configprovider.BuildConfigProvider(opts.ConfigSource)
if err != nil {
return err
}
config, err := provider.Provide()
if err != nil {
return err
}

encoder := json.NewEncoder(os.Stdout)
encoder.SetIndent("", " ")
if err = encoder.Encode(config); err != nil {
return err
}
log.Info("Configuration dumped")
return nil
}
1 change: 1 addition & 0 deletions nodeadm/cmd/nodeadm/config/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ import (
func NewConfigCommand() cli.Command {
container := cli.NewCommandContainer("config", "Manage configuration")
container.AddCommand(NewCheckCommand())
container.AddCommand(NewDumpCommand())
return container.AsCommand()
}