Skip to content

Commit 00a263d

Browse files
authored
Set configured environment as default in cluster commands (#1724)
1 parent c320af1 commit 00a263d

File tree

10 files changed

+34
-36
lines changed

10 files changed

+34
-36
lines changed

Makefile

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,26 +68,26 @@ cluster-up-aws:
6868
@$(MAKE) images-all-aws
6969
@$(MAKE) cli
7070
@kill $(shell pgrep -f rerun) >/dev/null 2>&1 || true
71-
@eval $$(python3 ./manager/cluster_config_env.py ./dev/config/cluster-aws.yaml) && ./bin/cortex cluster up --config=./dev/config/cluster-aws.yaml --configure-env="$$CORTEX_CLUSTER_NAME-aws" --aws-key=$$AWS_ACCESS_KEY_ID --aws-secret=$$AWS_SECRET_ACCESS_KEY --cluster-aws-key=$$CLUSTER_AWS_ACCESS_KEY_ID --cluster-aws-secret=$$CLUSTER_AWS_SECRET_ACCESS_KEY && ./bin/cortex env default "$$CORTEX_CLUSTER_NAME-aws"
71+
@eval $$(python3 ./manager/cluster_config_env.py ./dev/config/cluster-aws.yaml) && ./bin/cortex cluster up --config=./dev/config/cluster-aws.yaml --configure-env="$$CORTEX_CLUSTER_NAME-aws" --aws-key=$$AWS_ACCESS_KEY_ID --aws-secret=$$AWS_SECRET_ACCESS_KEY --cluster-aws-key=$$CLUSTER_AWS_ACCESS_KEY_ID --cluster-aws-secret=$$CLUSTER_AWS_SECRET_ACCESS_KEY"
7272
@$(MAKE) kubectl-aws
7373
cluster-up-gcp:
7474
@$(MAKE) images-all-gcp
7575
@$(MAKE) cli
7676
@kill $(shell pgrep -f rerun) >/dev/null 2>&1 || true
77-
@eval $$(python3 ./manager/cluster_config_env.py ./dev/config/cluster-gcp.yaml) && ./bin/cortex cluster-gcp up --config=./dev/config/cluster-gcp.yaml --configure-env="$$CORTEX_CLUSTER_NAME-gcp" && ./bin/cortex env default "$$CORTEX_CLUSTER_NAME-gcp"
77+
@eval $$(python3 ./manager/cluster_config_env.py ./dev/config/cluster-gcp.yaml) && ./bin/cortex cluster-gcp up --config=./dev/config/cluster-gcp.yaml --configure-env="$$CORTEX_CLUSTER_NAME-gcp"
7878
@$(MAKE) kubectl-gcp
7979

8080
cluster-up-aws-y:
8181
@$(MAKE) images-all-aws
8282
@$(MAKE) cli
8383
@kill $(shell pgrep -f rerun) >/dev/null 2>&1 || true
84-
@eval $$(python3 ./manager/cluster_config_env.py ./dev/config/cluster-aws.yaml) && ./bin/cortex cluster up --config=./dev/config/cluster-aws.yaml --configure-env="$$CORTEX_CLUSTER_NAME-aws" --aws-key=$$AWS_ACCESS_KEY_ID --aws-secret=$$AWS_SECRET_ACCESS_KEY --cluster-aws-key=$$CLUSTER_AWS_ACCESS_KEY_ID --cluster-aws-secret=$$CLUSTER_AWS_SECRET_ACCESS_KEY --yes && ./bin/cortex env default "$$CORTEX_CLUSTER_NAME-aws"
84+
@eval $$(python3 ./manager/cluster_config_env.py ./dev/config/cluster-aws.yaml) && ./bin/cortex cluster up --config=./dev/config/cluster-aws.yaml --configure-env="$$CORTEX_CLUSTER_NAME-aws" --aws-key=$$AWS_ACCESS_KEY_ID --aws-secret=$$AWS_SECRET_ACCESS_KEY --cluster-aws-key=$$CLUSTER_AWS_ACCESS_KEY_ID --cluster-aws-secret=$$CLUSTER_AWS_SECRET_ACCESS_KEY --yes"
8585
@$(MAKE) kubectl-aws
8686
cluster-up-gcp-y:
8787
@$(MAKE) images-all-gcp
8888
@$(MAKE) cli
8989
@kill $(shell pgrep -f rerun) >/dev/null 2>&1 || true
90-
@eval $$(python3 ./manager/cluster_config_env.py ./dev/config/cluster-gcp.yaml) && ./bin/cortex cluster-gcp up --config=./dev/config/cluster-gcp.yaml --configure-env="$$CORTEX_CLUSTER_NAME-gcp" --yes && ./bin/cortex env default "$$CORTEX_CLUSTER_NAME-gcp"
90+
@eval $$(python3 ./manager/cluster_config_env.py ./dev/config/cluster-gcp.yaml) && ./bin/cortex cluster-gcp up --config=./dev/config/cluster-gcp.yaml --configure-env="$$CORTEX_CLUSTER_NAME-gcp" --yes
9191
@$(MAKE) kubectl-gcp
9292

9393
cluster-down-aws:
@@ -115,33 +115,33 @@ cluster-down-gcp-y:
115115
cluster-info-aws:
116116
@$(MAKE) images-manager-local
117117
@$(MAKE) cli
118-
@eval $$(python3 ./manager/cluster_config_env.py ./dev/config/cluster-aws.yaml) && ./bin/cortex cluster info --config=./dev/config/cluster-aws.yaml --configure-env="$$CORTEX_CLUSTER_NAME-aws" --aws-key=$$AWS_ACCESS_KEY_ID --aws-secret=$$AWS_SECRET_ACCESS_KEY --yes && ./bin/cortex env default "$$CORTEX_CLUSTER_NAME-aws"
118+
@eval $$(python3 ./manager/cluster_config_env.py ./dev/config/cluster-aws.yaml) && ./bin/cortex cluster info --config=./dev/config/cluster-aws.yaml --configure-env="$$CORTEX_CLUSTER_NAME-aws" --aws-key=$$AWS_ACCESS_KEY_ID --aws-secret=$$AWS_SECRET_ACCESS_KEY --yes
119119
cluster-info-gcp:
120120
@$(MAKE) images-manager-local
121121
@$(MAKE) cli
122-
@eval $$(python3 ./manager/cluster_config_env.py ./dev/config/cluster-gcp.yaml) && ./bin/cortex cluster-gcp info --config=./dev/config/cluster-gcp.yaml --configure-env="$$CORTEX_CLUSTER_NAME-gcp" --yes && ./bin/cortex env default "$$CORTEX_CLUSTER_NAME-gcp"
122+
@eval $$(python3 ./manager/cluster_config_env.py ./dev/config/cluster-gcp.yaml) && ./bin/cortex cluster-gcp info --config=./dev/config/cluster-gcp.yaml --configure-env="$$CORTEX_CLUSTER_NAME-gcp" --yes
123123

124124
cluster-configure-aws:
125125
@$(MAKE) images-all-aws
126126
@$(MAKE) cli
127127
@kill $(shell pgrep -f rerun) >/dev/null 2>&1 || true
128-
@eval $$(python3 ./manager/cluster_config_env.py ./dev/config/cluster-aws.yaml) && ./bin/cortex cluster configure --config=./dev/config/cluster-aws.yaml --configure-env="$$CORTEX_CLUSTER_NAME-aws" --aws-key=$$AWS_ACCESS_KEY_ID --aws-secret=$$AWS_SECRET_ACCESS_KEY --cluster-aws-key=$$CLUSTER_AWS_ACCESS_KEY_ID --cluster-aws-secret=$$CLUSTER_AWS_SECRET_ACCESS_KEY && ./bin/cortex env default "$$CORTEX_CLUSTER_NAME-aws"
128+
@eval $$(python3 ./manager/cluster_config_env.py ./dev/config/cluster-aws.yaml) && ./bin/cortex cluster configure --config=./dev/config/cluster-aws.yaml --configure-env="$$CORTEX_CLUSTER_NAME-aws" --aws-key=$$AWS_ACCESS_KEY_ID --aws-secret=$$AWS_SECRET_ACCESS_KEY --cluster-aws-key=$$CLUSTER_AWS_ACCESS_KEY_ID --cluster-aws-secret=$$CLUSTER_AWS_SECRET_ACCESS_KEY
129129
# cluster-configure-gcp:
130130
# @$(MAKE) images-all-gcp
131131
# @$(MAKE) cli
132132
# @kill $(shell pgrep -f rerun) >/dev/null 2>&1 || true
133-
# @eval $$(python3 ./manager/cluster_config_env.py ./dev/config/cluster-gcp.yaml) && ./bin/cortex cluster-gcp configure --config=./dev/config/cluster-gcp.yaml --configure-env="$$CORTEX_CLUSTER_NAME-gcp" && ./bin/cortex env default "$$CORTEX_CLUSTER_NAME-gcp"
133+
# @eval $$(python3 ./manager/cluster_config_env.py ./dev/config/cluster-gcp.yaml) && ./bin/cortex cluster-gcp configure --config=./dev/config/cluster-gcp.yaml --configure-env="$$CORTEX_CLUSTER_NAME-gcp"
134134

135135
cluster-configure-aws-y:
136136
@$(MAKE) images-all-aws
137137
@$(MAKE) cli
138138
@kill $(shell pgrep -f rerun) >/dev/null 2>&1 || true
139-
@eval $$(python3 ./manager/cluster_config_env.py ./dev/config/cluster-aws.yaml) && ./bin/cortex cluster configure --config=./dev/config/cluster-aws.yaml --configure-env="$$CORTEX_CLUSTER_NAME-aws" --aws-key=$$AWS_ACCESS_KEY_ID --aws-secret=$$AWS_SECRET_ACCESS_KEY --cluster-aws-key=$$CLUSTER_AWS_ACCESS_KEY_ID --cluster-aws-secret=$$CLUSTER_AWS_SECRET_ACCESS_KEY --yes && ./bin/cortex env default "$$CORTEX_CLUSTER_NAME-aws"
139+
@eval $$(python3 ./manager/cluster_config_env.py ./dev/config/cluster-aws.yaml) && ./bin/cortex cluster configure --config=./dev/config/cluster-aws.yaml --configure-env="$$CORTEX_CLUSTER_NAME-aws" --aws-key=$$AWS_ACCESS_KEY_ID --aws-secret=$$AWS_SECRET_ACCESS_KEY --cluster-aws-key=$$CLUSTER_AWS_ACCESS_KEY_ID --cluster-aws-secret=$$CLUSTER_AWS_SECRET_ACCESS_KEY --yes
140140
# cluster-configure-gcp-y:
141141
# @$(MAKE) images-all-gcp
142142
# @$(MAKE) cli
143143
# @kill $(shell pgrep -f rerun) >/dev/null 2>&1 || true
144-
# @eval $$(python3 ./manager/cluster_config_env.py ./dev/config/cluster-gcp.yaml) && ./bin/cortex cluster-gcp configure --config=./dev/config/cluster-gcp.yaml --configure-env="$$CORTEX_CLUSTER_NAME-gcp" --yes && ./bin/cortex env default "$$CORTEX_CLUSTER_NAME-gcp"
144+
# @eval $$(python3 ./manager/cluster_config_env.py ./dev/config/cluster-gcp.yaml) && ./bin/cortex cluster-gcp configure --config=./dev/config/cluster-gcp.yaml --configure-env="$$CORTEX_CLUSTER_NAME-gcp" --yes
145145

146146
# stop the in-cluster operator
147147
operator-stop-aws:

cli/cmd/cluster.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -322,15 +322,15 @@ var _clusterUpCmd = &cobra.Command{
322322
AWSSecretAccessKey: pointer.String(awsCreds.ClusterAWSSecretAccessKey),
323323
}
324324

325-
err = addEnvToCLIConfig(newEnvironment)
325+
err = addEnvToCLIConfig(newEnvironment, true)
326326
if err != nil {
327327
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)))
328328
}
329329

