diff --git a/cmd/event-reporter-server/commands/event_reporter_server.go b/cmd/event-reporter-server/commands/event_reporter_server.go index 9ed5318eb5f84..2d89b60a50780 100644 --- a/cmd/event-reporter-server/commands/event_reporter_server.go +++ b/cmd/event-reporter-server/commands/event_reporter_server.go @@ -46,14 +46,15 @@ func init() { failureRetryPeriodMilliSeconds = env.ParseNumFromEnv(failureRetryPeriodMilliSecondsEnv, failureRetryPeriodMilliSeconds, 0, 1000) } -func getApplicationClient(useGrpc bool, address, token string) appclient.ApplicationClient { +func getApplicationClient(useGrpc bool, address, token string, path string) appclient.ApplicationClient { if useGrpc { applicationClientSet, err := apiclient.NewClient(&apiclient.ClientOptions{ - ServerAddr: address, - Insecure: true, - GRPCWeb: true, - PlainText: true, - AuthToken: token, + ServerAddr: address, + Insecure: true, + GRPCWeb: true, + PlainText: true, + AuthToken: token, + GRPCWebRootPath: path, }) errors.CheckError(err) @@ -64,7 +65,7 @@ func getApplicationClient(useGrpc bool, address, token string) appclient.Applica return applicationClient } - return appclient.NewHttpApplicationClient(token, address) + return appclient.NewHttpApplicationClient(token, address, path) } // NewCommand returns a new instance of an event reporter command @@ -90,6 +91,7 @@ func NewCommand() *cobra.Command { codefreshUrl string codefreshToken string shardingAlgorithm string + rootpath string useGrpc bool ) var command = &cobra.Command{ @@ -165,7 +167,7 @@ func NewCommand() *cobra.Command { Cache: cache, RedisClient: redisClient, ApplicationNamespaces: applicationNamespaces, - ApplicationServiceClient: getApplicationClient(useGrpc, applicationServerAddress, argocdToken), + ApplicationServiceClient: getApplicationClient(useGrpc, applicationServerAddress, argocdToken, rootpath), CodefreshConfig: &codefresh.CodefreshConfig{ BaseURL: codefreshUrl, AuthToken: codefreshToken, @@ -194,6 +196,7 @@ func NewCommand() *cobra.Command { } clientConfig = cli.AddKubectlFlagsToCmd(command) + command.Flags().StringVar(&rootpath, "argocd-server-path", env.StringFromEnv("ARGOCD_SERVER_ROOTPATH", ""), "Used if Argo CD is running behind reverse proxy under subpath different from /") command.Flags().BoolVar(&insecure, "insecure", env.ParseBoolFromEnv("EVENT_REPORTER_INSECURE", false), "Run server without TLS") command.Flags().StringVar(&cmdutil.LogFormat, "logformat", env.StringFromEnv("EVENT_REPORTER_LOGFORMAT", "text"), "Set the logging format. One of: text|json") command.Flags().StringVar(&cmdutil.LogLevel, "loglevel", env.StringFromEnv("EVENT_REPORTER_LOG_LEVEL", "info"), "Set the logging level. One of: debug|info|warn|error") diff --git a/event_reporter/application/client.go b/event_reporter/application/client.go index e0212e902953a..73cff77eb7891 100644 --- a/event_reporter/application/client.go +++ b/event_reporter/application/client.go @@ -32,19 +32,29 @@ type httpApplicationClient struct { httpClient *http.Client baseUrl string token string + rootpath string } -func NewHttpApplicationClient(token string, address string) ApplicationClient { +func NewHttpApplicationClient(token string, address string, rootpath string) ApplicationClient { + if rootpath != "" && !strings.HasPrefix(rootpath, "/") { + rootpath = "/" + rootpath + } + if !strings.Contains(address, "http") { address = "http://" + address } + if rootpath != "" { + address = address + rootpath + } + return &httpApplicationClient{ httpClient: &http.Client{ Timeout: 30 * time.Second, }, - baseUrl: address, - token: token, + baseUrl: address, + token: token, + rootpath: rootpath, } }