提交 b0edca7d 编写于 作者: S Steffen Hanikel 提交者: Sebastian Florek

Allow overriding the bearer token via an authorization header (#1539)

* Allow overriding the bearer token via an authorization header

* Inject apiClient centrally to reduce code duplication

* Dynamically create the resourceVerber in order to allow injecting authentication data

* Added bind-address cli option

* Create kubernetes clientConfig and client dynamically in apihandler

 This makes it easier to properly override the authorization token
 per request.

* Added workaround for broken auth when running in a cluster

* Fixed crash, when config could not be loaded

* Use the request filter chain to inject the apiclient and apiconfig

* Minor cleanup of apihandler.go

- Run of gulp format
- Removed unused parameter
- Moved getting the apiclient/config into a helper function
上级 8ec527c3
......@@ -56,10 +56,10 @@ func buildConfigFromFlags(masterUrl, kubeconfigPath string) (*rest.Config, error
//
// apiserverHost param is in the format of protocol://address:port/pathPrefix, e.g.http://localhost:8001.
// kubeConfig location of kubeconfig file
func CreateApiserverClient(apiserverHost string, kubeConfig string) (*kubernetes.Clientset, *rest.Config, error) {
func CreateApiserverClient(apiserverHost string, kubeConfig string) (*kubernetes.Clientset, error) {
cfg, err := buildConfigFromFlags(apiserverHost, kubeConfig)
if err != nil {
return nil, nil, err
return nil, err
}
cfg.QPS = defaultQPS
......@@ -70,8 +70,8 @@ func CreateApiserverClient(apiserverHost string, kubeConfig string) (*kubernetes
client, err := kubernetes.NewForConfig(cfg)
if err != nil {
return nil, nil, err
return nil, err
}
return client, cfg, nil
return client, nil
}
......@@ -62,7 +62,7 @@ func main() {
log.Printf("Using kubeconfig file: %s", *argKubeConfigFile)
}
apiserverClient, config, err := client.CreateApiserverClient(*argApiserverHost, *argKubeConfigFile)
apiserverClient, err := client.CreateApiserverClient(*argApiserverHost, *argKubeConfigFile)
if err != nil {
handleFatalInitError(err)
}
......@@ -78,7 +78,9 @@ func main() {
log.Printf("Could not create heapster client: %s. Continuing.", err)
}
apiHandler, err := handler.CreateHTTPAPIHandler(apiserverClient, heapsterRESTClient, config)
apiHandler, err := handler.CreateHTTPAPIHandler(
heapsterRESTClient,
handler.ApiClientConfig{ApiserverHost: *argApiserverHost, KubeConfigFile: *argKubeConfigFile})
if err != nil {
handleFatalInitError(err)
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册