Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(argoflags): updating how and were we apply argoflags #33

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions TROUBLESHOOTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
33 changes: 26 additions & 7 deletions pkg/gitops/argocd/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -208,14 +218,23 @@ 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)
}
logging.Log().Infof("added cluster %s to argo cd", workload.RequestCluster.GetName())
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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/gitops/argocd/embed/addClusters.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
argocd cluster add -y --upsert "$CONTEXT" --name "$CLUSTER" --kubeconfig "$KUBECONFIG" $ARGOFLAGS $1
Loading