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

fix: Set root path #3475

Merged
merged 4 commits into from
Apr 27, 2020
Merged

fix: Set root path #3475

merged 4 commits into from
Apr 27, 2020

Conversation

mayzhang2000
Copy link
Contributor

Checklist:

  • Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this does not need to be in the release notes.
  • The title of the PR states what changed and the related issues number (used for the release note).
  • I've updated both the CLI and UI to expose my feature, or I plan to submit a second PR with them.
  • Optional. My organization is added to USERS.md.
  • I've signed the CLA and my build is green (troubleshooting builds).

@codecov
Copy link

codecov bot commented Apr 23, 2020

Codecov Report

Merging #3475 into master will decrease coverage by 0.13%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
cmd/argocd/commands/login.go 0.00% <0.00%> (ø)
cmd/argocd/commands/relogin.go 0.00% <0.00%> (ø)
cmd/argocd/commands/root.go 4.65% <0.00%> (-0.12%) ⬇️
server/server.go 56.58% <0.00%> (-1.01%) ⬇️
server/project/project.go 59.66% <0.00%> (-1.74%) ⬇️
ui/src/app/applications/components/utils.tsx 49.83% <0.00%> (ø)
ui/src/app/shared/services/projects-service.ts 19.71% <0.00%> (ø)
server/application/application.go 28.31% <0.00%> (+0.20%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7660e40...9e504fc. Read the comment docs.

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},
Copy link
Collaborator

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 /")
Copy link
Collaborator

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 /")
Copy link
Collaborator

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:

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.
@alexmt
Copy link
Collaborator

alexmt commented Apr 24, 2020

@mayzhang2000 ,

@gpaul brought up a good point in #3483 (comment)

argocd login --grpc-web-root-path /argocd should be stored in argocd config so user does not have to repeat that CLI flag in every argocd command. Can you please implement that change. Config is updated in CLI login command implementation:

localCfg.UpsertServer(localconfig.Server{
Server: server,
PlainText: globalClientOpts.PlainText,
Insecure: globalClientOpts.Insecure,
GRPCWeb: globalClientOpts.GRPCWeb,

@alexmt alexmt marked this pull request as ready for review April 24, 2020 21:35
@mayzhang2000 mayzhang2000 merged commit d77072b into argoproj:master Apr 27, 2020
@mayzhang2000
Copy link
Contributor Author

fixes #3319

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants