mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-01-23 13:51:06 -05:00
cli: add debug logging to iam create command (#1127)
* AB#2787 add debug logging to iam create command * AB#2787 add test logger * AB#2787 reword log * separate debug output with empty line Co-authored-by: Daniel Weiße <66256922+daniel-weisse@users.noreply.github.com> --------- Co-authored-by: Daniel Weiße <66256922+daniel-weisse@users.noreply.github.com>
This commit is contained in:
parent
8b7979c500
commit
e01ddc08c2
@ -143,7 +143,7 @@ func (c *createCmd) create(cmd *cobra.Command, creator cloudCreator, fileHandler
|
||||
|
||||
spinner.Start("Creating", false)
|
||||
idFile, err := creator.Create(cmd.Context(), provider, conf, flags.name, instanceType, flags.controllerCount, flags.workerCount)
|
||||
c.log.Debugf("Create command generated idFile")
|
||||
c.log.Debugf("Successfully created the cloud resources for the cluster")
|
||||
spinner.Stop()
|
||||
if err != nil {
|
||||
return translateCreateErrors(cmd, err)
|
||||
|
@ -145,8 +145,12 @@ func createRunIAMFunc(provider cloudprovider.Provider) func(cmd *cobra.Command,
|
||||
}
|
||||
}
|
||||
return func(cmd *cobra.Command, args []string) error {
|
||||
iamCreator := newIAMCreator(cmd)
|
||||
iamCreator, err := newIAMCreator(cmd)
|
||||
if err != nil {
|
||||
return fmt.Errorf("creating iamCreator: %w", err)
|
||||
}
|
||||
defer iamCreator.spinner.Stop()
|
||||
defer iamCreator.log.Sync()
|
||||
iamCreator.provider = provider
|
||||
iamCreator.providerCreator = providerCreator
|
||||
return iamCreator.create(cmd.Context())
|
||||
@ -154,16 +158,23 @@ func createRunIAMFunc(provider cloudprovider.Provider) func(cmd *cobra.Command,
|
||||
}
|
||||
|
||||
// newIAMCreator creates a new iamiamCreator.
|
||||
func newIAMCreator(cmd *cobra.Command) *iamCreator {
|
||||
spinner := newSpinner(cmd.ErrOrStderr())
|
||||
|
||||
func newIAMCreator(cmd *cobra.Command) (*iamCreator, error) {
|
||||
spinner, err := newSpinnerOrStderr(cmd)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("creating spinner: %w", err)
|
||||
}
|
||||
log, err := newCLILogger(cmd)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("creating logger: %w", err)
|
||||
}
|
||||
return &iamCreator{
|
||||
cmd: cmd,
|
||||
spinner: spinner,
|
||||
log: log,
|
||||
creator: cloudcmd.NewIAMCreator(spinner),
|
||||
fileHandler: file.NewHandler(afero.NewOsFs()),
|
||||
iamConfig: &cloudcmd.IAMConfig{},
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
// iamCreator is the iamCreator for the iam create command.
|
||||
@ -175,6 +186,7 @@ type iamCreator struct {
|
||||
provider cloudprovider.Provider
|
||||
providerCreator providerIAMCreator
|
||||
iamConfig *cloudcmd.IAMConfig
|
||||
log debugLog
|
||||
}
|
||||
|
||||
// create IAM configuration on the iamCreator's cloud provider.
|
||||
@ -183,6 +195,7 @@ func (c *iamCreator) create(ctx context.Context) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.log.Debugf("Using flags: %+v", flags)
|
||||
|
||||
if !flags.yesFlag {
|
||||
c.cmd.Printf("The following IAM configuration will be created:\n\n")
|
||||
@ -210,6 +223,7 @@ func (c *iamCreator) create(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
c.cmd.Println() // Print empty line to separate after spinner ended.
|
||||
c.log.Debugf("Successfully created the IAM cloud resources")
|
||||
|
||||
err = c.providerCreator.parseAndWriteIDFile(iamFile, c.fileHandler)
|
||||
if err != nil {
|
||||
@ -217,6 +231,7 @@ func (c *iamCreator) create(ctx context.Context) error {
|
||||
}
|
||||
|
||||
if flags.generateConfig {
|
||||
c.log.Debugf("Writing IAM configuration to %s", flags.configPath)
|
||||
c.providerCreator.writeOutputValuesToConfig(conf, flags, iamFile)
|
||||
if err := c.fileHandler.WriteYAML(flags.configPath, conf, file.OptMkdirAll); err != nil {
|
||||
return err
|
||||
|
@ -17,6 +17,7 @@ import (
|
||||
"github.com/edgelesssys/constellation/v2/internal/config"
|
||||
"github.com/edgelesssys/constellation/v2/internal/constants"
|
||||
"github.com/edgelesssys/constellation/v2/internal/file"
|
||||
"github.com/edgelesssys/constellation/v2/internal/logger"
|
||||
"github.com/spf13/afero"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -246,6 +247,7 @@ func TestIAMCreateAWS(t *testing.T) {
|
||||
|
||||
iamCreator := &iamCreator{
|
||||
cmd: cmd,
|
||||
log: logger.NewTest(t),
|
||||
spinner: &nopSpinner{},
|
||||
creator: tc.creator,
|
||||
fileHandler: fileHandler,
|
||||
@ -469,6 +471,7 @@ func TestIAMCreateAzure(t *testing.T) {
|
||||
|
||||
iamCreator := &iamCreator{
|
||||
cmd: cmd,
|
||||
log: logger.NewTest(t),
|
||||
spinner: &nopSpinner{},
|
||||
creator: tc.creator,
|
||||
fileHandler: fileHandler,
|
||||
@ -716,6 +719,7 @@ func TestIAMCreateGCP(t *testing.T) {
|
||||
|
||||
iamCreator := &iamCreator{
|
||||
cmd: cmd,
|
||||
log: logger.NewTest(t),
|
||||
spinner: &nopSpinner{},
|
||||
creator: tc.creator,
|
||||
fileHandler: fileHandler,
|
||||
|
Loading…
Reference in New Issue
Block a user