mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
Update according to review
This commit is contained in:
parent
f351691493
commit
6da2653b4a
@ -205,6 +205,9 @@ func GetRecentDockerContainersWithNameAndUUID(client DockerInterface, podFullNam
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetKubeletDockerContainerLogs returns logs of specific container
|
// GetKubeletDockerContainerLogs returns logs of specific container
|
||||||
|
// By default the function will return snapshot of the container log
|
||||||
|
// Log streaming is possible if 'follow' param is set to true
|
||||||
|
// Log tailing is possible when number of tailed lines are set and only if 'follow' is false
|
||||||
func GetKubeletDockerContainerLogs(client DockerInterface, containerID, tail string, follow bool, writer io.Writer) (err error) {
|
func GetKubeletDockerContainerLogs(client DockerInterface, containerID, tail string, follow bool, writer io.Writer) (err error) {
|
||||||
opts := docker.LogsOptions{
|
opts := docker.LogsOptions{
|
||||||
Container: containerID,
|
Container: containerID,
|
||||||
@ -214,9 +217,10 @@ func GetKubeletDockerContainerLogs(client DockerInterface, containerID, tail str
|
|||||||
ErrorStream: writer,
|
ErrorStream: writer,
|
||||||
Timestamps: true,
|
Timestamps: true,
|
||||||
RawTerminal: true,
|
RawTerminal: true,
|
||||||
|
Follow: follow,
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.Follow = follow; follow == false {
|
if !follow {
|
||||||
opts.Tail = tail
|
opts.Tail = tail
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,17 +98,17 @@ func (h *httpActionHandler) Run(podFullName, uuid string, container *api.Contain
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// flusherWriter provides wrapper for responseWriter with HTTP streaming capabilities
|
// FlusherWriter provides wrapper for responseWriter with HTTP streaming capabilities
|
||||||
type FlushWriter struct {
|
type FlushWriter struct {
|
||||||
flusher http.Flusher
|
flusher http.Flusher
|
||||||
writer io.Writer
|
writer io.Writer
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write is a flushWriter implementation of the io.Writer that sends any buffered data to the client.
|
// Write is a FlushWriter implementation of the io.Writer that sends any buffered data to the client.
|
||||||
func (fw *FlushWriter) Write(p []byte) (n int, err error) {
|
func (fw *FlushWriter) Write(p []byte) (n int, err error) {
|
||||||
n, err = fw.writer.Write(p)
|
n, err = fw.writer.Write(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return n, err
|
return
|
||||||
}
|
}
|
||||||
if fw.flusher != nil {
|
if fw.flusher != nil {
|
||||||
fw.flusher.Flush()
|
fw.flusher.Flush()
|
||||||
|
@ -145,7 +145,7 @@ func (s *Server) handleContainers(w http.ResponseWriter, req *http.Request) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleContainerLogs handles containerLogs request againts the Kubelet
|
// handleContainerLogs handles containerLogs request against the Kubelet
|
||||||
func (s *Server) handleContainerLogs(w http.ResponseWriter, req *http.Request) {
|
func (s *Server) handleContainerLogs(w http.ResponseWriter, req *http.Request) {
|
||||||
defer req.Body.Close()
|
defer req.Body.Close()
|
||||||
u, err := url.ParseRequestURI(req.RequestURI)
|
u, err := url.ParseRequestURI(req.RequestURI)
|
||||||
@ -153,27 +153,21 @@ func (s *Server) handleContainerLogs(w http.ResponseWriter, req *http.Request) {
|
|||||||
s.error(w, err)
|
s.error(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
uriValues := u.Query()
|
uriValues := u.Query()
|
||||||
|
containerID := uriValues.Get("containerid")
|
||||||
containerID := uriValues.Get("containerID")
|
|
||||||
follow := uriValues.Get("follow") == "1"
|
|
||||||
tail := uriValues.Get("tail")
|
|
||||||
|
|
||||||
if len(containerID) == 0 {
|
if len(containerID) == 0 {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
http.Error(w, `{"message": "Missing containerID= query entry."}`, http.StatusBadRequest)
|
||||||
http.Error(w, "Missing 'containerID=' query entry.", http.StatusBadRequest)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logWriter := httplog.LogOf(req, w)
|
follow, _ := strconv.ParseBool(uriValues.Get("follow"))
|
||||||
w = httplog.Unlogged(w)
|
tail := uriValues.Get("tail")
|
||||||
|
|
||||||
fw := FlushWriter{writer: w}
|
fw := FlushWriter{writer: w}
|
||||||
if flusher, ok := w.(http.Flusher); ok {
|
if flusher, ok := w.(http.Flusher); ok {
|
||||||
fw.flusher = flusher
|
fw.flusher = flusher
|
||||||
} else {
|
|
||||||
logWriter.Addf("unable to get Flusher")
|
|
||||||
http.NotFound(w, req)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Transfer-Encoding", "chunked")
|
w.Header().Set("Transfer-Encoding", "chunked")
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
err = s.host.GetKubeletContainerLogs(containerID, tail, follow, &fw)
|
err = s.host.GetKubeletContainerLogs(containerID, tail, follow, &fw)
|
||||||
|
@ -45,10 +45,6 @@ type fakeKubelet struct {
|
|||||||
containerLogsFunc func(containerID, tail string, follow bool, writer io.Writer) error
|
containerLogsFunc func(containerID, tail string, follow bool, writer io.Writer) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fk *fakeKubelet) GetKubeletContainerLogs(containerID, tail string, follow bool, writer io.Writer) error {
|
|
||||||
return fk.containerLogsFunc(containerID, tail, follow, writer)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fk *fakeKubelet) GetPodInfo(name, uuid string) (api.PodInfo, error) {
|
func (fk *fakeKubelet) GetPodInfo(name, uuid string) (api.PodInfo, error) {
|
||||||
return fk.infoFunc(name)
|
return fk.infoFunc(name)
|
||||||
}
|
}
|
||||||
@ -69,6 +65,10 @@ func (fk *fakeKubelet) ServeLogs(w http.ResponseWriter, req *http.Request) {
|
|||||||
fk.logFunc(w, req)
|
fk.logFunc(w, req)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fk *fakeKubelet) GetKubeletContainerLogs(containerID, tail string, follow bool, writer io.Writer) error {
|
||||||
|
return fk.containerLogsFunc(containerID, tail, follow, writer)
|
||||||
|
}
|
||||||
|
|
||||||
func (fk *fakeKubelet) RunInContainer(podFullName, uuid, containerName string, cmd []string) ([]byte, error) {
|
func (fk *fakeKubelet) RunInContainer(podFullName, uuid, containerName string, cmd []string) ([]byte, error) {
|
||||||
return fk.runFunc(podFullName, uuid, containerName, cmd)
|
return fk.runFunc(podFullName, uuid, containerName, cmd)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user