diff --git a/commands/cloud_deploy_exec.go b/commands/cloud_deploy_exec.go index c0af68c3..b3556a0e 100644 --- a/commands/cloud_deploy_exec.go +++ b/commands/cloud_deploy_exec.go @@ -77,7 +77,9 @@ func (e *KoolDeployExec) Execute(args []string) (err error) { return } - if cloudService, err = e.cloud.Authenticate(domain, service); err != nil { + cluster := e.env.Get("KOOL_CLOUD_CLUSTER") + + if cloudService, err = e.cloud.Authenticate(domain, service, cluster); err != nil { return } diff --git a/commands/cloud_deploy_logs.go b/commands/cloud_deploy_logs.go index b09edc14..35b8962e 100644 --- a/commands/cloud_deploy_logs.go +++ b/commands/cloud_deploy_logs.go @@ -73,7 +73,9 @@ func (e *KoolDeployLogs) Execute(args []string) (err error) { return } - if cloudService, err = e.cloud.Authenticate(domain, service); err != nil { + cluster := e.env.Get("KOOL_CLOUD_CLUSTER") + + if cloudService, err = e.cloud.Authenticate(domain, service, cluster); err != nil { return } diff --git a/commands/cloud_deploy_logs_test.go b/commands/cloud_deploy_logs_test.go index 7e529983..92de58e7 100644 --- a/commands/cloud_deploy_logs_test.go +++ b/commands/cloud_deploy_logs_test.go @@ -15,6 +15,7 @@ type fakeK8S struct { CalledAuthenticate bool CalledAuthenticateParamDomain string CalledAuthenticateParamService string + CalledAuthenticateParamCluster string MockAuthenticateCloudService string MockAuthenticateErr error @@ -29,10 +30,11 @@ type fakeK8S struct { CalledCleanupParamOut shell.OutputWritter } -func (f *fakeK8S) Authenticate(domain, service string) (cloudService string, err error) { +func (f *fakeK8S) Authenticate(domain, service, cluster string) (cloudService string, err error) { f.CalledAuthenticate = true f.CalledAuthenticateParamDomain = domain f.CalledAuthenticateParamService = service + f.CalledAuthenticateParamCluster = cluster cloudService = f.MockAuthenticateCloudService err = f.MockAuthenticateErr diff --git a/services/cloud/k8s/kubectl.go b/services/cloud/k8s/kubectl.go index 32edc30b..e9521f31 100644 --- a/services/cloud/k8s/kubectl.go +++ b/services/cloud/k8s/kubectl.go @@ -11,7 +11,7 @@ import ( ) type K8S interface { - Authenticate(string, string) (string, error) + Authenticate(string, string, string) (string, error) Kubectl(shell.PathChecker) (builder.Command, error) Cleanup(shell.OutputWritter) } @@ -30,9 +30,10 @@ func NewDefaultK8S() *DefaultK8S { } } -func (k *DefaultK8S) Authenticate(domain, service string) (cloudService string, err error) { +func (k *DefaultK8S) Authenticate(domain, service, cluster string) (cloudService string, err error) { k.deployExec.Body().Set("domain", domain) k.deployExec.Body().Set("service", service) + k.deployExec.Body().Set("cluster", cluster) if k.resp, err = k.deployExec.Call(); err != nil { return diff --git a/services/cloud/k8s/kubectl_test.go b/services/cloud/k8s/kubectl_test.go index 277615ab..1ae28a0e 100644 --- a/services/cloud/k8s/kubectl_test.go +++ b/services/cloud/k8s/kubectl_test.go @@ -16,7 +16,7 @@ func TestAuthenticate(t *testing.T) { expectedErr := errors.New("call error") k.deployExec.Endpoint.(*api.DefaultEndpoint).MockErr(expectedErr) - if _, err := k.Authenticate("foo", "bar"); !errors.Is(err, expectedErr) { + if _, err := k.Authenticate("foo", "bar", ""); !errors.Is(err, expectedErr) { t.Error("unexpected error return from Authenticate") } @@ -29,7 +29,7 @@ func TestAuthenticate(t *testing.T) { CA: "ca", }) - if _, err := k.Authenticate("foo", "bar"); !strings.Contains(err.Error(), "failed to generate access credentials") { + if _, err := k.Authenticate("foo", "bar", ""); !strings.Contains(err.Error(), "failed to generate access credentials") { t.Errorf("unexpected error from DeployExec call: %v", err) } @@ -43,7 +43,7 @@ func TestAuthenticate(t *testing.T) { authTempPath = t.TempDir() - if cloudService, err := k.Authenticate("foo", "bar"); err != nil { + if cloudService, err := k.Authenticate("foo", "bar", ""); err != nil { t.Errorf("unexpected error from Authenticate call: %v", err) } else if cloudService != "path" { t.Errorf("unexpected cloudService return: %s", cloudService) @@ -104,7 +104,7 @@ func TestKubectl(t *testing.T) { t.Error("should get error before authenticating") } - _, _ = k.Authenticate("foo", "bar") + _, _ = k.Authenticate("foo", "bar", "") if cmd, _ := k.Kubectl(fakeShell); cmd.Cmd() != "kubectl" { t.Error("should use kubectl")