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
```

docs/workloads/task/example.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Or, using Python `requests`:
9090
import cortex
9191
import requests
9292

93-
cx = cortex.client("aws") # "aws" is the name of the Cortex environment used in this example
93+
cx = cortex.client("cortex") # "cortex" is the name of the Cortex environment used in this example
9494
task_endpoint = cx.get_api("train-iris")["endpoint"]
9595

9696
dest_s3_dir = # S3 directory where the model will be uploaded, e.g. "s3://my-bucket/dir"

test/apis/batch/image-classifier/README.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
This example shows how to deploy a batch image classification api that accepts a list of image urls as input, downloads the images, classifies them, and writes the results to S3.
44

5-
**Batch APIs are only supported in AWS.** You can find cluster installation documentation [here](../../../docs/aws/install.md).
6-
75
## Pre-requisites
86

97
* [Install](../../../docs/aws/install.md) Cortex and create a cluster
@@ -147,15 +145,15 @@ Here are the complete [API configuration docs](../../../docs/workloads/batch/con
147145
`cortex deploy` takes your model, your `handler.py` implementation, and your configuration from `cortex.yaml` and creates an endpoint that can receive job submissions and manage running jobs.
148146

149147
```bash
150-
$ cortex deploy --env aws
148+
$ cortex deploy
151149
152150
created image-classifier (BatchAPI)
153151
```
154152

155153
Get the endpoint for your Batch API with `cortex get image-classifier`:
156154

157155
```bash
158-
$ cortex get image-classifier --env aws
156+
$ cortex get image-classifier
159157
160158
no submitted jobs
161159
@@ -218,7 +216,7 @@ Take note of the job id in the response.
218216
### List the jobs for your Batch API
219217

220218
```bash
221-
$ cortex get image-classifier --env aws
219+
$ cortex get image-classifier
222220
223221
job id status progress start time duration
224222
69d6faf82e4660d3 running 0/3 20 Jul 2020 01:07:44 UTC 3m26s
@@ -248,7 +246,7 @@ $ curl http://***.elb.us-west-2.amazonaws.com/image-classifier?jobID=69d6faf82e4
248246
You can also use the Cortex CLI to get the status of your job using `cortex get <BATCH_API_NAME> <JOB_ID>`.
249247

250248
```bash
251-
$ cortex get image-classifier 69d6faf82e4660d3 --env aws
249+
$ cortex get image-classifier 69d6faf82e4660d3
252250
253251
job id: 69d6faf82e4660d3
254252
status: running
@@ -273,7 +271,7 @@ job endpoint: http://***.elb.us-west-2.amazonaws.com/image-classifier/69d6faf82e
273271
You can stream logs realtime for debugging and monitoring purposes with `cortex logs <BATCH_API_NAME> <JOB_ID>`
274272

275273
```bash
276-
$ cortex logs image-classifier 69d6fdeb2d8e6647 --env aws
274+
$ cortex logs image-classifier 69d6fdeb2d8e6647
277275
278276
started enqueuing batches to queue
279277
partitioning 5 items found in job submission into 3 batches of size 2
@@ -398,7 +396,7 @@ After submitting this job, you should get a response like this:
398396
Wait for the job to complete by streaming the logs with `cortex logs <BATCH_API_NAME> <JOB_ID>` or watching for the job status to change with `cortex get <BATCH_API_NAME> <JOB_ID> --watch`.
399397

400398
```bash
401-
$ cortex logs image-classifier 69d6faf82e4660d3 --env aws
399+
$ cortex logs image-classifier 69d6faf82e4660d3
402400
403401
started enqueuing batches to queue
404402
enqueuing contents from file s3://cortex-examples/image-classifier/urls_0.json
@@ -507,7 +505,7 @@ You should get a response like this:
507505
Wait for the job to complete by streaming the logs with `cortex logs <BATCH_API_NAME> <JOB_ID>` or watching for the job status to change with `cortex get <BATCH_API_NAME> <JOB_ID> --watch`.
508506

