mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-11 06:02:18 +00:00
Clean up how client is passed to Kubelet in preparation for reading pods
Also fixes how Kubelet server looks up pods by name when there are multiple sources.
This commit is contained in:
@@ -33,7 +33,6 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/healthz"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/httplog"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
"github.com/golang/glog"
|
||||
"github.com/google/cadvisor/info"
|
||||
@@ -66,6 +65,7 @@ type HostInterface interface {
|
||||
GetRootInfo(req *info.ContainerInfoRequest) (*info.ContainerInfo, error)
|
||||
GetMachineInfo() (*info.MachineInfo, error)
|
||||
GetBoundPods() ([]api.BoundPod, error)
|
||||
GetPodByName(namespace, name string) (*api.BoundPod, bool)
|
||||
GetPodInfo(name, uuid string) (api.PodInfo, error)
|
||||
RunInContainer(name, uuid, container string, cmd []string) ([]byte, error)
|
||||
GetKubeletContainerLogs(podFullName, containerName, tail string, follow bool, stdout, stderr io.Writer) error
|
||||
@@ -146,13 +146,11 @@ func (s *Server) handleContainerLogs(w http.ResponseWriter, req *http.Request) {
|
||||
follow, _ := strconv.ParseBool(uriValues.Get("follow"))
|
||||
tail := uriValues.Get("tail")
|
||||
|
||||
podFullName := GetPodFullName(&api.BoundPod{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: podID,
|
||||
Namespace: podNamespace,
|
||||
Annotations: map[string]string{ConfigSourceAnnotationKey: "etcd"},
|
||||
},
|
||||
})
|
||||
pod, ok := s.host.GetPodByName(podNamespace, podID)
|
||||
if !ok {
|
||||
http.Error(w, "Pod does not exist", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
fw := FlushWriter{writer: w}
|
||||
if flusher, ok := fw.writer.(http.Flusher); ok {
|
||||
@@ -162,7 +160,7 @@ func (s *Server) handleContainerLogs(w http.ResponseWriter, req *http.Request) {
|
||||
}
|
||||
w.Header().Set("Transfer-Encoding", "chunked")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
err = s.host.GetKubeletContainerLogs(podFullName, containerName, tail, follow, &fw, &fw)
|
||||
err = s.host.GetKubeletContainerLogs(GetPodFullName(pod), containerName, tail, follow, &fw, &fw)
|
||||
if err != nil {
|
||||
s.error(w, err)
|
||||
return
|
||||
@@ -217,19 +215,12 @@ func (s *Server) handlePodInfo(w http.ResponseWriter, req *http.Request, version
|
||||
http.Error(w, "Missing 'podNamespace=' query entry.", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
// TODO: backwards compatibility with existing API, needs API change
|
||||
podFullName := GetPodFullName(&api.BoundPod{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: podID,
|
||||
Namespace: podNamespace,
|
||||
Annotations: map[string]string{ConfigSourceAnnotationKey: "etcd"},
|
||||
},
|
||||
})
|
||||
info, err := s.host.GetPodInfo(podFullName, podUUID)
|
||||
if err == dockertools.ErrNoContainersInPod {
|
||||
http.Error(w, "api.BoundPod does not exist", http.StatusNotFound)
|
||||
pod, ok := s.host.GetPodByName(podNamespace, podID)
|
||||
if !ok {
|
||||
http.Error(w, "Pod does not exist", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
info, err := s.host.GetPodInfo(GetPodFullName(pod), podUUID)
|
||||
if err != nil {
|
||||
s.error(w, err)
|
||||
return
|
||||
@@ -293,15 +284,13 @@ func (s *Server) handleRun(w http.ResponseWriter, req *http.Request) {
|
||||
http.Error(w, "Unexpected path for command running", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
podFullName := GetPodFullName(&api.BoundPod{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: podID,
|
||||
Namespace: podNamespace,
|
||||
Annotations: map[string]string{ConfigSourceAnnotationKey: "etcd"},
|
||||
},
|
||||
})
|
||||
pod, ok := s.host.GetPodByName(podNamespace, podID)
|
||||
if !ok {
|
||||
http.Error(w, "Pod does not exist", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
command := strings.Split(u.Query().Get("cmd"), " ")
|
||||
data, err := s.host.RunInContainer(podFullName, uuid, container, command)
|
||||
data, err := s.host.RunInContainer(GetPodFullName(pod), uuid, container, command)
|
||||
if err != nil {
|
||||
s.error(w, err)
|
||||
return
|
||||
@@ -344,24 +333,20 @@ func (s *Server) serveStats(w http.ResponseWriter, req *http.Request) {
|
||||
// TODO(monnand) Implement this
|
||||
errors.New("pod level status currently unimplemented")
|
||||
case 3:
|
||||
// Backward compatibility without uuid information
|
||||
podFullName := GetPodFullName(&api.BoundPod{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: components[1],
|
||||
Namespace: api.NamespaceDefault,
|
||||
Annotations: map[string]string{ConfigSourceAnnotationKey: "etcd"},
|
||||
},
|
||||
})
|
||||
stats, err = s.host.GetContainerInfo(podFullName, "", components[2], &query)
|
||||
// Backward compatibility without uuid information, does not support namespace
|
||||
pod, ok := s.host.GetPodByName(api.NamespaceDefault, components[1])
|
||||
if !ok {
|
||||
http.Error(w, "Pod does not exist", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
stats, err = s.host.GetContainerInfo(GetPodFullName(pod), "", components[2], &query)
|
||||
case 5:
|
||||
podFullName := GetPodFullName(&api.BoundPod{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: components[2],
|
||||
Namespace: components[1],
|
||||
Annotations: map[string]string{ConfigSourceAnnotationKey: "etcd"},
|
||||
},
|
||||
})
|
||||
stats, err = s.host.GetContainerInfo(podFullName, components[3], components[4], &query)
|
||||
pod, ok := s.host.GetPodByName(components[1], components[2])
|
||||
if !ok {
|
||||
http.Error(w, "Pod does not exist", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
stats, err = s.host.GetContainerInfo(GetPodFullName(pod), components[3], components[4], &query)
|
||||
default:
|
||||
http.Error(w, "unknown resource.", http.StatusNotFound)
|
||||
return
|
||||
|
Reference in New Issue
Block a user