diff --git a/TROUBLESHOOTING.md b/TROUBLESHOOTING.md index f925c92..ab5cfce 100644 --- a/TROUBLESHOOTING.md +++ b/TROUBLESHOOTING.md @@ -13,6 +13,7 @@ You can control the container gateway hostname via the `CRI_GATEWAY` environment ## Argo is behind a reverse proxy (ingress like treafik) You can add required flags, such as `--grpc-web`, to the argocd commands by adding `ARGOFLAGS` an environment variable. +`ARGOFLAGS` applies to all the `Argo CD` commands, so ensure it is a global flag. Eg, `ARGOFLAGS=--grpc-web` ## How do I see more verbose logs? diff --git a/pkg/gitops/argocd/argocd.go b/pkg/gitops/argocd/argocd.go index 2837314..b8f4cf8 100644 --- a/pkg/gitops/argocd/argocd.go +++ b/pkg/gitops/argocd/argocd.go @@ -25,11 +25,15 @@ import ( var shellScript []byte type Agent struct { - cmd *tkexec.Command + cmd *tkexec.Command + argoFlags []string } func NewGitOpsEngine(binaries map[string]string) gitops.Engine { - return &Agent{cmd: tkexec.NewCommand(binaries)} + if err := setupArgoFlags(); err != nil { + logging.Log().Errorf("unable to set argo flags: %v", err) + } + return &Agent{cmd: tkexec.NewCommand(binaries), argoFlags: strings.Split(os.Getenv("ARGOFLAGS"), " ")} } func (a *Agent) Deploy(ctx context.Context, ops *kubernetes.Cluster) error { @@ -130,18 +134,24 @@ func (a *Agent) setAdminPassword(ops *kubernetes.Cluster) error { } host := fmt.Sprintf("%s:%s", a.getBindAddress(ops), ops.GetGitOps().GetPort()) + loginArgs := []string{"login", host, "--username", ops.GetGitOps().GetCredentials().GetUsername(), "--password", password, "--skip-test-tls"} + loginArgs = append(loginArgs, a.argoFlags...) // login - cmd := exec.Command(a.cmd.ArgoCD, "login", host, "--username", ops.GetGitOps().GetCredentials().GetUsername(), "--password", password, "--plaintext") + cmd := exec.Command(a.cmd.ArgoCD, loginArgs...) if _, err := tkexec.RunCommand(cmd); err != nil { logger.Log().Infoln("unable to log into argo cd using the initial password, trying config password") - cmd = exec.Command(a.cmd.ArgoCD, "login", host, "--username", ops.GetGitOps().GetCredentials().GetUsername(), "--password", ops.GetGitOps().GetCredentials().GetPassword(), "--plaintext") + loginArgs = []string{"login", host, "--username", ops.GetGitOps().GetCredentials().GetUsername(), "--password", ops.GetGitOps().GetCredentials().GetPassword(), "--skip-test-tls"} + loginArgs = append(loginArgs, a.argoFlags...) + cmd = exec.Command(a.cmd.ArgoCD, loginArgs...) if output, err := tkexec.RunCommand(cmd); err != nil { return fmt.Errorf("unable to log into argo cd %s: %v", output, err) } } else { // change password - cmd = exec.Command(a.cmd.ArgoCD, "account", "update-password", "--account", ops.GetGitOps().GetCredentials().GetUsername(), "--current-password", - password, "--new-password", ops.GetGitOps().GetCredentials().GetPassword()) + accArgs := []string{"account", "update-password", "--account", ops.GetGitOps().GetCredentials().GetUsername(), "--current-password", + password, "--new-password", ops.GetGitOps().GetCredentials().GetPassword()} + accArgs = append(accArgs, a.argoFlags...) + cmd = exec.Command(a.cmd.ArgoCD, accArgs...) if output, err := tkexec.RunCommand(cmd); err != nil { return fmt.Errorf("error changing argo cd password: %s: %v", output, err) } @@ -208,7 +218,7 @@ func (a *Agent) AddCluster(_ context.Context, ops, workload *kubernetes.Cluster) "-e", "ARGOFLAGS", "-v", workDirVolume, "quay.io/argoproj/argocd:latest", "/hack/addCluster.sh", labels+annotations) - logging.Log().Debugf("%s\n", cmd.String()) + logging.Log().Debugf("%s\n%s", cmd.String(), a.argoFlags) if output, err := tkexec.RunCommand(cmd); err != nil { return fmt.Errorf("error adding cluster to gitops agent: %s: %v", output, err) } @@ -216,6 +226,15 @@ func (a *Agent) AddCluster(_ context.Context, ops, workload *kubernetes.Cluster) return nil } +func setupArgoFlags() error { + if os.Getenv("ARGOFLAGS") == "" { + if err := os.Setenv("ARGOFLAGS", "--insecure --grpc-web"); err != nil { + return err + } + } + return nil +} + func generateArgs(argType clusterArgs, metadata map[string]string) string { var builder strings.Builder for k, v := range metadata { diff --git a/pkg/gitops/argocd/embed/addClusters.sh b/pkg/gitops/argocd/embed/addClusters.sh index 800ec36..0365fc3 100755 --- a/pkg/gitops/argocd/embed/addClusters.sh +++ b/pkg/gitops/argocd/embed/addClusters.sh @@ -8,7 +8,7 @@ CRI_GATEWAY="${CRI_GATEWAY:-"host.docker.internal"}" # login # https://docs.docker.com/desktop/networking/#i-want-to-connect-from-a-container-to-a-service-on-the-host -argocd login "$CRI_GATEWAY:$ARGO_PORT" --plaintext $ARGOFLAGS --username "$ARGOUSER" --password "$ARGOPASSWD" +argocd login "$CRI_GATEWAY:$ARGO_PORT" --skip-test-tls --username "$ARGOUSER" --password "$ARGOPASSWD" $ARGOFLAGS # don't quote $1 so it globs -argocd cluster add -y --upsert "$CONTEXT" --plaintext $ARGOFLAGS --name "$CLUSTER" --kubeconfig "$KUBECONFIG" $1 \ No newline at end of file +argocd cluster add -y --upsert "$CONTEXT" --name "$CLUSTER" --kubeconfig "$KUBECONFIG" $ARGOFLAGS $1 \ No newline at end of file