diff options
author | Martin Polden <mpolden@mpolden.no> | 2021-09-27 15:33:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-27 15:33:58 +0200 |
commit | e3de4656126063f92b3051c68ed544b9fd5d9c36 (patch) | |
tree | e3faf40f68194a30e6cf6764b3ca3d7500592693 | |
parent | 1654f886aa22dadab66a0d0b30024bbc46743ee1 (diff) | |
parent | b8e36a097e937ddf8f38baeb770d4a9f919ee9b4 (diff) |
Merge pull request #19275 from vespa-engine/mpolden/cloud-system-override
Support overriding Vespa Cloud system
-rw-r--r-- | client/go/cmd/api_key.go | 2 | ||||
-rw-r--r-- | client/go/cmd/config.go | 12 | ||||
-rw-r--r-- | client/go/cmd/deploy.go | 8 | ||||
-rw-r--r-- | client/go/cmd/helpers.go | 21 | ||||
-rw-r--r-- | client/go/vespa/target.go | 14 | ||||
-rw-r--r-- | client/go/vespa/target_test.go | 3 |
6 files changed, 43 insertions, 17 deletions
diff --git a/client/go/cmd/api_key.go b/client/go/cmd/api_key.go index a838f1a05c8..b3284daa993 100644 --- a/client/go/cmd/api_key.go +++ b/client/go/cmd/api_key.go @@ -77,6 +77,6 @@ func printPublicKey(apiKeyFile, tenant string) { log.Printf("\nThis is your public key:\n%s", color.Green(pemPublicKey)) log.Printf("Its fingerprint is:\n%s\n", color.Cyan(fingerprint)) log.Print("\nTo use this key in Vespa Cloud click 'Add custom key' at") - log.Printf(color.Cyan("%s/tenant/%s/keys").String(), defaultConsoleURL, tenant) + log.Printf(color.Cyan("%s/tenant/%s/keys").String(), getConsoleURL(), tenant) log.Print("and paste the entire public key including the BEGIN and END lines.") } diff --git a/client/go/cmd/config.go b/client/go/cmd/config.go index 3753d9a9390..c88225338c7 100644 --- a/client/go/cmd/config.go +++ b/client/go/cmd/config.go @@ -34,8 +34,16 @@ func init() { } var configCmd = &cobra.Command{ - Use: "config", - Short: "Configure default values for flags", + Use: "config", + Short: "Configure persistent values for flags", + Long: `Configure persistent values for flags. + +This command allows setting a persistent value for a given flag. On future +invocations the flag can then be omitted as it is read from the config file +instead. + +Configuration is written to $HOME/.vespa by default. This path can be +overridden by setting the VESPA_CLI_HOME environment variable.`, DisableAutoGenTag: true, Run: func(cmd *cobra.Command, args []string) { // Root command does nothing diff --git a/client/go/cmd/deploy.go b/client/go/cmd/deploy.go index 9bf59187778..b3171d184e0 100644 --- a/client/go/cmd/deploy.go +++ b/client/go/cmd/deploy.go @@ -39,7 +39,11 @@ When this returns successfully the application package has been validated and activated on config servers. The process of applying it on individual nodes has started but may not have completed. -If application directory is not specified, it defaults to working directory.`, +If application directory is not specified, it defaults to working directory. + +When deploying to Vespa Cloud the system can be overridden by setting the +environment variable VESPA_CLI_CLOUD_SYSTEM. This is intended for internal use +only.`, Example: "$ vespa deploy .", Args: cobra.MaximumNArgs(1), DisableAutoGenTag: true, @@ -78,7 +82,7 @@ If application directory is not specified, it defaults to working directory.`, if opts.IsCloud() { log.Printf("\nUse %s for deployment status, or follow this deployment at", color.Cyan("vespa status")) log.Print(color.Cyan(fmt.Sprintf("%s/tenant/%s/application/%s/dev/instance/%s/job/%s-%s/run/%d", - defaultConsoleURL, + getConsoleURL(), opts.Deployment.Application.Tenant, opts.Deployment.Application.Application, opts.Deployment.Application.Instance, opts.Deployment.Zone.Environment, opts.Deployment.Zone.Region, sessionOrRunID))) diff --git a/client/go/cmd/helpers.go b/client/go/cmd/helpers.go index f29a842aed2..6cd7aa38936 100644 --- a/client/go/cmd/helpers.go +++ b/client/go/cmd/helpers.go @@ -16,8 +16,6 @@ import ( "github.com/vespa-engine/vespa/client/go/vespa" ) -const defaultConsoleURL = "https://console.vespa.oath.cloud" - var exitFunc = os.Exit // To allow overriding Exit in tests func fatalErrHint(err error, hints ...string) { @@ -114,6 +112,23 @@ func getService(service string, sessionOrRunID int64) *vespa.Service { return s } +func getConsoleURL() string { + system := os.Getenv("VESPA_CLI_CLOUD_SYSTEM") + if system == "publiccd" { + return "https://console-cd.vespa.oath.cloud" + } + return "https://console.vespa.oath.cloud" + +} + +func getApiURL() string { + system := os.Getenv("VESPA_CLI_CLOUD_SYSTEM") + if system == "publiccd" { + return "https://api.vespa-external-cd.aws.oath.cloud:4443" + } + return "https://api.vespa-external.aws.oath.cloud:4443" +} + func getTarget() vespa.Target { targetType := getTargetType() if strings.HasPrefix(targetType, "http") { @@ -147,7 +162,7 @@ func getTarget() vespa.Target { if err != nil { fatalErrHint(err, "Deployment to cloud requires a certificate. Try 'vespa cert'") } - return vespa.CloudTarget(deployment, apiKey, + return vespa.CloudTarget(getApiURL(), deployment, apiKey, vespa.TLSOptions{ KeyPair: kp, CertificateFile: certificateFile, diff --git a/client/go/vespa/target.go b/client/go/vespa/target.go index 69dc876c1c8..24452a96f0f 100644 --- a/client/go/vespa/target.go +++ b/client/go/vespa/target.go @@ -24,8 +24,6 @@ const ( queryService = "query" documentService = "document" - defaultCloudAPI = "https://api.vespa-external.aws.oath.cloud:4443" - waitRetryInterval = 2 * time.Second ) @@ -171,7 +169,7 @@ func (t *customTarget) DiscoverServices(timeout time.Duration, runID int64) erro } type cloudTarget struct { - cloudAPI string + apiURL string targetType string deployment Deployment apiKey []byte @@ -187,7 +185,7 @@ func (t *cloudTarget) Type() string { return t.targetType } func (t *cloudTarget) Service(name string) (*Service, error) { switch name { case deployService: - return &Service{Name: name, BaseURL: t.cloudAPI}, nil + return &Service{Name: name, BaseURL: t.apiURL}, nil case queryService: if t.queryURL == "" { return nil, fmt.Errorf("service %s not discovered", name) @@ -216,7 +214,7 @@ func (t *cloudTarget) DiscoverServices(timeout time.Duration, runID int64) error func (t *cloudTarget) waitForRun(signer *RequestSigner, runID int64, timeout time.Duration) error { runURL := fmt.Sprintf("%s/application/v4/tenant/%s/application/%s/instance/%s/job/%s-%s/run/%d", - t.cloudAPI, + t.apiURL, t.deployment.Application.Tenant, t.deployment.Application.Application, t.deployment.Application.Instance, t.deployment.Zone.Environment, t.deployment.Zone.Region, runID) req, err := http.NewRequest("GET", runURL, nil) @@ -280,7 +278,7 @@ func (t *cloudTarget) printLog(response jobResponse, last int64) int64 { func (t *cloudTarget) discoverEndpoints(signer *RequestSigner, timeout time.Duration) error { deploymentURL := fmt.Sprintf("%s/application/v4/tenant/%s/application/%s/instance/%s/environment/%s/region/%s", - t.cloudAPI, + t.apiURL, t.deployment.Application.Tenant, t.deployment.Application.Application, t.deployment.Application.Instance, t.deployment.Zone.Environment, t.deployment.Zone.Region) req, err := http.NewRequest("GET", deploymentURL, nil) @@ -327,9 +325,9 @@ func CustomTarget(baseURL string) Target { } // CloudTarget creates a Target for the Vespa Cloud platform. -func CloudTarget(deployment Deployment, apiKey []byte, tlsOptions TLSOptions, logOptions LogOptions) Target { +func CloudTarget(apiURL string, deployment Deployment, apiKey []byte, tlsOptions TLSOptions, logOptions LogOptions) Target { return &cloudTarget{ - cloudAPI: defaultCloudAPI, + apiURL: apiURL, targetType: cloudTargetType, deployment: deployment, apiKey: apiKey, diff --git a/client/go/vespa/target_test.go b/client/go/vespa/target_test.go index 31f145f0db3..9e95c8c6ac2 100644 --- a/client/go/vespa/target_test.go +++ b/client/go/vespa/target_test.go @@ -102,6 +102,7 @@ func TestCloudTargetWait(t *testing.T) { var logWriter bytes.Buffer target := CloudTarget( + "https://example.com", Deployment{ Application: ApplicationID{Tenant: "t1", Application: "a1", Instance: "i1"}, Zone: ZoneID{Environment: "dev", Region: "us-north-1"}, @@ -110,7 +111,7 @@ func TestCloudTargetWait(t *testing.T) { TLSOptions{KeyPair: x509KeyPair}, LogOptions{Writer: &logWriter}) if ct, ok := target.(*cloudTarget); ok { - ct.cloudAPI = srv.URL + ct.apiURL = srv.URL } else { t.Fatalf("Wrong target type %T", ct) } |