Skip to content

Commit 3e41669

Browse files
authored
fix(argoflags): updating how and were we apply argoflags (#33)
Signed-off-by: rumstead <37445536+rumstead@users.noreply.github.com>
1 parent 921a1c0 commit 3e41669

3 files changed

Lines changed: 29 additions & 9 deletions

File tree

TROUBLESHOOTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ You can control the container gateway hostname via the `CRI_GATEWAY` environment
1313

1414
## Argo is behind a reverse proxy (ingress like treafik)
1515
You can add required flags, such as `--grpc-web`, to the argocd commands by adding `ARGOFLAGS` an environment variable.
16+
`ARGOFLAGS` applies to all the `Argo CD` commands, so ensure it is a global flag.
1617
Eg, `ARGOFLAGS=--grpc-web`
1718

1819
## How do I see more verbose logs?

pkg/gitops/argocd/argocd.go

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@ import (
2525
var shellScript []byte
2626

2727
type Agent struct {
28-
cmd *tkexec.Command
28+
cmd *tkexec.Command
29+
argoFlags []string
2930
}
3031

3132
func NewGitOpsEngine(binaries map[string]string) gitops.Engine {
32-
return &Agent{cmd: tkexec.NewCommand(binaries)}
33+
if err := setupArgoFlags(); err != nil {
34+
logging.Log().Errorf("unable to set argo flags: %v", err)
35+
}
36+
return &Agent{cmd: tkexec.NewCommand(binaries), argoFlags: strings.Split(os.Getenv("ARGOFLAGS"), " ")}
3337
}
3438

3539
func (a *Agent) Deploy(ctx context.Context, ops *kubernetes.Cluster) error {
@@ -130,18 +134,24 @@ func (a *Agent) setAdminPassword(ops *kubernetes.Cluster) error {
130134
}
131135

132136
host := fmt.Sprintf("%s:%s", a.getBindAddress(ops), ops.GetGitOps().GetPort())
137+
loginArgs := []string{"login", host, "--username", ops.GetGitOps().GetCredentials().GetUsername(), "--password", password, "--skip-test-tls"}
138+
loginArgs = append(loginArgs, a.argoFlags...)
133139
// login
134-
cmd := exec.Command(a.cmd.ArgoCD, "login", host, "--username", ops.GetGitOps().GetCredentials().GetUsername(), "--password", password, "--plaintext")
140+
cmd := exec.Command(a.cmd.ArgoCD, loginArgs...)
135141
if _, err := tkexec.RunCommand(cmd); err != nil {
136142
logger.Log().Infoln("unable to log into argo cd using the initial password, trying config password")
137-
cmd = exec.Command(a.cmd.ArgoCD, "login", host, "--username", ops.GetGitOps().GetCredentials().GetUsername(), "--password", ops.GetGitOps().GetCredentials().GetPassword(), "--plaintext")
143+
loginArgs = []string{"login", host, "--username", ops.GetGitOps().GetCredentials().GetUsername(), "--password", ops.GetGitOps().GetCredentials().GetPassword(), "--skip-test-tls"}
144+
loginArgs = append(loginArgs, a.argoFlags...)
145+
cmd = exec.Command(a.cmd.ArgoCD, loginArgs...)
138146
if output, err := tkexec.RunCommand(cmd); err != nil {
139147
return fmt.Errorf("unable to log into argo cd %s: %v", output, err)
140148
}
141149
} else {
142150
// change password
143-
cmd = exec.Command(a.cmd.ArgoCD, "account", "update-password", "--account", ops.GetGitOps().GetCredentials().GetUsername(), "--current-password",
144-
password, "--new-password", ops.GetGitOps().GetCredentials().GetPassword())
151+
accArgs := []string{"account", "update-password", "--account", ops.GetGitOps().GetCredentials().GetUsername(), "--current-password",
152+
password, "--new-password", ops.GetGitOps().GetCredentials().GetPassword()}
153+
accArgs = append(accArgs, a.argoFlags...)
154+
cmd = exec.Command(a.cmd.ArgoCD, accArgs...)
145155
if output, err := tkexec.RunCommand(cmd); err != nil {
146156
return fmt.Errorf("error changing argo cd password: %s: %v", output, err)
147157
}
@@ -208,14 +218,23 @@ func (a *Agent) AddCluster(_ context.Context, ops, workload *kubernetes.Cluster)
208218
"-e", "ARGOFLAGS",
209219
"-v", workDirVolume,
210220
"quay.io/argoproj/argocd:latest", "/hack/addCluster.sh", labels+annotations)
211-
logging.Log().Debugf("%s\n", cmd.String())
221+
logging.Log().Debugf("%s\n%s", cmd.String(), a.argoFlags)
212222
if output, err := tkexec.RunCommand(cmd); err != nil {
213223
return fmt.Errorf("error adding cluster to gitops agent: %s: %v", output, err)
214224
}
215225
logging.Log().Infof("added cluster %s to argo cd", workload.RequestCluster.GetName())
216226
return nil
217227
}
218228

229+
func setupArgoFlags() error {
230+
if os.Getenv("ARGOFLAGS") == "" {
231+
if err := os.Setenv("ARGOFLAGS", "--insecure --grpc-web"); err != nil {
232+
return err
233+
}
234+
}
235+
return nil
236+
}
237+
219238
func generateArgs(argType clusterArgs, metadata map[string]string) string {
220239
var builder strings.Builder
221240
for k, v := range metadata {

pkg/gitops/argocd/embed/addClusters.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ CRI_GATEWAY="${CRI_GATEWAY:-"host.docker.internal"}"
88

99
# login
1010
# https://docs.docker.com/desktop/networking/#i-want-to-connect-from-a-container-to-a-service-on-the-host
11-
argocd login "$CRI_GATEWAY:$ARGO_PORT" --plaintext $ARGOFLAGS --username "$ARGOUSER" --password "$ARGOPASSWD"
11+
argocd login "$CRI_GATEWAY:$ARGO_PORT" --skip-test-tls --username "$ARGOUSER" --password "$ARGOPASSWD" $ARGOFLAGS
1212

1313
# don't quote $1 so it globs
14-
argocd cluster add -y --upsert "$CONTEXT" --plaintext $ARGOFLAGS --name "$CLUSTER" --kubeconfig "$KUBECONFIG" $1
14+
argocd cluster add -y --upsert "$CONTEXT" --name "$CLUSTER" --kubeconfig "$KUBECONFIG" $ARGOFLAGS $1

0 commit comments

Comments
 (0)