-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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: Set root path #3475
fix: Set root path #3475
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3475 +/- ##
==========================================
- Coverage 43.22% 43.09% -0.14%
==========================================
Files 180 180
Lines 20090 20127 +37
Branches 273 237 -36
==========================================
- Hits 8684 8673 -11
- Misses 10407 10462 +55
+ Partials 999 992 -7
Continue to review full report at Codecov.
|
server/server.go
Outdated
@@ -525,7 +526,7 @@ func (a *ArgoCDServer) newHTTPServer(ctx context.Context, port int, grpcWebHandl | |||
httpS := http.Server{ | |||
Addr: endpoint, | |||
Handler: &handlerSwitcher{ | |||
handler: &bug21955Workaround{handler: mux}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works! Just want to suggest a slightly different approach to avoid coupling code related to golang bug workaround:
- Create handler which adds root prefix to any handler:
func withRootPath(handler http.Handler, root string) http.Handler {
// get rid of slashes
root = strings.TrimRight(strings.TrimLeft(root, "/"), "/")
mux := http.NewServeMux()
mux.Handle("/"+root+"/", http.StripPrefix("/"+root, handler))
return mux
}
- use it to add root path to argocd server here:
if rootPath != "" {
httpS.Handler = withRootPath(httpS.Handler, rootPath)
if httpsS != nil {
httpsS.Handler = withRootPath(httpsS.Handler, rootPath)
}
}
@@ -98,6 +100,7 @@ func NewCommand() *cobra.Command { | |||
command.Flags().BoolVar(&insecure, "insecure", false, "Run server without TLS") | |||
command.Flags().StringVar(&staticAssetsDir, "staticassets", "", "Static assets directory path") | |||
command.Flags().StringVar(&baseHRef, "basehref", "/", "Value for base href in index.html. Used if Argo CD is running behind reverse proxy under subpath different from /") | |||
command.Flags().StringVar(&rootPath, "rootpath", "", "Used if Argo CD is running behind reverse proxy under subpath different from /") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The --rootpath
flag is supposed to change both server-side and client-side behavior. So if it is specified we need to add root path on server-side and change UI basehref
as well.
I think we should just check if rootPath
if not empty and change baseHRef
to the same value. If for some reason user has specified conflictingbaseHRef
value then I suggest to print warning and override it with rootPath
@@ -98,6 +100,7 @@ func NewCommand() *cobra.Command { | |||
command.Flags().BoolVar(&insecure, "insecure", false, "Run server without TLS") | |||
command.Flags().StringVar(&staticAssetsDir, "staticassets", "", "Static assets directory path") | |||
command.Flags().StringVar(&baseHRef, "basehref", "/", "Value for base href in index.html. Used if Argo CD is running behind reverse proxy under subpath different from /") | |||
command.Flags().StringVar(&rootPath, "rootpath", "", "Used if Argo CD is running behind reverse proxy under subpath different from /") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Argo CD CLI has an option to talk to the server using grpc web protocol (e.g. argocd app list --grpc-web
).
The grpc web requests should use root path, so we need to add CLI flag to specify path. Can you please add --grpc-web-root-path
flag. If flag is set then CLI should send grpc web requests with the specified path. Request URL is constructed here:
argo-cd/pkg/apiclient/grpcproxy.go
Line 58 in 4bd8173
req, err := http.NewRequest(http.MethodPost, fmt.Sprintf("%s://%s%s", schema, c.ServerAddr, fullMethodName), bytes.NewReader(toFrame(msg))) |
For convenience we should assume that user wants to use grpc web if either --grpc-web
or --grpc-web-root-path
is set
updated baseHRef if --rootpath is set. added --grpc-web-root-path for CLI.
@gpaul brought up a good point in #3483 (comment)
argo-cd/cmd/argocd/commands/login.go Lines 112 to 116 in 73590e1
|
fixes #3319 |
fix: Set root path (argoproj#3475)
Checklist: