Skip to content

Commit

Permalink
Merge pull request #246 from meroxa/preflight_cli_changes
Browse files Browse the repository at this point in the history
feat(environments): Preflight cli changes
  • Loading branch information
anna-cross authored Feb 9, 2022
2 parents 8ced680 + b452a7d commit 75e2e88
Show file tree
Hide file tree
Showing 18 changed files with 372 additions and 47 deletions.
24 changes: 17 additions & 7 deletions cmd/meroxa/root/environments/create.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
/*
Copyright © 2021 Meroxa Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -23,8 +20,10 @@ import (
"strings"

"github.com/manifoldco/promptui"

"github.com/meroxa/cli/cmd/meroxa/builder"
"github.com/meroxa/cli/log"
"github.com/meroxa/cli/utils"
"github.com/meroxa/meroxa-go/pkg/meroxa"
)

Expand Down Expand Up @@ -54,7 +53,7 @@ type Create struct {
Type string `long:"type" usage:"environment type, when not specified"`
Provider string `long:"provider" usage:"environment cloud provider to use"`
Region string `long:"region" usage:"environment region"`
Config []string `short:"c" long:"config" usage:"environment configuration based on type and provider (e.g.: --config aws_access_key_id=my_access_key --config aws_access_secret=my_access_secret)"` // nolint:lll
Config []string `short:"c" long:"config" usage:"environment configuration based on type and provider (e.g.: --config aws_access_key_id=my_access_key --config aws_secret_access_key=my_access_secret)"` // nolint:lll
}

envCfg map[string]interface{}
Expand Down Expand Up @@ -134,9 +133,20 @@ func (c *Create) Execute(ctx context.Context) error {
return err
}

c.logger.Infof(ctx, "Environment %q is being provisioned. Run `meroxa env describe %s` for status", environment.Name, environment.Name)
c.logger.JSON(ctx, environment)
if environment.Status.State != meroxa.EnvironmentStatePreflightSuccess {
details := utils.EnvironmentPreflightTable(environment)
c.logger.Errorf(ctx,
"Environment %q could not be provisioned because it failed the preflight checks\n%s\n",
environment.Name,
details)
} else {
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)
return nil
}

Expand Down Expand Up @@ -275,7 +285,7 @@ func (c *Create) Docs() builder.Docs {
return builder.Docs{
Short: "Create an environment",
Example: `
meroxa env create my-env --type self_hosted --provider aws --region us-east-1 --config aws_access_key_id=my_access_key --config aws_access_secret=my_access_secret
meroxa env create my-env --type self_hosted --provider aws --region us-east-1 --config aws_access_key_id=my_access_key --config aws_secret_access_key=my_access_secret
`,
}
}
4 changes: 2 additions & 2 deletions cmd/meroxa/root/environments/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestCreateEnvironmentExecution(t *testing.T) {
Type: e.Type,
Configuration: e.Configuration,
Status: meroxa.EnvironmentViewStatus{
State: meroxa.EnvironmentStateProvisioning,
State: meroxa.EnvironmentStatePreflightSuccess,
},
CreatedAt: time.Time{},
UpdatedAt: time.Time{},
Expand All @@ -153,7 +153,7 @@ func TestCreateEnvironmentExecution(t *testing.T) {

gotLeveledOutput := logger.LeveledOutput()
wantLeveledOutput := fmt.Sprintf("Provisioning environment...\n"+
"Environment %q is being provisioned. Run `meroxa env describe %s` for status", e.Name, e.Name)
"Preflight checks have passed. Environment %q is being provisioned. Run `meroxa env describe %s` for status", e.Name, e.Name)

if !strings.Contains(gotLeveledOutput, wantLeveledOutput) {
t.Fatalf("expected output:\n%s\ngot:\n%s", wantLeveledOutput, gotLeveledOutput)
Expand Down
48 changes: 48 additions & 0 deletions cmd/meroxa/root/environments/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,51 @@ func TestDescribeEnvironmentExecution(t *testing.T) {
t.Fatalf("expected \"%v\", got \"%v\"", e, gotEnvironment)
}
}

func TestDescribeEnvironmentExecutionBadEnv(t *testing.T) {
ctx := context.Background()
ctrl := gomock.NewController(t)
client := mock.NewMockClient(ctrl)
logger := log.NewTestLogger()

environmentName := "my-env-bad"

e := utils.GenerateEnvironmentFailed(environmentName)

client.
EXPECT().
GetEnvironment(
ctx,
e.Name,
).
Return(&e, nil)

dc := &Describe{
client: client,
logger: logger,
}
dc.args.NameOrUUID = e.Name

err := dc.Execute(ctx)
if err != nil {
t.Fatalf("not expected error, got %q", err.Error())
}

gotLeveledOutput := logger.LeveledOutput()
wantLeveledOutput := utils.EnvironmentTable(&e)

if !strings.Contains(gotLeveledOutput, wantLeveledOutput) {
t.Fatalf("expected output:\n%s\ngot:\n%s", wantLeveledOutput, gotLeveledOutput)
}

gotJSONOutput := logger.JSONOutput()
var gotEnvironment meroxa.Environment
err = json.Unmarshal([]byte(gotJSONOutput), &gotEnvironment)
if err != nil {
t.Fatalf("not expected error, got %q", err.Error())
}

if !reflect.DeepEqual(gotEnvironment, e) {
t.Fatalf("expected \"%v\", got \"%v\"", e, gotEnvironment)
}
}
2 changes: 1 addition & 1 deletion cmd/meroxa/root/environments/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestListEnvironmentsExecution(t *testing.T) {
Name: "environment-1234",
Provider: meroxa.EnvironmentProviderAws,
Region: meroxa.EnvironmentRegionUsEast1,
Status: meroxa.EnvironmentViewStatus{State: meroxa.EnvironmentStateProvisioned},
Status: meroxa.EnvironmentViewStatus{State: meroxa.EnvironmentStateReady},
UUID: "531428f7-4e86-4094-8514-d397d49026f7",
}

Expand Down
19 changes: 15 additions & 4 deletions cmd/meroxa/root/environments/repair.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"github.com/meroxa/cli/cmd/meroxa/builder"
"github.com/meroxa/cli/log"
"github.com/meroxa/cli/utils"
"github.com/meroxa/meroxa-go/pkg/meroxa"
)

Expand Down Expand Up @@ -76,14 +77,24 @@ func (r *Repair) ParseArgs(args []string) error {
}

func (r *Repair) Execute(ctx context.Context) error {
rr, err := r.client.PerformActionOnEnvironment(ctx, r.args.NameOrUUID, &meroxa.RepairEnvironmentInput{Action: meroxa.EnvironmentActionRepair}) // nolint:lll
environment, err := r.client.PerformActionOnEnvironment(ctx, r.args.NameOrUUID, &meroxa.RepairEnvironmentInput{Action: meroxa.EnvironmentActionRepair}) // nolint:lll
if err != nil {
return err
}

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
r.logger.Infof(ctx, `Run "meroxa env describe %s" for status.`, r.args.NameOrUUID)
r.logger.JSON(ctx, rr)
if environment.Status.State != meroxa.EnvironmentStatePreflightSuccess {
details := utils.EnvironmentPreflightTable(environment)
r.logger.Errorf(ctx,
"Environment %q could not be repaired because it failed the preflight checks\n%s\n",
environment.Name,
details)
} else {
r.logger.Infof(ctx,
"Preflight checks have passed. Environment %q is being repaired. Run `meroxa env describe %s` for status",
environment.Name,
environment.Name)
}

r.logger.JSON(ctx, environment)
return nil
}
3 changes: 1 addition & 2 deletions cmd/meroxa/root/environments/repair_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ func TestRepairEnvironmentExecution(t *testing.T) {

gotLeveledOutput := logger.LeveledOutput()
wantLeveledOutput := fmt.Sprintf(
`The repairment of your environment %q is now in progress and your environment will be up and running soon.
Run "meroxa env describe %s" for status.`,
"Preflight checks have passed. Environment %q is being repaired. Run `meroxa env describe %s` for status",
e.Name,
e.Name)

Expand Down
17 changes: 15 additions & 2 deletions cmd/meroxa/root/environments/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import (
"fmt"

"github.com/manifoldco/promptui"

"github.com/meroxa/cli/cmd/meroxa/builder"
"github.com/meroxa/cli/log"
"github.com/meroxa/cli/utils"
"github.com/meroxa/meroxa-go/pkg/meroxa"
)

Expand Down Expand Up @@ -109,9 +111,20 @@ func (c *Update) Execute(ctx context.Context) error {
return err
}

c.logger.Infof(ctx, "Environment %q has been updated. Run `meroxa env describe %s` for status", environment.Name, environment.Name)
c.logger.JSON(ctx, environment)
if environment.Status.State != meroxa.EnvironmentStatePreflightSuccess {
details := utils.EnvironmentPreflightTable(environment)
c.logger.Errorf(ctx,
"Environment %q could not be updated because it failed the preflight checks\n%s\n",
environment.Name,
details)
} else {
c.logger.Infof(ctx,
"Preflight checks have passed. Environment %q is being updated. Run `meroxa env describe %s` for status",
environment.Name,
environment.Name)
}

c.logger.JSON(ctx, environment)
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/meroxa/root/environments/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestUpdateEnvironmentExecution(t *testing.T) {

gotLeveledOutput := logger.LeveledOutput()
wantLeveledOutput := fmt.Sprintf(
"Updating environment...\nEnvironment %q has been updated. Run `meroxa env describe %s` for status",
"Updating environment...\nPreflight checks have passed. Environment %q is being updated. Run `meroxa env describe %s` for status",
e.Name,
e.Name)

Expand Down
4 changes: 2 additions & 2 deletions docs/cmd/md/meroxa_environments_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ meroxa environments create NAME [flags]

```
meroxa env create my-env --type self_hosted --provider aws --region us-east-1 --config aws_access_key_id=my_access_key --config aws_access_secret=my_access_secret
meroxa env create my-env --type self_hosted --provider aws --region us-east-1 --config aws_access_key_id=my_access_key --config aws_secret_access_key=my_access_secret
```

### Options

```
-c, --config strings environment configuration based on type and provider (e.g.: --config aws_access_key_id=my_access_key --config aws_access_secret=my_access_secret)
-c, --config strings environment configuration based on type and provider (e.g.: --config aws_access_key_id=my_access_key --config aws_secret_access_key=my_access_secret)
-h, --help help for create
--provider string environment cloud provider to use
--region string environment region
Expand Down
4 changes: 2 additions & 2 deletions docs/cmd/www/meroxa-environments-create.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ meroxa environments create NAME [flags]

```
meroxa env create my-env --type self_hosted --provider aws --region us-east-1 --config aws_access_key_id=my_access_key --config aws_access_secret=my_access_secret
meroxa env create my-env --type self_hosted --provider aws --region us-east-1 --config aws_access_key_id=my_access_key --config aws_secret_access_key=my_access_secret
```

### Options

```
-c, --config strings environment configuration based on type and provider (e.g.: --config aws_access_key_id=my_access_key --config aws_access_secret=my_access_secret)
-c, --config strings environment configuration based on type and provider (e.g.: --config aws_access_key_id=my_access_key --config aws_secret_access_key=my_access_secret)
-h, --help help for create
--provider string environment cloud provider to use
--region string environment region
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/manifoldco/promptui v0.8.0
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-runewidth v0.0.10 // indirect
github.com/meroxa/meroxa-go v0.0.0-20220202200635-942cf1c778a4
github.com/meroxa/meroxa-go v0.0.0-20220208195203-71ddc3133fab
github.com/nirasan/go-oauth-pkce-code-verifier v0.0.0-20170819232839-0fbfe93532da
github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4
github.com/rivo/uniseg v0.2.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ github.com/mattn/go-runewidth v0.0.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRR
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebGE2xrk=
github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y=
github.com/meroxa/meroxa-go v0.0.0-20220202200635-942cf1c778a4 h1:NlyG9imqx9fLuqNFtSSpUajILE45Ms/pAkK/f1AaFw0=
github.com/meroxa/meroxa-go v0.0.0-20220202200635-942cf1c778a4/go.mod h1:HDFszURCM1cOpKE699o5Hs0T2tEIXqY+vFcsur3RiwY=
github.com/meroxa/meroxa-go v0.0.0-20220208195203-71ddc3133fab h1:EzZzmvjyU+U/8ecHt0QmKbJQs4293wms3EeapctnBME=
github.com/meroxa/meroxa-go v0.0.0-20220208195203-71ddc3133fab/go.mod h1:HDFszURCM1cOpKE699o5Hs0T2tEIXqY+vFcsur3RiwY=
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
Expand Down
Binary file added kubectl
Binary file not shown.
Loading

0 comments on commit 75e2e88

Please sign in to comment.