Repository: cortexlabs/cortex (language: go)

Issue:
Set the default name of the environment to cluster name during cluster up
Confirm that the user is prompted If an environment already exists with the cluster name.



Discussion / hints:

Fix patch:
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 5f72d80191..eafe09a679 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -56,14 +56,14 @@ commands:
     steps:
       - run:
           name: Create Cluster
-          command: cortex cluster up << parameters.config >> --configure-env aws -y
+          command: cortex cluster up << parameters.config >> --configure-env cortex -y
       - run:
           name: Run E2E Tests
           no_output_timeout: 30m
           command: |
-            pytest -v test/e2e/tests --env aws --skip-autoscaling --skip-load --skip-long-running
-            pytest -v test/e2e/tests --env aws -k test_autoscaling
-            pytest -v test/e2e/tests --env aws -k test_load
+            pytest -v test/e2e/tests --env cortex --skip-autoscaling --skip-load --skip-long-running
+            pytest -v test/e2e/tests --env cortex -k test_autoscaling
+            pytest -v test/e2e/tests --env cortex -k test_load
       - run:
           name: Delete Cluster
           command: cortex cluster down --config << parameters.config >> -y
diff --git a/cli/cmd/cluster.go b/cli/cmd/cluster.go
index 79b3e4334b..574ab3ca40 100644
--- a/cli/cmd/cluster.go
+++ b/cli/cmd/cluster.go
@@ -74,7 +74,7 @@ var _eksctlPrefixRegex = regexp.MustCompile(`^.*[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]
 
 func clusterInit() {
 	_clusterUpCmd.Flags().SortFlags = false
-	_clusterUpCmd.Flags().StringVarP(&_flagClusterUpEnv, "configure-env", "e", "aws", "name of environment to configure")
+	_clusterUpCmd.Flags().StringVarP(&_flagClusterUpEnv, "configure-env", "e", "", "name of environment to configure (default: the name of your cluster)")
 	_clusterUpCmd.Flags().BoolVarP(&_flagClusterDisallowPrompt, "yes", "y", false, "skip prompts")
 	_clusterCmd.AddCommand(_clusterUpCmd)
 
@@ -144,26 +144,31 @@ var _clusterUpCmd = &cobra.Command{
 
 		clusterConfigFile := args[0]
 
-		envExists, err := isEnvConfigured(_flagClusterUpEnv)
-		if err != nil {
+		if _, err := docker.GetDockerClient(); err != nil {
 			exit.Error(err)
 		}
-		if envExists {
-			if _flagClusterDisallowPrompt {
-				fmt.Printf("found an existing environment named \"%s\", which will be overwritten to connect to this cluster once it's created\n\n", _flagClusterUpEnv)
-			} else {
-				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`")
-			}
-		}
 
