mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 18:54:06 +00:00
Merge pull request #22966 from timstclair/server
Auto commit by PR queue bot
This commit is contained in:
commit
71a3b91ac1
@ -495,7 +495,7 @@ func (s *Server) getPods(request *restful.Request, response *restful.Response) {
|
|||||||
response.WriteError(http.StatusInternalServerError, err)
|
response.WriteError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
response.Write(data)
|
writeJsonResponse(response, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// getRunningPods returns a list of pods running on Kubelet. The list is
|
// getRunningPods returns a list of pods running on Kubelet. The list is
|
||||||
@ -512,7 +512,7 @@ func (s *Server) getRunningPods(request *restful.Request, response *restful.Resp
|
|||||||
response.WriteError(http.StatusInternalServerError, err)
|
response.WriteError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
response.Write(data)
|
writeJsonResponse(response, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// getLogs handles logs requests against the Kubelet.
|
// getLogs handles logs requests against the Kubelet.
|
||||||
@ -585,7 +585,7 @@ func (s *Server) getRun(request *restful.Request, response *restful.Response) {
|
|||||||
response.WriteError(http.StatusInternalServerError, err)
|
response.WriteError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
response.Write(data)
|
writeJsonResponse(response, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// getExec handles requests to run a command inside a container.
|
// getExec handles requests to run a command inside a container.
|
||||||
@ -778,6 +778,20 @@ func getPodCoordinates(request *restful.Request) (namespace, pod string, uid typ
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Derived from go-restful writeJSON.
|
||||||
|
func writeJsonResponse(response *restful.Response, data []byte) {
|
||||||
|
if data == nil {
|
||||||
|
response.WriteHeader(http.StatusOK)
|
||||||
|
// do not write a nil representation
|
||||||
|
return
|
||||||
|
}
|
||||||
|
response.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
|
||||||
|
response.WriteHeader(http.StatusOK)
|
||||||
|
if _, err := response.Write(data); err != nil {
|
||||||
|
glog.Errorf("Error writing response: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// PortForwarder knows how to forward content from a data stream to/from a port
|
// PortForwarder knows how to forward content from a data stream to/from a port
|
||||||
// in a pod.
|
// in a pod.
|
||||||
type PortForwarder interface {
|
type PortForwarder interface {
|
||||||
|
@ -220,12 +220,8 @@ func (h *handler) handlePodContainer(request *restful.Request, response *restful
|
|||||||
}
|
}
|
||||||
|
|
||||||
func writeResponse(response *restful.Response, stats interface{}) {
|
func writeResponse(response *restful.Response, stats interface{}) {
|
||||||
if stats == nil {
|
if err := response.WriteAsJson(stats); err != nil {
|
||||||
return
|
glog.Errorf("Error writing response: %v", err)
|
||||||
}
|
|
||||||
err := response.WriteAsJson(stats)
|
|
||||||
if err != nil {
|
|
||||||
handleError(response, err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,7 +232,7 @@ func handleError(response *restful.Response, err error) {
|
|||||||
response.WriteError(http.StatusNotFound, err)
|
response.WriteError(http.StatusNotFound, err)
|
||||||
default:
|
default:
|
||||||
msg := fmt.Sprintf("Internal Error: %v", err)
|
msg := fmt.Sprintf("Internal Error: %v", err)
|
||||||
glog.Infof("HTTP InternalServerError: %s", msg)
|
glog.Errorf("HTTP InternalServerError: %s", msg)
|
||||||
response.WriteErrorString(http.StatusInternalServerError, msg)
|
response.WriteErrorString(http.StatusInternalServerError, msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user