8000 cli: debug: various improvements by Nirusu · Pull Request #995 · edgelesssys/constellation · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

cli: debug: various improvements #995

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

Merged
merged 21 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
5ac011e
cli: debug: %s -> %q / %v
Nirusu Jan 17, 2023
ede4581
cli: debug: add service account URI debug log message back but withou…
Nirusu Jan 17, 2023
a61d58d
cli: debug: node-endpoint flag
Nirusu Jan 17, 2023
7034c79
Revert "cli: debug: %s -> %q / %v"
Nirusu Jan 17, 2023
7741da5
ci: debug: let's try that again with the %q's
Nirusu Jan 17, 2023
33f6ec5
ci: debug: err.Error() -> err
Nirusu Jan 17, 2023
ca45372
cli: debug: use %v for URLs
Nirusu Jan 18, 2023
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
16 changes: 8 additions & 8 deletions cli/internal/cmd/configfetchmeasurements.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ func (cfm *configFetchMeasurementsCmd) configFetchMeasurements(
fileHandler file.Handler, client *http.Client,
) error {
flags, err := cfm.parseFetchMeasurementsFlags(cmd)
cfm.log.Debugf("Using flags %v", flags)
if err != nil {
return err
}
cfm.log.Debugf("Using flags %v", flags)

cfm.log.Debugf("Loading config file from %s", flags.configPath)
cfm.log.Debugf("Loading configuration file from %q", flags.configPath)
conf, err := config.New(fileHandler, flags.configPath)
if err != nil {
return displayConfigValidationErrors(cmd.ErrOrStderr(), err)
Expand Down Expand Up @@ -117,7 +117,7 @@ func (cfm *configFetchMeasurementsCmd) configFetchMeasurements(
cmd.PrintErrln("Make sure the downloaded measurements are trustworthy!")
}

cfm.log.Debugf("Verified measurements with Rekor, updating measurements in config")
cfm.log.Debugf("Verified measurements with Rekor, updating measurements in configuration")
conf.UpdateMeasurements(fetchedMeasurements)
if err := fileHandler.WriteYAML(flags.configPath, conf, file.OptOverwrite); err != nil {
return err
Expand All @@ -133,9 +133,9 @@ func (cfm *configFetchMeasurementsCmd) parseURLFlag(cmd *cobra.Command, flag str
if err != nil {
return nil, fmt.Errorf("parsing config generate flags '%s': %w", flag, err)
}
cfm.log.Debugf("Flag %s has raw URL %s", flag, rawURL)
cfm.log.Debugf("Flag %s has raw URL %q", flag, rawURL)
if rawURL != "" {
cfm.log.Debugf("Parsing raw URL %s", rawURL)
cfm.log.Debugf("Parsing raw URL")
return url.Parse(rawURL)
}
return nil, nil
Expand All @@ -146,19 +146,19 @@ func (cfm *configFetchMeasurementsCmd) parseFetchMeasurementsFlags(cmd *cobra.Co
if err != nil {
return &fetchMeasurementsFlags{}, err
}
cfm.log.Debugf("Parsed measurements URL")
cfm.log.Debugf("Parsed measurements URL as %v", measurementsURL)

measurementsSignatureURL, err := cfm.parseURLFlag(cmd, "signature-url")
if err != nil {
return &fetchMeasurementsFlags{}, err
}
cfm.log.Debugf("Parsed measurements signature URL")
cfm.log.Debugf("Parsed measurements signature URL as %v", measurementsSignatureURL)

config, err := cmd.Flags().GetString("config")
if err != nil {
return &fetchMeasurementsFlags{}, fmt.Errorf("parsing config path argument: %w", err)
}
cfm.log.Debugf("Config path is %s", config)
cfm.log.Debugf("Configuration path is %q", config)

return &fetchMeasurementsFlags{
measurementsURL: measurementsURL,
Expand Down
16 changes: 8 additions & 8 deletions cli/internal/cmd/create.go
8000
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func runCreate(cmd *cobra.Command, args []string) error {
return fmt.Errorf("creating logger: %w", err)
}
defer log.Sync()
spinner, err := newSpinnerOrStdout(cmd)
spinner, err := newSpinnerOrStderr(cmd)
if err != nil {
return fmt.Errorf("creating spinner: %w", err)
}
Expand All @@ -72,7 +72,7 @@ func (c *createCmd) create(cmd *cobra.Command, creator cloudCreator, fileHandler
return err
}

c.log.Debugf("Loading config file from %s", flags.configPath)
c.log.Debugf("Loading configuration file from %q", flags.configPath)
conf, err := config.New(fileHandler, flags.configPath)
if err != nil {
return displayConfigValidationErrors(cmd.ErrOrStderr(), err)
Expand Down Expand Up @@ -124,7 +124,7 @@ func (c *createCmd) create(cmd *cobra.Command, creator cloudCreator, fileHandler
cpus := conf.Provider.QEMU.VCPUs
instanceType = fmt.Sprintf("%d-vCPU", cpus)
}
c.log.Debugf("Configured with instance type %s", instanceType)
c.log.Debugf("Configured with instance type %q", instanceType)

if !flags.yes {
// Ask user to confirm action.
Expand Down Expand Up @@ -160,28 +160,28 @@ func (c *createCmd) create(cmd *cobra.Command, creator cloudCreator, fileHandler
// parseCreateFlags parses the flags of the create command.
func (c *createCmd) parseCreateFlags(cmd *cobra.Command) (createFlags, error) {
controllerCount, err := cmd.Flags().GetInt("control-plane-nodes")
c.log. 8000 Debugf("Control-plane nodes flag is %d", controllerCount)
if err != nil {
return createFlags{}, fmt.Errorf("parsing number of control-plane nodes: %w", err)
}
c.log.Debugf("Control-plane nodes flag is %d", controllerCount)
if controllerCount < constants.MinControllerCount {
return createFlags{}, fmt.Errorf("number of control-plane nodes must be at least %d", constants.MinControllerCount)
}

workerCount, err := cmd.Flags().GetInt("worker-nodes")
c.log.Debugf("Worker nodes falg is %d", workerCount)
if err != nil {
return createFlags{}, fmt.Errorf("parsing number of worker nodes: %w", err)
}
c.log.Debugf("Worker nodes flag is %d", workerCount)
if workerCount < constants.MinWorkerCount {
return createFlags{}, fmt.Errorf("number of worker nodes must be at least %d", constants.MinWorkerCount)
}

name, err := cmd.Flags().GetString("name")
c.log.Debugf("Name flag is %s", name)
if err != nil {
return createFlags{}, fmt.Errorf("parsing name argument: %w", err)
}
c.log.Debugf("Name flag is %q", name)
if len(name) > constants.ConstellationNameLength {
return createFlags{}, fmt.Errorf(
"name for Constellation cluster too long, maximum length is %d, got %d: %s",
Expand All @@ -190,16 +190,16 @@ func (c *createCmd) parseCreateFlags(cmd *cobra.Command) (createFlags, error) {
}

yes, err := cmd.Flags().GetBool("yes")
c.log.Debugf("Yes flag is %t", yes)
if err != nil {
return createFlags{}, fmt.Errorf("%w; Set '-yes' without a value to automatically confirm", err)
}
c.log.Debugf("Yes flag is %t", yes)

configPath, err := cmd.Flags().GetString("config")
c.log.Debugf("Config path flag is %s", configPath)
if err != nil {
return createFlags{}, fmt.Errorf("parsing config path argument: %w", err)
}
c.log.Debugf("Configuration path flag is %q", configPath)

return createFlags{
controllerCount: controllerCount,
Expand Down
40 changes: 25 additions & 15 deletions cli/internal/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ func runInitialize(cmd *cobra.Command, args []string) error {
return dialer.New(nil, validator.V(cmd), &net.Dialer{})
}

spinner := newSpinner(cmd.ErrOrStderr())
spinner, err := newSpinnerOrStderr(cmd)
if err != nil {
return err
}
defer spinner.Stop()

ctx, cancel := context.WithTimeout(cmd.Context(), time.Hour)
Expand All @@ -88,7 +91,7 @@ func (i *initCmd) initialize(cmd *cobra.Command, newDialer func(validator *cloud
return err
}
i.log.Debugf("Using flags: %+v", flags)
i.log.Debugf("Loading config file from %s", flags.configPath)
i.log.Debugf("Loading configuration file from %q", flags.configPath)
conf, err := config.New(fileHandler, flags.configPath)
if err != nil {
return displayConfigValidationErrors(cmd.ErrOrStderr(), err)
Expand Down Expand Up @@ -125,16 +128,15 @@ func (i *initCmd) initialize(cmd *cobra.Command, newDialer func(validator *cloud
if err != nil {
return err
}
i.log.Debugf("Got service account uri %s", serviceAccURI)
i.log.Debugf("Loading master secret file from %s", flags.masterSecretPath)
i.log.Debugf("Successfully marshaled service account URI")
masterSecret, err := i.readOrGenerateMasterSecret(cmd.OutOrStdout(), fileHandler, flags.masterSecretPath)
if err != nil {
return fmt.Errorf("parsing or generating master secret from file %s: %w", flags.masterSecretPath, err)
}
helmLoader := helm.NewLoader(provider, k8sVersion)
i.log.Debugf("Created new helm loader")
i.log.Debugf("Created new Helm loader")
helmDeployments, err := helmLoader.Load(conf, flags.conformance, masterSecret.Key, masterSecret.Salt)
i.log.Debugf("Loaded helm heployments")
i.log.Debugf("Loaded Helm heployments")
if err != nil {
return fmt.Errorf("loading Helm charts: %w", err)
}
Expand All @@ -158,7 +160,6 @@ func (i *initCmd) initialize(cmd *cobra.Command, newDialer func(validator *cloud
}
i.log.Debugf("Sending initialization request")
resp, err := i.initCall(cmd.Context(), newDialer(validator), idFile.IP, req)
i.log.Debugf("Got initialization response")
spinner.Stop()
if err != nil {
var nonRetriable *nonRetriableError
Expand All @@ -168,7 +169,8 @@ func (i *initCmd) initialize(cmd *cobra.Command, newDialer func(validator *cloud
}
return err
}
i.log.Debugf("Writing Constellation id file")
i.log.Debugf("Initialization request succeeded")
i.log.Debugf("Writing Constellation ID file")
idFile.CloudProvider = provider
if err := i.writeOutput(idFile, resp, cmd.OutOrStdout(), fileHandler); err != nil {
return err
Expand All @@ -184,8 +186,16 @@ func (i *initCmd) initCall(ctx context.Context, dialer grpcDialer, ip string, re
req: req,
log: i.log,
}

// Create a wrapper function that allows logging any returned error from the retrier before checking if it's the expected retriable one.
serviceIsUnavailable := func(err error) bool {
isServiceUnavailable := grpcRetry.ServiceIsUnavailable(err)
i.log.Debugf("Encountered error (retriable: %t): %s", isServiceUnavailable, err)
return isServiceUnavailable
}

i.log.Debugf("Making initialization call, doer is %+v", doer)
retrier := retry.NewIntervalRetrier(doer, 30*time.Second, grpcRetry.ServiceIsUnavailable)
retrier := retry.NewIntervalRetrier(doer, 30*time.Second, serviceIsUnavailable)
if err := retrier.Do(ctx); err != nil {
return nil, err
}
Expand Down Expand Up @@ -221,7 +231,7 @@ func (i *initCmd) writeOutput(idFile clusterid.File, resp *initproto.InitRespons
fmt.Fprint(wr, "Your Constellation cluster was successfully initialized.\n\n")

ownerID := hex.EncodeToString(resp.OwnerId)
i.log.Debugf("Owner id is %s", ownerID)
// i.log.Debugf("Owner id is %s", ownerID)
clusterID := hex.EncodeToString(resp.ClusterId)

tw := tabwriter.NewWriter(wr, 0, 0, 2, ' ', 0)
Expand Down Expand Up @@ -256,20 +266,20 @@ func writeRow(wr io.Writer, col1 string, col2 string) {
// reading the content from file path flags and deriving other values from flag combinations.
func (i *initCmd) evalFlagArgs(cmd *cobra.Command) (initFlags, error) {
masterSecretPath, err := cmd.Flags().GetString("master-secret")
i.log.Debugf("Master secret path flag value is %s", masterSecretPath)
if err != nil {
return initFlags{}, fmt.Errorf("parsing master-secret path flag: %w", err)
}
i.log.Debugf("Master secret path flag value is %q", masterSecretPath)
conformance, err := cmd.Flags().GetBool("conformance")
i.log.Debugf("Conformance flag is %t", conformance)
if err != nil {
return initFlags{}, fmt.Errorf("parsing autoscale flag: %w", err)
return initFlags{}, fmt.Errorf("parsing conformance flag: %w", err)
}
i.log.Debugf("Conformance flag is %t", conformance)
configPath, err := cmd.Flags().GetString("config")
i.log.Debugf("Config path flag is %s", conformance)
if err != nil {
return initFlags{}, fmt.Errorf("parsing config path flag: %w", err)
}
i.log.Debugf("Configuration path flag is %q", configPath)

return initFlags{
configPath: configPath,
Expand All @@ -294,7 +304,7 @@ type masterSecret struct {
// readOrGenerateMasterSecret reads a base64 encoded master secret from file or generates a new 32 byte secret.
func (i *initCmd) readOrGenerateMasterSecret(outWriter io.Writer, fileHandler file.Handler, filename string) (masterSecret, error) {
if filename != "" {
i.log.Debugf("Reading master secret from file")
i.log.Debugf("Reading master secret from file %q", filename)
var secret masterSecret
if err := fileHandler.ReadJSON(filename, &secret); err != nil {
return masterSecret{}, err
Expand Down
13 changes: 8 additions & 5 deletions cli/internal/cmd/miniup.go
10000
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ func runUp(cmd *cobra.Command, args []string) error {
return fmt.Errorf("creating logger: %w", err)
}
defer log.Sync()
spinner := newSpinner(cmd.ErrOrStderr())
spinner, err := newSpinnerOrStderr(cmd)
if err != nil {
return err
}
defer spinner.Stop()
creator := cloudcmd.NewCreator(spinner)

Expand All @@ -76,7 +79,7 @@ func (m *miniUpCmd) up(cmd *cobra.Command, creator cloudCreator, spinner spinner
if err != nil {
return fmt.Errorf("preparing config: %w", err)
}
m.log.Debugf("Prepared config")
m.log.Debugf("Prepared configuration")

// create cluster
spinner.Start("Creating cluster in QEMU ", false)
Expand Down Expand Up @@ -171,7 +174,7 @@ func (m *miniUpCmd) checkSystemRequirements(out io.Writer) error {

// prepareConfig reads a given config, or creates a new minimal QEMU config.
func (m *miniUpCmd) prepareConfig(cmd *cobra.Command, fileHandler file.Handler) (*config.Config, error) {
m.log.Debugf("Preparing config")
m.log.Debugf("Preparing configuration")
configPath, err := cmd.Flags().GetString("config")
if err != nil {
return nil, err
Expand All @@ -187,7 +190,7 @@ func (m *miniUpCmd) prepareConfig(cmd *cobra.Command, fileHandler file.Handler)
}
return conf, nil
}
m.log.Debugf("Config path is %s", configPath)
m.log.Debugf("Configuration path is %q", configPath)
if err := cmd.Flags().Set("config", constants.ConfigFilename); err != nil {
return nil, err
}
Expand All @@ -207,7 +210,7 @@ func (m *miniUpCmd) prepareConfig(cmd *cobra.Command, fileHandler file.Handler)
config := config.Default()
config.RemoveProviderExcept(cloudprovider.QEMU)
config.StateDiskSizeGB = 8
m.log.Debugf("Prepared config")
m.log.Debugf("Prepared configuration")

return config, fileHandler.WriteYAML(constants.ConfigFilename, config, file.OptOverwrite)
}
Expand Down
20 changes: 11 additions & 9 deletions cli/internal/cmd/recover.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (r *recoverCmd) recover(
return err
}

r.log.Debugf("Loading configuration file from %s", flags.configPath)
r.log.Debugf("Loading configuration file from %q", flags.configPath)
conf, err := config.New(fileHandler, flags.configPath)
if err != nil {
return displayConfigValidationErrors(cmd.ErrOrStderr(), err)
Expand Down Expand Up @@ -119,17 +119,19 @@ func (r *recoverCmd) recoverCall(ctx context.Context, out io.Writer, interval ti
for {
once := sync.Once{}
retryOnceOnFailure := func(err error) bool {
var retry bool
// retry transient GCP LB errors
if grpcRetry.LoadbalancerIsNotReady(err) {
return true
retry = true
} else {
// retry connection errors once
// this is necessary because Azure's LB takes a while to remove unhealthy instances
once.Do(func() {
retry = grpcRetry.ServiceIsUnavailable(err)
})
}
retry := false

// retry connection errors once
// this is necessary because Azure's LB takes a while to remove unhealthy instances
once.Do(func() {
retry = grpcRetry.ServiceIsUnavailable(err)
})
r.log.Debugf("Encountered error (retriable: %t): %s", retry, err)
return retry
}

Expand Down Expand Up @@ -268,7 +270,7 @@ func (r *recoverCmd) parseRecoverFlags(cmd *cobra.Command, fileHandler file.Hand
if err != nil {
return recoverFlags{}, fmt.Errorf("parsing config path argument: %w", err)
}
r.log.Debugf("Config path flag is %s", configPath)
r.log.Debugf("Configuration path flag is %s", configPath)

return recoverFlags{
endpoint: endpoint,
Expand Down
2 changes: 1 addition & 1 deletion cli/internal/cmd/spinner.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type spinner struct {
spinFunc func(out io.Writer, wg *sync.WaitGroup, stop *atomic.Bool, delay time.Duration, text string, showDots bool)
}

func newSpinnerOrStdout(cmd *cobra.Command) (spinnerInterf, error) {
func newSpinnerOrStderr(cmd *cobra.Command) (spinnerInterf, error) {
debug, err := cmd.Flags().GetBool("debug")
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions cli/internal/cmd/upgradeplan.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (up *upgradePlanCmd) upgradePlan(cmd *cobra.Command, planner upgradePlanner
if err != nil {
return displayConfigValidationErrors(cmd.ErrOrStderr(), err)
}
up.log.Debugf("Read config from %s", flags.configPath)
up.log.Debugf("Read configuration from %q", flags.configPath)
// get current image version of the cluster
csp := conf.GetProvider()
up.log.Debugf("Using provider %s", csp.String())
Expand Down Expand Up @@ -140,7 +140,7 @@ func (up *upgradePlanCmd) upgradePlan(cmd *cobra.Command, planner upgradePlanner

// filter out versions that are not compatible with the current cluster
compatibleImages := getCompatibleImages(version, updateCandidates)
up.log.Debugf("Of those images, these ones are compaitble %v", compatibleImages)
up.log.Debugf("Of those images, these ones are compatible %v", compatibleImages)

// get expected measurements for each image
upgrades, err := getCompatibleImageMeasurements(cmd.Context(), cmd, client, rekor, []byte(flags.cosignPubKey), csp, compatibleImages)
Expand Down
Loading
0