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

feat: support argocd server path #272

Merged
merged 2 commits into from
Dec 26, 2023
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
19 changes: 11 additions & 8 deletions cmd/event-reporter-server/commands/event_reporter_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -90,6 +91,7 @@ func NewCommand() *cobra.Command {
codefreshUrl string
codefreshToken string
shardingAlgorithm string
rootpath string
useGrpc bool
)
var command = &cobra.Command{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand Down
16 changes: 13 additions & 3 deletions event_reporter/application/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
Loading