Skip to content

Commit 28019b9

Browse files
authored
Set default environment name to the cluster name (#2164)
1 parent 42088f6 commit 28019b9

File tree

16 files changed

+58
-63
lines changed

16 files changed

+58
-63
lines changed

.circleci/config.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ commands:
5656
steps:
5757
- run:
5858
name: Create Cluster
59-
command: cortex cluster up << parameters.config >> --configure-env aws -y
59+
command: cortex cluster up << parameters.config >> --configure-env cortex -y
6060
- run:
6161
name: Run E2E Tests
6262
no_output_timeout: 30m
6363
command: |
64-
pytest -v test/e2e/tests --env aws --skip-autoscaling --skip-load --skip-long-running
65-
pytest -v test/e2e/tests --env aws -k test_autoscaling
66-
pytest -v test/e2e/tests --env aws -k test_load
64+
pytest -v test/e2e/tests --env cortex --skip-autoscaling --skip-load --skip-long-running
65+
pytest -v test/e2e/tests --env cortex -k test_autoscaling
66+
pytest -v test/e2e/tests --env cortex -k test_load
6767
- run:
6868
name: Delete Cluster
6969
command: cortex cluster down --config << parameters.config >> -y

cli/cmd/cluster.go

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ var _eksctlPrefixRegex = regexp.MustCompile(`^.*[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]
7474

7575
func clusterInit() {
7676
_clusterUpCmd.Flags().SortFlags = false
77-
_clusterUpCmd.Flags().StringVarP(&_flagClusterUpEnv, "configure-env", "e", "aws", "name of environment to configure")
77+
_clusterUpCmd.Flags().StringVarP(&_flagClusterUpEnv, "configure-env", "e", "", "name of environment to configure (default: the name of your cluster)")
7878
_clusterUpCmd.Flags().BoolVarP(&_flagClusterDisallowPrompt, "yes", "y", false, "skip prompts")
7979
_clusterCmd.AddCommand(_clusterUpCmd)
8080

@@ -144,26 +144,31 @@ var _clusterUpCmd = &cobra.Command{
144144

145145
clusterConfigFile := args[0]
146146

147-
envExists, err := isEnvConfigured(_flagClusterUpEnv)
148-
if err != nil {
147+
if _, err := docker.GetDockerClient(); err != nil {
149148
exit.Error(err)
150149
}
151-
if envExists {
152-
if _flagClusterDisallowPrompt {
153-
fmt.Printf("found an existing environment named \"%s\", which will be overwritten to connect to this cluster once it's created\n\n", _flagClusterUpEnv)
154-
} else {
155-
prompt.YesOrExit(fmt.Sprintf("found an existing environment named \"%s\"; would you like to overwrite it to connect to this cluster once it's created?", _flagClusterUpEnv), "", "you can specify a different environment name to be configured to connect to this cluster by specifying the --configure-env flag (e.g. `cortex cluster up --configure-env prod`); or you can list your environments with `cortex env list` and delete an environment with `cortex env delete ENV_NAME`")
156-
}
157-
}
158150

159-
if _, err := docker.GetDockerClient(); err != nil {
151+
accessConfig, err := getNewClusterAccessConfig(clusterConfigFile)
152+
if err != nil {
160153
exit.Error(err)
161154
}
162155

163-
accessConfig, err := getNewClusterAccessConfig(clusterConfigFile)
156+
envName := _flagClusterUpEnv
157+
if envName == "" {
158+
envName = accessConfig.ClusterName
159+
}
160+
161+
envExists, err := isEnvConfigured(envName)
164162
if err != nil {
165163
exit.Error(err)
166164
}
165+
if envExists {
166+
if _flagClusterDisallowPrompt {
167+
fmt.Printf("found an existing environment named \"%s\", which will be overwritten to connect to this cluster once it's created\n\n", envName)
168+
} else {
169+
prompt.YesOrExit(fmt.Sprintf("found an existing environment named \"%s\"; would you like to overwrite it to connect to this cluster once it's created?", envName), "", "you can specify a different environment name to be configured to connect to this cluster by specifying the --configure-env flag (e.g. `cortex cluster up --configure-env prod`); or you can list your environments with `cortex env list` and delete an environment with `cortex env delete ENV_NAME`")
170+
}
171+
}
167172

168173
awsClient, err := newAWSClient(accessConfig.Region, true)
169174
if err != nil {
@@ -290,23 +295,23 @@ var _clusterUpCmd = &cobra.Command{
290295

291296
loadBalancer, err := getLoadBalancer(clusterConfig.ClusterName, OperatorLoadBalancer, awsClient)
292297
if err != nil {
293-
exit.Error(errors.Append(err, fmt.Sprintf("\n\nyou can attempt to resolve this issue and configure your cli environment by running `cortex cluster info --configure-env %s`", _flagClusterUpEnv)))
298+
exit.Error(errors.Append(err, fmt.Sprintf("\n\nyou can attempt to resolve this issue and configure your cli environment by running `cortex cluster info --configure-env %s`", envName)))
294299
}
295300

296301
newEnvironment := cliconfig.Environment{
297-
Name: _flagClusterUpEnv,
302+
Name: envName,
298303
OperatorEndpoint: "https://" + *loadBalancer.DNSName,
299304
}
300305

301306
err = addEnvToCLIConfig(newEnvironment, true)
302307
if err != nil {
303-
exit.Error(errors.Append(err, fmt.Sprintf("\n\nyou can attempt to resolve this issue and configure your cli environment by running `cortex cluster info --configure-env %s`", _flagClusterUpEnv)))
308+
exit.Error(errors.Append(err, fmt.Sprintf("\n\nyou can attempt to resolve this issue and configure your cli environment by running `cortex cluster info --configure-env %s`", envName)))
304309
}
305310

306311
if envExists {
307-
fmt.Printf(console.Bold("\nthe environment named \"%s\" has been updated to point to this cluster (and was set as the default environment)\n"), _flagClusterUpEnv)
312+
fmt.Printf(console.Bold("\nthe environment named \"%s\" has been updated to point to this cluster (and was set as the default environment)\n"), envName)
308313
} else {
309-
fmt.Printf(console.Bold("\nan environment named \"%s\" has been configured to point to this cluster (and was set as the default environment)\n"), _flagClusterUpEnv)
314+
fmt.Printf(console.Bold("\nan environment named \"%s\" has been configured to point to this cluster (and was set as the default environment)\n"), envName)
310315
}
311316
},
312317
}

cli/cmd/errors.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ const (
5050
ErrCortexYAMLNotFound = "cli.cortex_yaml_not_found"
5151
ErrDockerCtrlC = "cli.docker_ctrl_c"
5252
ErrResponseUnknown = "cli.response_unknown"
53-
ErrOnlyAWSClusterFlagSet = "cli.only_aws_cluster_flag_set"
5453
ErrMissingAWSCredentials = "cli.missing_aws_credentials"
5554
ErrCredentialsInClusterConfig = "cli.credentials_in_cluster_config"
5655
ErrClusterUp = "cli.cluster_up"

docs/clients/cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ Usage:
113113
cortex cluster up CLUSTER_CONFIG_FILE [flags]
114114
115115
Flags:
116-
-e, --configure-env string name of environment to configure (default "aws")
116+
-e, --configure-env string name of environment to configure (default: the name of your cluster)
117117
-y, --yes skip prompts
118118
-h, --help help for up
119119
```

docs/clusters/management/environments.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Environments
22

3-
When you create a cluster with `cortex cluster up`, an environment named `aws` is automatically created to point to your cluster and is configured to be the default environment. You can name the environment something else via the `--configure-env` flag, e.g. `cortex cluster up --configure-env prod`. You can also use the `--configure-env` flag with `cortex cluster info` to create / update the specified environment.
3+
When you create a cluster with `cortex cluster up`, an environment with the same name as your cluster is automatically created to point to your cluster and is configured to be the default environment. You can name the environment something else via the `--configure-env` flag, e.g. `cortex cluster up --configure-env prod`. You can also use the `--configure-env` flag with `cortex cluster info` to create / update the specified environment.
44

55
You can list your environments with `cortex env list`, change the default environment with `cortex env default`, delete an environment with `cortex env delete`, and create/update an environment with `cortex env configure`.
66

docs/workloads/batch/example.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ cortex get image-classifier
9393
import cortex
9494
import requests
9595

96-
cx = cortex.client("aws")
96+
cx = cortex.client("cortex")
9797
batch_endpoint = cx.get_api("image-classifier")["endpoint"]
9898

9999
dest_s3_dir = # specify S3 directory for the results, e.g. "s3://my-bucket/dir" (make sure your cluster has access to this bucket)

docs/workloads/dependencies/example.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ api_spec = {
4040
}
4141
}
4242

43-
cx = cortex.client("aws")
43+
cx = cortex.client("cortex")
4444
cx.deploy(api_spec, project_dir=".")
4545
```
4646

docs/workloads/realtime/metrics.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ response code counts (summed over the past 2 weeks) for your APIs:
66
```bash
77
cortex get
88

9-
env api status up-to-date requested last update avg request 2XX
10-
aws iris-classifier live 1 1 17m 24ms 1223
11-
aws text-generator live 1 1 8m 180ms 433
12-
aws image-classifier-resnet50 live 2 2 1h 32ms 1121126
9+
env api status up-to-date requested last update avg request 2XX
10+
cortex iris-classifier live 1 1 17m 24ms 1223
11+
cortex text-generator live 1 1 8m 180ms 433
12+
cortex image-classifier-resnet50 live 2 2 1h 32ms 1121126
1313
```
1414

1515
The `cortex get API_NAME` command also provides a link to a Grafana dashboard:

docs/workloads/realtime/multi-model/example.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ requirements = ["tensorflow", "transformers", "wget", "fasttext"]
3232

3333
api_spec = {"name": "multi-model", "kind": "RealtimeAPI"}
3434

35-
cx = cortex.client("aws")
35+
cx = cortex.client("cortex")
3636
cx.deploy_realtime_api(api_spec, handler=Handler, requirements=requirements)
3737
```
3838

docs/workloads/realtime/traffic-splitter/example.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ api_spec_gpu = {
3333
},
3434
}
3535

36-
cx = cortex.client("aws")
36+
cx = cortex.client("cortex")
3737
cx.deploy_realtime_api(api_spec_cpu, handler=Handler, requirements=requirements)
3838
cx.deploy_realtime_api(api_spec_gpu, handler=Handler, requirements=requirements)
3939
```

0 commit comments

Comments
 (0)