509507
```bash
510-
$ cortex logs image-classifier 69d6f8a472f0e1e5 --env aws
508+
$ cortex logs image-classifier 69d6f8a472f0e1e5
511509
512510
started enqueuing batches to queue
513511
completed enqueuing a total of 8 batches
@@ -550,7 +548,7 @@ stopped job 69d96a01ea55da8c
550548
You can also use the Cortex CLI `cortex delete <BATCH_API_NAME> <JOB_ID>`.
551549

552550
```bash
553-
$ cortex delete image-classifier 69d96a01ea55da8c --env aws
551+
$ cortex delete image-classifier 69d96a01ea55da8c
554552
555553
stopped job 69d96a01ea55da8c
556554
```
@@ -562,7 +560,7 @@ stopped job 69d96a01ea55da8c
562560
Run `cortex delete` to delete the API:
563561

564562
```bash
565-
$ cortex delete image-classifier --env aws
563+
$ cortex delete image-classifier
566564
567565
deleting image-classifier
568566
```

test/apis/grpc/iris-classifier-sklearn/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ sample = iris_classifier_pb2.Sample(
2121
petal_width=0.3
2222
)
2323

24-
cx = cortex.client("aws")
24+
cx = cortex.client("cortex")
2525
api = cx.get_api("iris-classifier")
2626
grpc_endpoint = api["endpoint"] + ":" + str(api["grpc_ports"]["insecure"])
2727
channel = grpc.insecure_channel(grpc_endpoint)

test/apis/grpc/prime-number-generator/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import cortex
1414
import generator_pb2
1515
import generator_pb2_grpc
1616

17-
cx = cortex.client("aws")
17+
cx = cortex.client("cortex")
1818
api = cx.get_api("prime-generator")
1919
grpc_endpoint = api["endpoint"] + ":" + str(api["grpc_ports"]["insecure"])
2020

test/apis/model-caching/python/translator/README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,13 @@ Once the cluster is spun up (roughly 20 minutes), we can deploy by running:
5757
cortex deploy
5858
```
5959

60-
(I've configured my CLI to default to the AWS environment by running `cortex env default aws`)
61-
6260
Now, we wait for the API to become live. You can track its status with `cortex get --watch`.
6361

6462
Note that after the API goes live, we may need to wait a few minutes for it to register all the models hosted in the S3 bucket. Because the bucket is so large, it takes Cortex a bit longer than usual. When it's done, running `cortex get translator` should return something like:
6563

6664
```
6765
cortex get translator
6866
69-
using aws environment
70-
7167
status up-to-date requested last update avg request 2XX
7268
live 1 1 3m -- --
7369

test/apis/traffic-splitter/README.md

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ To deploy this example:
1111
## `cortex deploy`
1212

1313
```bash
14-
$ cortex deploy --env aws
14+
$ cortex deploy
1515

1616
creating iris-classifier-onnx (RealtimeAPI)
1717
creating iris-classifier-tf (RealtimeAPI)
@@ -23,18 +23,18 @@ created iris-classifier (TrafficSplitter)
2323
```bash
2424
$ cortex get
2525

26-
env realtime api status up-to-date requested last update avg request 2XX
27-
aws iris-classifier-onnx updating 0 1 27s - -
28-
aws iris-classifier-tf updating 0 1 27s - -
26+
env realtime api status up-to-date requested last update avg request 2XX
27+
cortex iris-classifier-onnx updating 0 1 27s - -
28+
cortex iris-classifier-tf updating 0 1 27s - -
2929

3030
env traffic splitter apis last update
31-
aws iris-classifier iris-classifier-onnx:30 iris-classifier-tf:70 27s
31+
cortex iris-classifier iris-classifier-onnx:30 iris-classifier-tf:70 27s
3232
```
3333

3434
## `cortex get iris-classifier`
3535

3636
```bash
37-
$ cortex get iris-classifier --env aws
37+
$ cortex get iris-classifier
3838

3939
apis weights status requested last update avg request 2XX 5XX
4040
iris-classifier-onnx 30 live 1 1m - - -
@@ -73,10 +73,7 @@ setosa
7373
Notice the requests being routed to the different Realtime APIs based on their weights (the output below may not match yours):
7474

7575
```bash
76-
$ cortex get iris-classifier --env aws
77-
78-
using aws environment
79-
76+
$ cortex get iris-classifier
8077

8178
apis weights status requested last update avg request 2XX 5XX
8279
iris-classifier-onnx 30 live 1 4m 6.00791 ms 1 -
@@ -93,15 +90,15 @@ example curl: curl http://***.elb.us-west-2.amazonaws.com/iris-classifier -X POS
9390
Use `cortex delete <api_name>` to delete the Traffic Splitter and the two Realtime APIs (note that the Traffic Splitter and each Realtime API must be deleted by separate `cortex delete` commands):
9491

9592
```bash
96-
$ cortex delete iris-classifier --env aws
93+
$ cortex delete iris-classifier
9794

9895
deleting iris-classifier
9996

100-
$ cortex delete iris-classifier-onnx --env aws
97+
$ cortex delete iris-classifier-onnx
10198

10299
deleting iris-classifier-onnx
103100

104-
$ cortex delete iris-classifier-tf --env aws
101+
$ cortex delete iris-classifier-tf
105102

106103
deleting iris-classifier-tf
107104
```

0 commit comments

Comments
 (0)