Commit 9677616e authored by Lantao Liu's avatar Lantao Liu

Address comments in #64006.

parent 5da925ad
...@@ -86,7 +86,7 @@ func (s *ContainerRuntimeOptions) AddFlags(fs *pflag.FlagSet) { ...@@ -86,7 +86,7 @@ func (s *ContainerRuntimeOptions) AddFlags(fs *pflag.FlagSet) {
// General settings. // General settings.
fs.StringVar(&s.ContainerRuntime, "container-runtime", s.ContainerRuntime, "The container runtime to use. Possible values: 'docker', 'remote', 'rkt (deprecated)'.") fs.StringVar(&s.ContainerRuntime, "container-runtime", s.ContainerRuntime, "The container runtime to use. Possible values: 'docker', 'remote', 'rkt (deprecated)'.")
fs.StringVar(&s.RuntimeCgroups, "runtime-cgroups", s.RuntimeCgroups, "Optional absolute name of cgroups to create and run the runtime in.") fs.StringVar(&s.RuntimeCgroups, "runtime-cgroups", s.RuntimeCgroups, "Optional absolute name of cgroups to create and run the runtime in.")
fs.BoolVar(&s.RedirectContainerStreaming, "redirect-container-streaming", s.RedirectContainerStreaming, "Enables container streaming redirect. If false, kubelet will proxy container streaming data between apiserver and container runtime; if true, kubelet will return an http redirect to apiserver, and apiserver will access container runtime directly. The proxy approach is more secure, but introduces some overhead. The redirect approach is more performant, but less secure because the connection between apiserver and container runtime is not authenticated.") fs.BoolVar(&s.RedirectContainerStreaming, "redirect-container-streaming", s.RedirectContainerStreaming, "Enables container streaming redirect. If false, kubelet will proxy container streaming data between apiserver and container runtime; if true, kubelet will return an http redirect to apiserver, and apiserver will access container runtime directly. The proxy approach is more secure, but introduces some overhead. The redirect approach is more performant, but less secure because the connection between apiserver and container runtime may not be authenticated.")
// Docker-specific settings. // Docker-specific settings.
fs.BoolVar(&s.ExperimentalDockershim, "experimental-dockershim", s.ExperimentalDockershim, "Enable dockershim only mode. In this mode, kubelet will only start dockershim without any other functionalities. This flag only serves test purpose, please do not use it unless you are conscious of what you are doing. [default=false]") fs.BoolVar(&s.ExperimentalDockershim, "experimental-dockershim", s.ExperimentalDockershim, "Enable dockershim only mode. In this mode, kubelet will only start dockershim without any other functionalities. This flag only serves test purpose, please do not use it unless you are conscious of what you are doing. [default=false]")
......
...@@ -411,7 +411,7 @@ func (ds *dockerService) Start(stopCh <-chan struct{}) error { ...@@ -411,7 +411,7 @@ func (ds *dockerService) Start(stopCh <-chan struct{}) error {
}() }()
go func() { go func() {
if err := ds.streamingServer.Start(true); err != nil && err != http.ErrServerClosed { if err := ds.streamingServer.Start(true); err != nil && err != http.ErrServerClosed {
glog.Fatalf("Failed to start streaming server: %v", err) glog.Fatalf("Streaming server stopped unexpectedly: %v", err)
} }
}() }()
} }
......
...@@ -631,6 +631,13 @@ func (r *responder) Error(w http.ResponseWriter, req *http.Request, err error) { ...@@ -631,6 +631,13 @@ func (r *responder) Error(w http.ResponseWriter, req *http.Request, err error) {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
} }
// proxyStream proxies stream to url.
func proxyStream(w http.ResponseWriter, r *http.Request, url *url.URL) {
// TODO(random-liu): Set MaxBytesPerSec to throttle the stream.
handler := proxy.NewUpgradeAwareHandler(url, nil /*transport*/, false /*wrapTransport*/, true /*upgradeRequired*/, &responder{})
handler.ServeHTTP(w, r)
}
// getAttach handles requests to attach to a container. // getAttach handles requests to attach to a container.
func (s *Server) getAttach(request *restful.Request, response *restful.Response) { func (s *Server) getAttach(request *restful.Request, response *restful.Response) {
params := getExecRequestParams(request) params := getExecRequestParams(request)
...@@ -657,8 +664,7 @@ func (s *Server) getAttach(request *restful.Request, response *restful.Response) ...@@ -657,8 +664,7 @@ func (s *Server) getAttach(request *restful.Request, response *restful.Response)
http.Redirect(response.ResponseWriter, request.Request, url.String(), http.StatusFound) http.Redirect(response.ResponseWriter, request.Request, url.String(), http.StatusFound)
return return
} }
handler := proxy.NewUpgradeAwareHandler(url, nil /*transport*/, false /*wrapTransport*/, false /*upgradeRequired*/, &responder{}) proxyStream(response.ResponseWriter, request.Request, url)
handler.ServeHTTP(response.ResponseWriter, request.Request)
} }
// getExec handles requests to run a command inside a container. // getExec handles requests to run a command inside a container.
...@@ -686,8 +692,7 @@ func (s *Server) getExec(request *restful.Request, response *restful.Response) { ...@@ -686,8 +692,7 @@ func (s *Server) getExec(request *restful.Request, response *restful.Response) {
http.Redirect(response.ResponseWriter, request.Request, url.String(), http.StatusFound) http.Redirect(response.ResponseWriter, request.Request, url.String(), http.StatusFound)
return return
} }
handler := proxy.NewUpgradeAwareHandler(url, nil /*transport*/, false /*wrapTransport*/, false /*upgradeRequired*/, &responder{}) proxyStream(response.ResponseWriter, request.Request, url)
handler.ServeHTTP(response.ResponseWriter, request.Request)
} }
// getRun handles requests to run a command inside a container. // getRun handles requests to run a command inside a container.
...@@ -753,8 +758,7 @@ func (s *Server) getPortForward(request *restful.Request, response *restful.Resp ...@@ -753,8 +758,7 @@ func (s *Server) getPortForward(request *restful.Request, response *restful.Resp
http.Redirect(response.ResponseWriter, request.Request, url.String(), http.StatusFound) http.Redirect(response.ResponseWriter, request.Request, url.String(), http.StatusFound)
return return
} }
handler := proxy.NewUpgradeAwareHandler(url, nil /*transport*/, false /*wrapTransport*/, false /*upgradeRequired*/, &responder{}) proxyStream(response.ResponseWriter, request.Request, url)
handler.ServeHTTP(response.ResponseWriter, request.Request)
} }
// ServeHTTP responds to HTTP requests on the Kubelet. // ServeHTTP responds to HTTP requests on the Kubelet.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment