@@ -25,11 +25,15 @@ import (
2525var shellScript []byte
2626
2727type Agent struct {
28- cmd * tkexec.Command
28+ cmd * tkexec.Command
29+ argoFlags []string
2930}
3031
3132func 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
3539func (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+
219238func generateArgs (argType clusterArgs , metadata map [string ]string ) string {
220239 var builder strings.Builder
221240 for k , v := range metadata {
0 commit comments