-		if _, err := docker.GetDockerClient(); err != nil {
+		accessConfig, err := getNewClusterAccessConfig(clusterConfigFile)
+		if err != nil {
 			exit.Error(err)
 		}
 
-		accessConfig, err := getNewClusterAccessConfig(clusterConfigFile)
+		envName := _flagClusterUpEnv
+		if envName == "" {
+			envName = accessConfig.ClusterName
+		}
+
+		envExists, err := isEnvConfigured(envName)
 		if err != nil {
 			exit.Error(err)
 		}
+		if envExists {
+			if _flagClusterDisallowPrompt {
+				fmt.Printf("found an existing environment named \"%s\", which will be overwritten to connect to this cluster once it's created\n\n", envName)
+			} else {
+				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`")
+			}
+		}
 
 		awsClient, err := newAWSClient(accessConfig.Region, true)
 		if err != nil {
@@ -290,23 +295,23 @@ var _clusterUpCmd = &cobra.Command{
 
 		loadBalancer, err := getLoadBalancer(clusterConfig.ClusterName, OperatorLoadBalancer, awsClient)
 		if err != nil {
-			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)))
+			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)))
 		}
 
 		newEnvironment := cliconfig.Environment{
-			Name:             _flagClusterUpEnv,
+			Name:             envName,
 			OperatorEndpoint: "https://" + *loadBalancer.DNSName,
 		}
 
 		err = addEnvToCLIConfig(newEnvironment, true)
 		if err != nil {
-			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)))
+			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)))
 		}
 
 		if envExists {
-			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)
+			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)
 		} else {
-			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)
+			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)
 		}
 	},
 }
diff --git a/cli/cmd/errors.go b/cli/cmd/errors.go
index 25fbba0909..9a3db6e652 100644
--- a/cli/cmd/errors.go
+++ b/cli/cmd/errors.go
@@ -50,7 +50,6 @@ const (
 	ErrCortexYAMLNotFound                  = "cli.cortex_yaml_not_found"
 	ErrDockerCtrlC                         = "cli.docker_ctrl_c"
 	ErrResponseUnknown                     = "cli.response_unknown"
-	ErrOnlyAWSClusterFlagSet               = "cli.only_aws_cluster_flag_set"
 	ErrMissingAWSCredentials               = "cli.missing_aws_credentials"
 	ErrCredentialsInClusterConfig          = "cli.credentials_in_cluster_config"
 	ErrClusterUp                           = "cli.cluster_up"
diff --git a/docs/clients/cli.md b/docs/clients/cli.md
index 8c48f98093..4e60c08bd2 100644
--- a/docs/clients/cli.md
+++ b/docs/clients/cli.md
@@ -113,7 +113,7 @@ Usage:
   cortex cluster up CLUSTER_CONFIG_FILE [flags]
 
 Flags:
-  -e, --configure-env string   name of environment to configure (default "aws")
+  -e, --configure-env string   name of environment to configure (default: the name of your cluster)
   -y, --yes                    skip prompts
   -h, --help                   help for up
 ```
diff --git a/docs/clusters/management/environments.md b/docs/clusters/management/environments.md
index 73c779bdb7..04e5ce2e81 100644
--- a/docs/clusters/management/environments.md
+++ b/docs/clusters/management/environments.md
@@ -1,6 +1,6 @@
 # Environments
 
-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.
+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.
 
 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`.
 
diff --git a/docs/workloads/batch/example.md b/docs/workloads/batch/example.md
index ee6c33a910..32f5903c9d 100644
--- a/docs/workloads/batch/example.md
+++ b/docs/workloads/batch/example.md
@@ -93,7 +93,7 @@ cortex get image-classifier
 import cortex
 import requests
 
-cx = cortex.client("aws")
+cx = cortex.client("cortex")
 batch_endpoint = cx.get_api("image-classifier")["endpoint"]
 
 dest_s3_dir = # specify S3 directory for the results, e.g. "s3://my-bucket/dir" (make sure your cluster has access to this bucket)
diff --git a/docs/workloads/dependencies/example.md b/docs/workloads/dependencies/example.md
index 2ff7a58197..2fcc1b330f 100644
--- a/docs/workloads/dependencies/example.md
+++ b/docs/workloads/dependencies/example.md
@@ -40,7 +40,7 @@ api_spec = {
     }
 }
 
-cx = cortex.client("aws")
+cx = cortex.client("cortex")
 cx.deploy(api_spec, project_dir=".")
 ```
 
diff --git a/docs/workloads/realtime/metrics.md b/docs/workloads/realtime/metrics.md
index 8fb82eb4fb..9343f03925 100644
--- a/docs/workloads/realtime/metrics.md
+++ b/docs/workloads/realtime/metrics.md
@@ -6,10 +6,10 @@ response code counts (summed over the past 2 weeks) for your APIs:
 ```bash
 cortex get
 
-env   api                         status   up-to-date   requested   last update   avg request   2XX
-aws   iris-classifier             live     1            1           17m           24ms          1223
-aws   text-generator              live     1            1           8m            180ms         433
-aws   image-classifier-resnet50   live     2            2           1h            32ms          1121126
+env      api                         status   up-to-date   requested   last update   avg request   2XX
+cortex   iris-classifier             live     1            1           17m           24ms          1223
+cortex   text-generator              live     1            1           8m            180ms         433
+cortex   image-classifier-resnet50   live     2            2           1h            32ms          1121126
 ```
 
 The `cortex get API_NAME` command also provides a link to a Grafana dashboard:
diff --git a/docs/workloads/realtime/multi-model/example.md b/docs/workloads/realtime/multi-model/example.md
index 6eee9d9797..d09fc790c9 100644
--- a/docs/workloads/realtime/multi-model/example.md
+++ b/docs/workloads/realtime/multi-model/example.md
@@ -32,7 +32,7 @@ requirements = ["tensorflow", "transformers", "wget", "fasttext"]
 
 api_spec = {"name": "multi-model", "kind": "RealtimeAPI"}
 
-cx = cortex.client("aws")
+cx = cortex.client("cortex")
 cx.deploy_realtime_api(api_spec, handler=Handler, requirements=requirements)
 ```
 
diff --git a/docs/workloads/realtime/traffic-splitter/example.md b/docs/workloads/realtime/traffic-splitter/example.md
index 04034dc330..baa9d72130 100644
--- a/docs/workloads/realtime/traffic-splitter/example.md
+++ b/docs/workloads/realtime/traffic-splitter/example.md
@@ -33,7 +33,7 @@ api_spec_gpu = {
     },
 }
 
-cx = cortex.client("aws")
+cx = cortex.client("cortex")
 cx.deploy_realtime_api(api_spec_cpu, handler=Handler, requirements=requirements)
 cx.deploy_realtime_api(api_spec_gpu, handler=Handler, requirements=requirements)
 ```
diff --git a/docs/workloads/task/example.md b/docs/workloads/task/example.md
index 6add71a5f0..f318cc7995 100644
--- a/docs/workloads/task/example.md
+++ b/docs/workloads/task/example.md
@@ -90,7 +90,7 @@ Or, using Python `requests`:
 import cortex
 import requests
 
-cx = cortex.client("aws")  # "aws" is the name of the Cortex environment used in this example
+cx = cortex.client("cortex")  # "cortex" is the name of the Cortex environment used in this example
 task_endpoint = cx.get_api("train-iris")["endpoint"]
 
 dest_s3_dir =  # S3 directory where the model will be uploaded, e.g. "s3://my-bucket/dir"


Test patch:
diff --git a/test/apis/batch/image-classifier/README.md b/test/apis/batch/image-classifier/README.md
index 71f77b1929..2e893c8fbe 100644
--- a/test/apis/batch/image-classifier/README.md
+++ b/test/apis/batch/image-classifier/README.md
@@ -2,8 +2,6 @@
 
 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.
 
-**Batch APIs are only supported in AWS.** You can find cluster installation documentation [here](../../../docs/aws/install.md).
-
 ## Pre-requisites
 
 * [Install](../../../docs/aws/install.md) Cortex and create a cluster
@@ -147,7 +145,7 @@ Here are the complete [API configuration docs](../../../docs/workloads/batch/con
 `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.
 
 ```bash
-$ cortex deploy --env aws
+$ cortex deploy
 
 created image-classifier (BatchAPI)
 ```
@@ -155,7 +153,7 @@ created image-classifier (BatchAPI)
 Get the endpoint for your Batch API with `cortex get image-classifier`:
 
 ```bash
-$ cortex get image-classifier --env aws
+$ cortex get image-classifier
 
 no submitted jobs
 
@@ -218,7 +216,7 @@ Take note of the job id in the response.
 ### List the jobs for your Batch API
 
 ```bash
-$ cortex get image-classifier --env aws
+$ cortex get image-classifier
 
 job id             status    progress   start time                 duration
 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
 You can also use the Cortex CLI to get the status of your job using `cortex get <BATCH_API_NAME> <JOB_ID>`.
 
 ```bash
-$ cortex get image-classifier 69d6faf82e4660d3 --env aws
+$ cortex get image-classifier 69d6faf82e4660d3
 
 job id: 69d6faf82e4660d3
 status: running
@@ -273,7 +271,7 @@ job endpoint: http://***.elb.us-west-2.amazonaws.com/image-classifier/69d6faf82e
 You can stream logs realtime for debugging and monitoring purposes with `cortex logs <BATCH_API_NAME> <JOB_ID>`
 
 ```bash
-$ cortex logs image-classifier 69d6fdeb2d8e6647 --env aws
+$ cortex logs image-classifier 69d6fdeb2d8e6647
 
 started enqueuing batches to queue
 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:
 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`.
 
 ```bash
-$ cortex logs image-classifier 69d6faf82e4660d3 --env aws
+$ cortex logs image-classifier 69d6faf82e4660d3
 
 started enqueuing batches to queue
 enqueuing contents from file s3://cortex-examples/image-classifier/urls_0.json
@@ -507,7 +505,7 @@ You should get a response like this:
 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`.
 
 ```bash
-$ cortex logs image-classifier 69d6f8a472f0e1e5 --env aws
+$ cortex logs image-classifier 69d6f8a472f0e1e5
 
 started enqueuing batches to queue
 completed enqueuing a total of 8 batches
@@ -550,7 +548,7 @@ stopped job 69d96a01ea55da8c
 You can also use the Cortex CLI `cortex delete <BATCH_API_NAME> <JOB_ID>`.
 
 ```bash
-$ cortex delete image-classifier 69d96a01ea55da8c --env aws
+$ cortex delete image-classifier 69d96a01ea55da8c
 
 stopped job 69d96a01ea55da8c
 ```
@@ -562,7 +560,7 @@ stopped job 69d96a01ea55da8c
 Run `cortex delete` to delete the API:
 
 ```bash
-$ cortex delete image-classifier --env aws
+$ cortex delete image-classifier
 
 deleting image-classifier
 ```
diff --git a/test/apis/grpc/iris-classifier-sklearn/README.md b/test/apis/grpc/iris-classifier-sklearn/README.md
index 7900540c33..50aa786b5b 100644
--- a/test/apis/grpc/iris-classifier-sklearn/README.md
+++ b/test/apis/grpc/iris-classifier-sklearn/README.md
@@ -21,7 +21,7 @@ sample = iris_classifier_pb2.Sample(
     petal_width=0.3
 )
 
-cx = cortex.client("aws")
+cx = cortex.client("cortex")
 api = cx.get_api("iris-classifier")
 grpc_endpoint = api["endpoint"] + ":" + str(api["grpc_ports"]["insecure"])
 channel = grpc.insecure_channel(grpc_endpoint)
diff --git a/test/apis/grpc/prime-number-generator/README.md b/test/apis/grpc/prime-number-generator/README.md
index 62729c1c9e..53bcf7da72 100644
--- a/test/apis/grpc/prime-number-generator/README.md
+++ b/test/apis/grpc/prime-number-generator/README.md
@@ -14,7 +14,7 @@ import cortex
 import generator_pb2
 import generator_pb2_grpc
 
-cx = cortex.client("aws")
+cx = cortex.client("cortex")
 api = cx.get_api("prime-generator")
 grpc_endpoint = api["endpoint"] + ":" + str(api["grpc_ports"]["insecure"])
 
diff --git a/test/apis/model-caching/python/translator/README.md b/test/apis/model-caching/python/translator/README.md
index 2114915058..ddb1c5cb1f 100644
--- a/test/apis/model-caching/python/translator/README.md
+++ b/test/apis/model-caching/python/translator/README.md
@@ -57,8 +57,6 @@ Once the cluster is spun up (roughly 20 minutes), we can deploy by running:
 cortex deploy
 ```
 
-(I've configured my CLI to default to the AWS environment by running `cortex env default aws`)
-
 Now, we wait for the API to become live. You can track its status with `cortex get --watch`.
 
 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:
@@ -66,8 +64,6 @@ Note that after the API goes live, we may need to wait a few minutes for it to r
 ```
 cortex get translator
 
-using aws environment
-
 status   up-to-date   requested   last update   avg request   2XX
 live     1            1           3m            --            --
 
diff --git a/test/apis/traffic-splitter/README.md b/test/apis/traffic-splitter/README.md
index ccad661ce7..6bd70ac98e 100644
--- a/test/apis/traffic-splitter/README.md
+++ b/test/apis/traffic-splitter/README.md
@@ -11,7 +11,7 @@ To deploy this example:
 ## `cortex deploy`
 
 ```bash
-$ cortex deploy --env aws
+$ cortex deploy
 
 creating iris-classifier-onnx (RealtimeAPI)
 creating iris-classifier-tf (RealtimeAPI)
@@ -23,18 +23,18 @@ created iris-classifier (TrafficSplitter)
 ```bash
 $ cortex get
 
-env   realtime api           status     up-to-date   requested   last update   avg request   2XX
-aws   iris-classifier-onnx   updating   0            1           27s           -             -
-aws   iris-classifier-tf     updating   0            1           27s           -             -
+env      realtime api           status     up-to-date   requested   last update   avg request   2XX
+cortex   iris-classifier-onnx   updating   0            1           27s           -             -
+cortex   iris-classifier-tf     updating   0            1           27s           -             -
 
 env   traffic splitter   apis                                            last update
-aws   iris-classifier    iris-classifier-onnx:30 iris-classifier-tf:70   27s
+cortex   iris-classifier    iris-classifier-onnx:30 iris-classifier-tf:70   27s
 ```
 
 ## `cortex get iris-classifier`
 
 ```bash
-$ cortex get iris-classifier --env aws
+$ cortex get iris-classifier
 
 apis                   weights   status   requested   last update   avg request   2XX   5XX
 iris-classifier-onnx   30        live     1           1m            -             -     -
@@ -73,10 +73,7 @@ setosa
 Notice the requests being routed to the different Realtime APIs based on their weights (the output below may not match yours):
 
 ```bash
-$ cortex get iris-classifier --env aws
-
-using aws environment
-
+$ cortex get iris-classifier
 
 apis                   weights   status   requested   last update   avg request   2XX   5XX
 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
 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):
 
 ```bash
-$ cortex delete iris-classifier --env aws
+$ cortex delete iris-classifier
 
 deleting iris-classifier
 
-$ cortex delete iris-classifier-onnx  --env aws
+$ cortex delete iris-classifier-onnx
 
 deleting iris-classifier-onnx
 
-$ cortex delete iris-classifier-tf --env aws
+$ cortex delete iris-classifier-tf
 
 deleting iris-classifier-tf
 ```