330330
if envExists {
331-
fmt.Printf(console.Bold("\nthe environment named \"%s\" has been updated to point to this cluster; append `--env %s` to cortex commands to use this cluster (e.g. `cortex deploy --env %s`), or set it as your default with `cortex env default %s`\n"), _flagClusterUpEnv, _flagClusterUpEnv, _flagClusterUpEnv, _flagClusterUpEnv)
331+
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)
332332
} else {
333-
fmt.Printf(console.Bold("\nan environment named \"%s\" has been configured to point to this cluster; append `--env %s` to cortex commands to use this cluster (e.g. `cortex deploy --env %s`), or set it as your default with `cortex env default %s`\n"), _flagClusterUpEnv, _flagClusterUpEnv, _flagClusterUpEnv, _flagClusterUpEnv)
333+
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)
334334
}
335335
},
336336
}
@@ -956,15 +956,15 @@ func updateAWSCLIEnv(envName string, operatorEndpoint string, awsCreds AWSCreden
956956
}
957957

958958
if shouldWriteEnv {
959-
err := addEnvToCLIConfig(newEnvironment)
959+
err := addEnvToCLIConfig(newEnvironment, true)
960960
if err != nil {
961961
return err
962962
}
963963

964964
if envWasUpdated {
965-
fmt.Printf(console.Bold("the environment named \"%s\" has been updated to point to this cluster; append `--env %s` to cortex commands to use this cluster (e.g. `cortex deploy --env %s`), or set it as your default with `cortex env default %s`\n"), envName, envName, envName, envName)
965+
fmt.Printf(console.Bold("the environment named \"%s\" has been updated to point to this cluster (and was set as the default environment)\n"), envName)
966966
} else {
967-
fmt.Printf(console.Bold("an environment named \"%s\" has been configured to point to this cluster; append `--env %s` to cortex commands to use this cluster (e.g. `cortex deploy --env %s`), or set it as your default with `cortex env default %s`\n"), envName, envName, envName, envName)
967+
fmt.Printf(console.Bold("an environment named \"%s\" has been configured to point to this cluster (and was set as the default environment)\n"), envName)
968968
}
969969
}
970970

cli/cmd/cluster_gcp.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,15 @@ var _clusterGCPUpCmd = &cobra.Command{
182182
OperatorEndpoint: &operatorLoadBalancerIP,
183183
}
184184

185-
err = addEnvToCLIConfig(newEnvironment)
185+
err = addEnvToCLIConfig(newEnvironment, true)
186186
if err != nil {
187187
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`", _flagClusterGCPUpEnv)))
188188
}
189189

190190
if envExists {
191-
fmt.Printf(console.Bold("\nthe environment named \"%s\" has been updated to point to this cluster; append `--env %s` to cortex commands to use this cluster (e.g. `cortex deploy --env %s`), or set it as your default with `cortex env default %s`\n"), _flagClusterGCPUpEnv, _flagClusterGCPUpEnv, _flagClusterGCPUpEnv, _flagClusterGCPUpEnv)
191+
fmt.Printf(console.Bold("\nthe environment named \"%s\" has been updated to point to this cluster (and was set as the default environment)\n"), _flagClusterGCPUpEnv)
192192
} else {
193-
fmt.Printf(console.Bold("\nan environment named \"%s\" has been configured to point to this cluster; append `--env %s` to cortex commands to use this cluster (e.g. `cortex deploy --env %s`), or set it as your default with `cortex env default %s`\n"), _flagClusterGCPUpEnv, _flagClusterGCPUpEnv, _flagClusterGCPUpEnv, _flagClusterGCPUpEnv)
193+
fmt.Printf(console.Bold("\nan environment named \"%s\" has been configured to point to this cluster (and was set as the default environment)\n"), _flagClusterGCPUpEnv)
194194
}
195195
},
196196
}
@@ -402,15 +402,15 @@ func updateGCPCLIEnv(envName string, operatorEndpoint string, disallowPrompt boo
402402
}
403403

404404
if shouldWriteEnv {
405-
err := addEnvToCLIConfig(newEnvironment)
405+
err := addEnvToCLIConfig(newEnvironment, true)
406406
if err != nil {
407407
return err
408408
}
409409

410410
if envWasUpdated {
411-
fmt.Printf(console.Bold("the environment named \"%s\" has been updated to point to this cluster; append `--env %s` to cortex commands to use this cluster (e.g. `cortex deploy --env %s`), or set it as your default with `cortex env default %s`\n"), envName, envName, envName, envName)
411+
fmt.Printf(console.Bold("the environment named \"%s\" has been updated to point to this cluster (and was set as the default environment)\n"), envName)
412412
} else {
413-
fmt.Printf(console.Bold("an environment named \"%s\" has been configured to point to this cluster; append `--env %s` to cortex commands to use this cluster (e.g. `cortex deploy --env %s`), or set it as your default with `cortex env default %s`\n"), envName, envName, envName, envName)
413+
fmt.Printf(console.Bold("an environment named \"%s\" has been configured to point to this cluster (and was set as the default environment)\n"), envName)
414414
}
415415
}
416416

cli/cmd/lib_cli_config.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ func configureEnv(envName string, fieldsToSkipPrompt cliconfig.Environment) (cli
698698
return cliconfig.Environment{}, err
699699
}
700700

701-
if err := addEnvToCLIConfig(env); err != nil {
701+
if err := addEnvToCLIConfig(env, false); err != nil {
702702
return cliconfig.Environment{}, err
703703
}
704704

@@ -839,7 +839,7 @@ func isEnvConfigured(envName string) (bool, error) {
839839
return false, nil
840840
}
841841

842-
func addEnvToCLIConfig(newEnv cliconfig.Environment) error {
842+
func addEnvToCLIConfig(newEnv cliconfig.Environment, setAsDefault bool) error {
843843
cliConfig, err := readCLIConfig()
844844
if err != nil {
845845
return errors.Wrap(err, "unable to configure cli environment")
@@ -858,6 +858,10 @@ func addEnvToCLIConfig(newEnv cliconfig.Environment) error {
858858
cliConfig.Environments = append(cliConfig.Environments, &newEnv)
859859
}
860860

861+
if setAsDefault {
862+
cliConfig.DefaultEnvironment = newEnv.Name
863+
}
864+
861865
if err := writeCLIConfig(cliConfig); err != nil {
862866
return errors.Wrap(err, "unable to configure cli environment")
863867
}

docs/clients/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` or `gcp` is automatically created to point to your cluster. 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` and `cortex cluster configure` to create / update the specified environment.
3+
When you create a cluster with `cortex cluster up`, an environment named `aws` or `gcp` 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` and `cortex cluster configure` 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/clusters/aws/install.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ pip install cortex
1414

1515
# spin up Cortex on your AWS account
1616
cortex cluster up # or: cortex cluster up --config cluster.yaml (see configuration options below)
17-
18-
# set the default environment
19-
cortex env default aws
2017
```
2118

2219
## Configure Cortex

docs/clusters/gcp/install.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ pip install cortex
1212

1313
# spin up Cortex on your GCP account
1414
cortex cluster-gcp up # or: cortex cluster-gcp up --config cluster.yaml (see configuration options below)
15-
16-
# set the default environment
17-
cortex env default gcp
1815
```
1916

2017
## Configure Cortex

docs/workloads/batch/example.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ $ python batch.py
9797
### Describe the Batch API
9898

9999
```bash
100-
$ cortex get image-classifier --env aws
100+
$ cortex get image-classifier
101101
```
102102

103103
### Submit a job
@@ -153,5 +153,5 @@ Once the job is complete, you should be able to find the results of the batch jo
153153
### Delete the Batch API
154154

155155
```bash
156-
$ cortex delete image-classifier --env aws
156+
$ cortex delete image-classifier
157157
```

docs/workloads/dependencies/example.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ cx.create_api(api_spec, project_dir=".")
5757
```
5858
5959
```bash
60-
$ cortex deploy api.yaml --env aws
60+
$ cortex deploy api.yaml
6161
```

docs/workloads/realtime/example.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ $ python text_generator.py
5656
### Monitor
5757

5858
```bash
59-
$ cortex get text-generator --env aws --watch
59+
$ cortex get text-generator --watch
6060
```
6161

6262
### Stream logs
@@ -74,5 +74,5 @@ $ curl https://***.execute-api.us-west-2.amazonaws.com/text-generator -X POST -H
7474
### Delete the API
7575

7676
```bash
77-
$ cortex delete text-generator --env aws
77+
$ cortex delete text-generator
7878
```

0 commit comments

Comments
 (0)