mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-01-23 22:01:14 -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)
|
spinner.Start("Creating", false)
|
||||||
idFile, err := creator.Create(cmd.Context(), provider, conf, flags.name, instanceType, flags.controllerCount, flags.workerCount)
|
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()
|
spinner.Stop()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return translateCreateErrors(cmd, err)
|
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 {
|
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.spinner.Stop()
|
||||||
|
defer iamCreator.log.Sync()
|
||||||
iamCreator.provider = provider
|
iamCreator.provider = provider
|
||||||
iamCreator.providerCreator = providerCreator
|
iamCreator.providerCreator = providerCreator
|
||||||
return iamCreator.create(cmd.Context())
|
return iamCreator.create(cmd.Context())
|
||||||
@ -154,16 +158,23 @@ func createRunIAMFunc(provider cloudprovider.Provider) func(cmd *cobra.Command,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// newIAMCreator creates a new iamiamCreator.
|
// newIAMCreator creates a new iamiamCreator.
|
||||||
func newIAMCreator(cmd *cobra.Command) *iamCreator {
|
func newIAMCreator(cmd *cobra.Command) (*iamCreator, error) {
|
||||||
spinner := newSpinner(cmd.ErrOrStderr())
|
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{
|
return &iamCreator{
|
||||||
cmd: cmd,
|
cmd: cmd,
|
||||||
spinner: spinner,
|
spinner: spinner,
|
||||||
|
log: log,
|
||||||
creator: cloudcmd.NewIAMCreator(spinner),
|
creator: cloudcmd.NewIAMCreator(spinner),
|
||||||
fileHandler: file.NewHandler(afero.NewOsFs()),
|
fileHandler: file.NewHandler(afero.NewOsFs()),
|
||||||
iamConfig: &cloudcmd.IAMConfig{},
|
iamConfig: &cloudcmd.IAMConfig{},
|
||||||
}
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// iamCreator is the iamCreator for the iam create command.
|
// iamCreator is the iamCreator for the iam create command.
|
||||||
@ -175,6 +186,7 @@ type iamCreator struct {
|
|||||||
provider cloudprovider.Provider
|
provider cloudprovider.Provider
|
||||||
providerCreator providerIAMCreator
|
providerCreator providerIAMCreator
|
||||||
iamConfig *cloudcmd.IAMConfig
|
iamConfig *cloudcmd.IAMConfig
|
||||||
|
log debugLog
|
||||||
}
|
}
|
||||||
|
|
||||||
// create IAM configuration on the iamCreator's cloud provider.
|
// create IAM configuration on the iamCreator's cloud provider.
|
||||||
@ -183,6 +195,7 @@ func (c *iamCreator) create(ctx context.Context) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
c.log.Debugf("Using flags: %+v", flags)
|
||||||
|
|
||||||
if !flags.yesFlag {
|
if !flags.yesFlag {
|
||||||
c.cmd.Printf("The following IAM configuration will be created:\n\n")
|
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
|
return err
|
||||||
}
|
}
|
||||||
c.cmd.Println() // Print empty line to separate after spinner ended.
|
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)
|
err = c.providerCreator.parseAndWriteIDFile(iamFile, c.fileHandler)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -217,6 +231,7 @@ func (c *iamCreator) create(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if flags.generateConfig {
|
if flags.generateConfig {
|
||||||
|
c.log.Debugf("Writing IAM configuration to %s", flags.configPath)
|
||||||
c.providerCreator.writeOutputValuesToConfig(conf, flags, iamFile)
|
c.providerCreator.writeOutputValuesToConfig(conf, flags, iamFile)
|
||||||
if err := c.fileHandler.WriteYAML(flags.configPath, conf, file.OptMkdirAll); err != nil {
|
if err := c.fileHandler.WriteYAML(flags.configPath, conf, file.OptMkdirAll); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -17,6 +17,7 @@ import (
|
|||||||
"github.com/edgelesssys/constellation/v2/internal/config"
|
"github.com/edgelesssys/constellation/v2/internal/config"
|
||||||
"github.com/edgelesssys/constellation/v2/internal/constants"
|
"github.com/edgelesssys/constellation/v2/internal/constants"
|
||||||
"github.com/edgelesssys/constellation/v2/internal/file"
|
"github.com/edgelesssys/constellation/v2/internal/file"
|
||||||
|
"github.com/edgelesssys/constellation/v2/internal/logger"
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@ -246,6 +247,7 @@ func TestIAMCreateAWS(t *testing.T) {
|
|||||||
|
|
||||||
iamCreator := &iamCreator{
|
iamCreator := &iamCreator{
|
||||||
cmd: cmd,
|
cmd: cmd,
|
||||||
|
log: logger.NewTest(t),
|
||||||
spinner: &nopSpinner{},
|
spinner: &nopSpinner{},
|
||||||
creator: tc.creator,
|
creator: tc.creator,
|
||||||
fileHandler: fileHandler,
|
fileHandler: fileHandler,
|
||||||
@ -469,6 +471,7 @@ func TestIAMCreateAzure(t *testing.T) {
|
|||||||
|
|
||||||
iamCreator := &iamCreator{
|
iamCreator := &iamCreator{
|
||||||
cmd: cmd,
|
cmd: cmd,
|
||||||
|
log: logger.NewTest(t),
|
||||||
spinner: &nopSpinner{},
|
spinner: &nopSpinner{},
|
||||||
creator: tc.creator,
|
creator: tc.creator,
|
||||||
fileHandler: fileHandler,
|
fileHandler: fileHandler,
|
||||||
@ -716,6 +719,7 @@ func TestIAMCreateGCP(t *testing.T) {
|
|||||||
|
|
||||||
iamCreator := &iamCreator{
|
iamCreator := &iamCreator{
|
||||||
cmd: cmd,
|
cmd: cmd,
|
||||||
|
log: logger.NewTest(t),
|
||||||
spinner: &nopSpinner{},
|
spinner: &nopSpinner{},
|
||||||
creator: tc.creator,
|
creator: tc.creator,
|
||||||
fileHandler: fileHandler,
|
fileHandler: fileHandler,
|
||||||
|
Loading…
Reference in New Issue
Block a user