From a2e92030049845fce3acd8d889763f3439229501 Mon Sep 17 00:00:00 2001 From: Bradford Wagner Date: Fri, 10 May 2024 14:16:38 -0400 Subject: [PATCH] fix(bind.addr): argocd login (#27) --- pkg/gitops/argocd/argocd.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/pkg/gitops/argocd/argocd.go b/pkg/gitops/argocd/argocd.go index 6ef0498..a3e7826 100644 --- a/pkg/gitops/argocd/argocd.go +++ b/pkg/gitops/argocd/argocd.go @@ -101,11 +101,7 @@ func (a *Agent) deployArgoCD(_ context.Context, ops *kubernetes.Cluster) error { logging.Log().Infoln("Port forward is not required") return nil } - // pull bind address from yaml config or default to 0.0.0.0 (maintaining backwards compatibility) - bindAddress := "0.0.0.0" - if ops.GetGitOps().GetBindAddress() != "" { - bindAddress = ops.GetGitOps().GetBindAddress() - } + bindAddress := a.getBindAddress(ops) port := fmt.Sprintf("%s:8080", ops.GetGitOps().GetPort()) cmd = exec.Command(a.cmd.Kubectl, "port-forward", "-n", ops.GetGitOps().GetNamespace(), "deploy/argocd-server", port, "--address", bindAddress) // use start because we do not want to wait for the process to finish @@ -118,13 +114,22 @@ func (a *Agent) deployArgoCD(_ context.Context, ops *kubernetes.Cluster) error { return nil } +func (a *Agent) getBindAddress(ops *kubernetes.Cluster) (bindAddress string) { + // pull bind address from yaml config or default to 0.0.0.0 (maintaining backwards compatibility) + bindAddress = "0.0.0.0" + if ops.GetGitOps().GetBindAddress() != "" { + bindAddress = ops.GetGitOps().GetBindAddress() + } + return +} + func (a *Agent) setAdminPassword(ops *kubernetes.Cluster) error { password, err := a.getInitialPassword(ops) if err != nil { return err } - host := fmt.Sprintf("localhost:%s", ops.GetGitOps().GetPort()) + host := fmt.Sprintf("%s:%s", a.getBindAddress(ops), ops.GetGitOps().GetPort()) // login cmd := exec.Command(a.cmd.ArgoCD, "login", host, "--username", ops.GetGitOps().GetCredentials().GetUsername(), "--password", password, "--insecure") if _, err := tkexec.RunCommand(cmd); err != nil {