Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
janelletavares committed Feb 8, 2022
1 parent c817d63 commit ef6a1fe
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 32 deletions.
12 changes: 9 additions & 3 deletions cmd/meroxa/root/environments/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,17 @@ func (c *Create) Execute(ctx context.Context) error {
}

if environment.Status.State == meroxa.EnvironmentStatePreflightError {
details := utils.PrettyString(environment.Status.PreflightDetails)
c.logger.Errorf(ctx, "Environment %q could not be provisioned because it failed the preflight checks\n%s\n", environment.Name, details)
details, _ := utils.PrettyString(environment.Status.PreflightDetails)
c.logger.Errorf(ctx,
"Environment %q could not be provisioned because it failed the preflight checks\n%s\n",
environment.Name,
details)
} else {
environment.Status.PreflightDetails = nil
c.logger.Infof(ctx, "Preflight checks have passed. Environment %q is being provisioned. Run `meroxa env describe %s` for status", environment.Name, environment.Name)
c.logger.Infof(ctx,
"Preflight checks have passed. Environment %q is being provisioned. Run `meroxa env describe %s` for status",
environment.Name,
environment.Name)
}

c.logger.JSON(ctx, environment)
Expand Down
33 changes: 13 additions & 20 deletions cmd/meroxa/root/environments/repair.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,28 +86,21 @@ func (r *Repair) Execute(ctx context.Context) error {

state := rr.Status.State
name := rr.Name
if rr != nil && state == meroxa.EnvironmentStatePreflightError {
log := fmt.Sprintf("Environment %q could not be repaired because it failed the preflight checks.", name)
details := utils.PrettyString(rr.Status.PreflightDetails)
if details != "" && details != "null" {
log += fmt.Sprintf("\n%s\n", details)
if state == meroxa.EnvironmentStatePreflightError {
text := fmt.Sprintf("Environment %q could not be repaired because it failed the preflight checks.", name)
if details, err := utils.PrettyString(rr.Status.PreflightDetails); err == nil {
text += fmt.Sprintf("\n%s\n", details)
}
r.logger.Errorf(ctx, log)
} else if rr != nil && (state != meroxa.EnvironmentStateRepairing && state != meroxa.EnvironmentStateReady) {
log := fmt.Sprintf("Environment %q could not be repaired.", r.args.NameOrUUID)
details := utils.PrettyString(rr.Status.Details)
if details != "" && details != "null" {
log += fmt.Sprintf("\n%s\n", details)
}
switch state {
case meroxa.EnvironmentStateRepairingError:
case meroxa.EnvironmentStateUpdatingError:
case meroxa.EnvironmentStateProvisioningError:
case meroxa.EnvironmentStateDeprovisioningError:
r.logger.Infof(ctx, log)
}
} else {
r.logger.Errorf(ctx, text)
} else if state == meroxa.EnvironmentStateRepairing || state == meroxa.EnvironmentStateReady {
r.logger.Infof(ctx, `The repairment of your environment %q is now in progress and your environment will be up and running soon.`, r.args.NameOrUUID) // nolint:lll
} else if state == meroxa.EnvironmentStateRepairingError || state == meroxa.EnvironmentStateUpdatingError ||
state == meroxa.EnvironmentStateProvisioningError || state == meroxa.EnvironmentStateDeprovisioningError {
text := fmt.Sprintf("Environment %q could not be repaired.", r.args.NameOrUUID)
if details, err := utils.PrettyString(rr.Status.Details); err == nil {
text += fmt.Sprintf("\n%s\n", details)
}
r.logger.Infof(ctx, text)
}
r.logger.Infof(ctx, `Run "meroxa env describe %s" for status.`, r.args.NameOrUUID)
r.logger.JSON(ctx, rr)
Expand Down
9 changes: 6 additions & 3 deletions cmd/meroxa/root/environments/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,12 @@ func (c *Update) Execute(ctx context.Context) error {
}

state := environment.Status.State
if environment != nil && state == meroxa.EnvironmentStateUpdatingError {
details := utils.PrettyString(environment.Status.Details)
c.logger.Infof(ctx, "Environment %q could not be updated:\n%s\n", c.args.NameOrUUID, details)
if state == meroxa.EnvironmentStateUpdatingError {
text := fmt.Sprintf("Environment %q could not be updated.", c.args.NameOrUUID)
if details, err := utils.PrettyString(environment.Status.Details); err == nil {
text += fmt.Sprintf("\n%s\n", details)
}
c.logger.Infof(ctx, text)
} else {
c.logger.Infof(ctx, "Environment %q has been updated. Run `meroxa env describe %s` for status", environment.Name, environment.Name)
}
Expand Down
16 changes: 10 additions & 6 deletions utils/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ func EnvironmentsTable(environments []*meroxa.Environment, hideHeaders bool) str
return ""
}

// nolint:funlen
func EnvironmentTable(environment *meroxa.Environment) string {
mainTable := simpletable.New()

Expand Down Expand Up @@ -720,15 +721,15 @@ func EnvironmentTable(environment *meroxa.Environment) string {
},
{
{Align: simpletable.AlignRight, Text: "AWS EIP Limits Status:"},
{Text: string(environment.Status.PreflightDetails.PreflightLimits.EIP)},
{Text: environment.Status.PreflightDetails.PreflightLimits.EIP},
},
{
{Align: simpletable.AlignRight, Text: "AWS NAT Limits Status:"},
{Text: string(environment.Status.PreflightDetails.PreflightLimits.NAT)},
{Text: environment.Status.PreflightDetails.PreflightLimits.NAT},
},
{
{Align: simpletable.AlignRight, Text: "AWS VPC Limits Status:"},
{Text: string(environment.Status.PreflightDetails.PreflightLimits.VPC)},
{Text: environment.Status.PreflightDetails.PreflightLimits.VPC},
},
}
preflightTable.SetStyle(simpletable.StyleCompact)
Expand All @@ -752,10 +753,13 @@ func truncateString(oldString string, l int) string {
return str
}

func PrettyString(a interface{}) string {
func PrettyString(a interface{}) (string, error) {
j, err := json.MarshalIndent(a, "", " ")
if err != nil {
return ""
return "", err
}
if string(j) == "null" {
return "", fmt.Errorf("unsuccessful marshal indent")
}
return string(j)
return string(j), nil
}

0 comments on commit ef6a1fe

Please sign in to comment.