Skip to content

Commit 891cd1b

Browse files
authored
Update environment flags for cluster commands (#1533)
1 parent c037be2 commit 891cd1b

File tree

13 files changed

+203
-108
lines changed

13 files changed

+203
-108
lines changed

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ cluster-up:
5151
@$(MAKE) registry-all
5252
@$(MAKE) cli
5353
@kill $(shell pgrep -f rerun) >/dev/null 2>&1 || true
54-
@./bin/cortex cluster up --config=./dev/config/cluster.yaml --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
54+
@eval $$(python3 ./manager/cluster_config_env.py ./dev/config/cluster.yaml) && ./bin/cortex cluster up --config=./dev/config/cluster.yaml --configure-env="$$CORTEX_CLUSTER_NAME" --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"
5555
@$(MAKE) kubectl
5656

5757
cluster-up-y:
5858
@$(MAKE) registry-all
5959
@$(MAKE) cli
6060
@kill $(shell pgrep -f rerun) >/dev/null 2>&1 || true
61-
@./bin/cortex cluster up --config=./dev/config/cluster.yaml --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
61+
@eval $$(python3 ./manager/cluster_config_env.py ./dev/config/cluster.yaml) && ./bin/cortex cluster up --config=./dev/config/cluster.yaml --configure-env="$$CORTEX_CLUSTER_NAME" --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"
6262
@$(MAKE) kubectl
6363

6464
cluster-down:
@@ -76,19 +76,19 @@ cluster-down-y:
7676
cluster-info:
7777
@$(MAKE) manager-local
7878
@$(MAKE) cli
79-
@./bin/cortex cluster info --config=./dev/config/cluster.yaml --aws-key=$$AWS_ACCESS_KEY_ID --aws-secret=$$AWS_SECRET_ACCESS_KEY
79+
@eval $$(python3 ./manager/cluster_config_env.py ./dev/config/cluster.yaml) && ./bin/cortex cluster info --config=./dev/config/cluster.yaml --configure-env="$$CORTEX_CLUSTER_NAME" --aws-key=$$AWS_ACCESS_KEY_ID --aws-secret=$$AWS_SECRET_ACCESS_KEY && ./bin/cortex env default "$$CORTEX_CLUSTER_NAME"
8080

8181
cluster-configure:
8282
@$(MAKE) registry-all
8383
@$(MAKE) cli
8484
@kill $(shell pgrep -f rerun) >/dev/null 2>&1 || true
85-
@./bin/cortex cluster configure --config=./dev/config/cluster.yaml --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
85+
@eval $$(python3 ./manager/cluster_config_env.py ./dev/config/cluster.yaml) && ./bin/cortex cluster configure --config=./dev/config/cluster.yaml --configure-env="$$CORTEX_CLUSTER_NAME" --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"
8686

8787
cluster-configure-y:
8888
@$(MAKE) registry-all
8989
@$(MAKE) cli
9090
@kill $(shell pgrep -f rerun) >/dev/null 2>&1 || true
91-
@./bin/cortex cluster configure --config=./dev/config/cluster.yaml --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
91+
@eval $$(python3 ./manager/cluster_config_env.py ./dev/config/cluster.yaml) && ./bin/cortex cluster configure --config=./dev/config/cluster.yaml --configure-env="$$CORTEX_CLUSTER_NAME" --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"
9292

9393
# stop the in-cluster operator
9494
operator-stop:

cli/cluster/errors.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,27 @@ const (
4343
)
4444

4545
func ErrorFailedToConnectOperator(originalError error, envName string, operatorURL string) error {
46-
originalErrMsg := ""
46+
msg := ""
4747
if originalError != nil {
48-
originalErrMsg = urls.TrimQueryParamsStr(errors.Message(originalError)) + "\n\n"
48+
msg += urls.TrimQueryParamsStr(errors.Message(originalError)) + "\n\n"
4949
}
5050

51-
msg := fmt.Sprintf("%sunable to connect to your cluster in the %s environment (operator endpoint: %s)\n\n", originalErrMsg, envName, operatorURL)
52-
msg += "if you don't have a cluster running:\n"
53-
msg += fmt.Sprintf(" → if you'd like to create a cluster, run `cortex cluster up --env %s`\n", envName)
54-
msg += fmt.Sprintf(" → otherwise you can ignore this message, and prevent it in the future with `cortex env delete %s`\n", envName)
55-
msg += "\nif you have a cluster running:\n"
56-
msg += fmt.Sprintf(" → run `cortex cluster info --env %s` to update your environment (include `--config <cluster.yaml>` if you have a cluster configuration file)\n", envName)
57-
// CORTEX_VERSION_MINOR
58-
msg += " → if you set `operator_load_balancer_scheme: internal` in your cluster configuration file, your CLI must run from within a VPC that has access to your cluster's VPC (see https://docs.cortex.dev/v/master/guides/vpc-peering)\n"
51+
if envName == "" {
52+
msg += fmt.Sprintf("unable to connect to your cluster (operator endpoint: %s)\n\n", operatorURL)
53+
msg += "if you don't have a cluster running:\n"
54+
msg += " → to create a cluster, run `cortex cluster up`\n"
55+
msg += "\nif you have a cluster running:\n"
56+
msg += " → run `cortex cluster info --configure-env ENV_NAME` to update your environment (replace ENV_NAME with your desired environment name, and include `--config <cluster.yaml>` if you have a cluster configuration file)\n"
57+
} else {
58+
msg += fmt.Sprintf("unable to connect to your cluster in the %s environment (operator endpoint: %s)\n\n", envName, operatorURL)
59+
msg += "if you don't have a cluster running:\n"
60+
msg += fmt.Sprintf(" → if you'd like to create a cluster, run `cortex cluster up --configure-env %s`\n", envName)
61+
msg += fmt.Sprintf(" → otherwise you can ignore this message, and prevent it in the future with `cortex env delete %s`\n", envName)
62+
msg += "\nif you have a cluster running:\n"
63+
msg += fmt.Sprintf(" → run `cortex cluster info --configure-env %s` to update your environment (include `--config <cluster.yaml>` if you have a cluster configuration file)\n", envName)
64+
// CORTEX_VERSION_MINOR
65+
msg += " → if you set `operator_load_balancer_scheme: internal` in your cluster configuration file, your CLI must run from within a VPC that has access to your cluster's VPC (see https://docs.cortex.dev/v/master/guides/vpc-peering)\n"
66+
}
5967

6068
return errors.WithStack(&errors.Error{
6169
Kind: ErrFailedToConnectOperator,

cli/cluster/lib_http_client.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,6 @@ func makeOperatorRequest(operatorConfig OperatorConfig, request *http.Request) (
200200

201201
response, err := client.Do(request)
202202
if err != nil {
203-
if operatorConfig.EnvName == "" {
204-
return nil, errors.Wrap(err, "failed to connect to operator", operatorConfig.OperatorEndpoint)
205-
}
206203
return nil, ErrorFailedToConnectOperator(err, operatorConfig.EnvName, operatorConfig.OperatorEndpoint)
207204
}
208205
defer response.Body.Close()

0 commit comments

Comments
 (0)