-
Notifications
You must be signed in to change notification settings - Fork 554
[Feat][apiserver] Support CORS config #3711
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][apiserver] Support CORS config #3711
Conversation
Signed-off-by: Chi-Sheng Liu <[email protected]>
6c97057
to
fe6d95d
Compare
apiserver/cmd/main.go
Outdated
@@ -165,8 +165,27 @@ func startHttpProxy() { | |||
topMux = http.NewServeMux() | |||
} | |||
|
|||
// Seems /apis (matches /apis/v1alpha1/clusters) works fine | |||
topMux.Handle("/", runtimeMux) | |||
if allowedOrigin := os.Getenv("CORS_ALLOW_ORIGIN"); allowedOrigin != "" { |
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.
Print a log so that users can know whether CORS is enabled or not?
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.
done
@@ -11,6 +11,9 @@ image: | |||
tag: nightly | |||
pullPolicy: IfNotPresent | |||
|
|||
cors: | |||
# allowOrigin: "*" |
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.
What does "*" mean? Can you add some comments to explain what are valid values and the expected behavior?
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.
done
@@ -52,6 +52,13 @@ spec: | |||
httpGet: | |||
path: /healthz | |||
port: http | |||
env: |
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.
Maybe pass to args
instead so that we don't need to handle the complex merge logic of env
in the future.
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.
done
apiserver/cmd/main.go
Outdated
@@ -165,8 +165,27 @@ func startHttpProxy() { | |||
topMux = http.NewServeMux() | |||
} | |||
|
|||
// Seems /apis (matches /apis/v1alpha1/clusters) works fine | |||
topMux.Handle("/", runtimeMux) | |||
if allowedOrigin := os.Getenv("CORS_ALLOW_ORIGIN"); allowedOrigin != "" { |
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 seems to be a breaking change for users when users use their old Values.yaml
with the new api server image.
The same YAML with old image will enable CORS, but CORS will be disabled with the new image.
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.
What do you mean? If users use old values.yaml
, then CORS_ALLOW_ORIGIN
won't be set, and the else
block will be executed. So topMux.Handle("/", runtimeMux)
will still be run. There is no behavior change.
apiserver/cmd/main.go
Outdated
}) | ||
} | ||
|
||
topMux.Handle("/", corsHandler(runtimeMux)) |
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.
Could we just use https://github.com/rs/cors?
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.
done
Signed-off-by: Chi-Sheng Liu <[email protected]>
Signed-off-by: Chi-Sheng Liu <[email protected]>
Signed-off-by: Chi-Sheng Liu <[email protected]>
Why are these changes needed?
Add CORS config to apiserver v1, so that KubeRay dashboard can be easily run.
Manual testing:
Related issue number
N/A
Checks