Skip to content

Add cluster name/region flags to the CLI #1492

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 6 commits into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 16 additions & 0 deletions cli/cmd/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ import (
var (
_flagClusterEnv string
_flagClusterConfig string
_flagClusterName string
_flagClusterRegion string
_flagClusterInfoDebug bool
_flagClusterDisallowPrompt bool
_flagAWSAccessKeyID string
Expand All @@ -73,6 +75,8 @@ func clusterInit() {

_infoCmd.Flags().SortFlags = false
addClusterConfigFlag(_infoCmd)
addClusterNameFlag(_infoCmd)
addClusterRegionFlag(_infoCmd)
addAWSCredentialsFlags(_infoCmd)
_infoCmd.Flags().StringVarP(&_flagClusterEnv, "env", "e", defaultEnv, "environment to update")
_infoCmd.Flags().BoolVarP(&_flagClusterInfoDebug, "debug", "d", false, "save the current cluster state to a file")
Expand All @@ -89,12 +93,16 @@ func clusterInit() {

_downCmd.Flags().SortFlags = false
addClusterConfigFlag(_downCmd)
addClusterNameFlag(_downCmd)
addClusterRegionFlag(_downCmd)
addAWSCredentialsFlags(_downCmd)
_downCmd.Flags().BoolVarP(&_flagClusterDisallowPrompt, "yes", "y", false, "skip prompts")
_clusterCmd.AddCommand(_downCmd)

_exportCmd.Flags().SortFlags = false
addClusterConfigFlag(_exportCmd)
addClusterNameFlag(_exportCmd)
addClusterRegionFlag(_exportCmd)
addAWSCredentialsFlags(_exportCmd)
_clusterCmd.AddCommand(_exportCmd)
}
Expand All @@ -104,6 +112,14 @@ func addClusterConfigFlag(cmd *cobra.Command) {
cmd.Flags().SetAnnotation("config", cobra.BashCompFilenameExt, _configFileExts)
}

func addClusterNameFlag(cmd *cobra.Command) {
cmd.Flags().StringVarP(&_flagClusterName, "name", "n", "", "aws name of the cluster")
}

func addClusterRegionFlag(cmd *cobra.Command) {
cmd.Flags().StringVarP(&_flagClusterRegion, "region", "r", "", "aws region of the cluster")
}

func addAWSCredentialsFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(&_flagAWSAccessKeyID, "aws-key", "", "aws access key id")
cmd.Flags().StringVar(&_flagAWSSecretAccessKey, "aws-secret", "", "aws secret access key")
Expand Down
14 changes: 14 additions & 0 deletions cli/cmd/lib_cluster_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ func getNewClusterAccessConfig(disallowPrompt bool) (*clusterconfig.AccessConfig
}
}

if _flagClusterName != "" {
accessConfig.ClusterName = pointer.String(_flagClusterName)
}
if _flagClusterRegion != "" {
accessConfig.Region = pointer.String(_flagClusterRegion)
}

if accessConfig.ClusterName != nil && accessConfig.Region != nil {
return accessConfig, nil
}
Expand Down Expand Up @@ -118,6 +125,13 @@ func getClusterAccessConfigWithCache(disallowPrompt bool) (*clusterconfig.Access
}
}

if _flagClusterName != "" {
accessConfig.ClusterName = pointer.String(_flagClusterName)
}
if _flagClusterRegion != "" {
accessConfig.Region = pointer.String(_flagClusterRegion)
}

if accessConfig.ClusterName != nil && accessConfig.Region != nil {
return accessConfig, nil
}
Expand Down
2 changes: 1 addition & 1 deletion dev/generate_cli_md.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ commands=(
"cluster up"
"cluster info"
"cluster configure"
"cluster export"
"cluster down"
"cluster export"
"env configure"
"env list"
"env default"
Expand Down
24 changes: 15 additions & 9 deletions docs/miscellaneous/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ Usage:

Flags:
-c, --config string path to a cluster configuration file
-n, --name string aws name of the cluster
-r, --region string aws region of the cluster
--aws-key string aws access key id
--aws-secret string aws secret access key
-e, --env string environment to update (default "aws")
Expand Down Expand Up @@ -170,35 +172,39 @@ Flags:
-h, --help help for configure
```

### cluster export
### cluster down

```text
download the code and configuration for all APIs deployed in a cluster
spin down a cluster

Usage:
cortex cluster export [flags]
cortex cluster down [flags]

Flags:
-c, --config string path to a cluster configuration file
-n, --name string aws name of the cluster
-r, --region string aws region of the cluster
--aws-key string aws access key id
--aws-secret string aws secret access key
-h, --help help for export
-y, --yes skip prompts
-h, --help help for down
```

### cluster down
### cluster export

```text
spin down a cluster
download the code and configuration for all APIs deployed in a cluster

Usage:
cortex cluster down [flags]
cortex cluster export [flags]

Flags:
-c, --config string path to a cluster configuration file
-n, --name string aws name of the cluster
-r, --region string aws region of the cluster
--aws-key string aws access key id
--aws-secret string aws secret access key
-y, --yes skip prompts
-h, --help help for down
-h, --help help for export
```

### env configure
Expand Down