mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 09:49:50 +00:00
Check Docker version in Kubelet /healthz handler
This commit is contained in:
parent
0b801a91b1
commit
78f66a6ce9
@ -1361,6 +1361,23 @@ func (kl *Kubelet) syncLoop(updates <-chan PodUpdate, handler SyncHandler) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns Docker version for this Kubelet.
|
||||||
|
func (kl *Kubelet) GetDockerVersion() (string, error) {
|
||||||
|
if kl.dockerClient == nil {
|
||||||
|
return "", fmt.Errorf("No Docker client")
|
||||||
|
}
|
||||||
|
env, err := kl.dockerClient.Version()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
for _, entry := range *env {
|
||||||
|
if strings.HasPrefix(entry, "Version=") {
|
||||||
|
return strings.Split(entry, "=")[1], nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "", fmt.Errorf("Docker version unknown")
|
||||||
|
}
|
||||||
|
|
||||||
// GetKubeletContainerLogs returns logs from the container
|
// GetKubeletContainerLogs returns logs from the container
|
||||||
// The second parameter of GetPodStatus and FindPodContainer methods represents pod UUID, which is allowed to be blank
|
// The second parameter of GetPodStatus and FindPodContainer methods represents pod UUID, which is allowed to be blank
|
||||||
// TODO: this method is returning logs of random container attempts, when it should be returning the most recent attempt
|
// TODO: this method is returning logs of random container attempts, when it should be returning the most recent attempt
|
||||||
|
@ -31,7 +31,6 @@ import (
|
|||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/healthz"
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/httplog"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/httplog"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
||||||
@ -64,6 +63,7 @@ func ListenAndServeKubeletServer(host HostInterface, address net.IP, port uint,
|
|||||||
type HostInterface interface {
|
type HostInterface interface {
|
||||||
GetContainerInfo(podFullName string, uid types.UID, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error)
|
GetContainerInfo(podFullName string, uid types.UID, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error)
|
||||||
GetRootInfo(req *info.ContainerInfoRequest) (*info.ContainerInfo, error)
|
GetRootInfo(req *info.ContainerInfoRequest) (*info.ContainerInfo, error)
|
||||||
|
GetDockerVersion() (string, error)
|
||||||
GetMachineInfo() (*info.MachineInfo, error)
|
GetMachineInfo() (*info.MachineInfo, error)
|
||||||
GetBoundPods() ([]api.BoundPod, error)
|
GetBoundPods() ([]api.BoundPod, error)
|
||||||
GetPodByName(namespace, name string) (*api.BoundPod, bool)
|
GetPodByName(namespace, name string) (*api.BoundPod, bool)
|
||||||
@ -88,7 +88,7 @@ func NewServer(host HostInterface, enableDebuggingHandlers bool) Server {
|
|||||||
|
|
||||||
// InstallDefaultHandlers registers the default set of supported HTTP request patterns with the mux.
|
// InstallDefaultHandlers registers the default set of supported HTTP request patterns with the mux.
|
||||||
func (s *Server) InstallDefaultHandlers() {
|
func (s *Server) InstallDefaultHandlers() {
|
||||||
healthz.InstallHandler(s.mux)
|
s.mux.HandleFunc("/healthz", s.handleHealthz)
|
||||||
s.mux.HandleFunc("/podInfo", s.handlePodInfoOld)
|
s.mux.HandleFunc("/podInfo", s.handlePodInfoOld)
|
||||||
s.mux.HandleFunc("/api/v1beta1/podInfo", s.handlePodInfoVersioned)
|
s.mux.HandleFunc("/api/v1beta1/podInfo", s.handlePodInfoVersioned)
|
||||||
s.mux.HandleFunc("/boundPods", s.handleBoundPods)
|
s.mux.HandleFunc("/boundPods", s.handleBoundPods)
|
||||||
@ -109,6 +109,25 @@ func (s *Server) error(w http.ResponseWriter, err error) {
|
|||||||
http.Error(w, fmt.Sprintf("Internal Error: %v", err), http.StatusInternalServerError)
|
http.Error(w, fmt.Sprintf("Internal Error: %v", err), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handleHealthz handles /healthz request and checks Docker version
|
||||||
|
func (s *Server) handleHealthz(w http.ResponseWriter, req *http.Request) {
|
||||||
|
version, err := s.host.GetDockerVersion()
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
w.Write([]byte("unknown Docker version"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const minDockerVersion = "1.3.0"
|
||||||
|
if version < minDockerVersion {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
msg := "Docker version is too old (" + version + ")"
|
||||||
|
w.Write([]byte(msg))
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
w.Write([]byte("ok"))
|
||||||
|
}
|
||||||
|
|
||||||
// handleContainerLogs handles containerLogs request against 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()
|
||||||
|
@ -42,6 +42,7 @@ type fakeKubelet struct {
|
|||||||
boundPodsFunc func() ([]api.BoundPod, error)
|
boundPodsFunc func() ([]api.BoundPod, error)
|
||||||
logFunc func(w http.ResponseWriter, req *http.Request)
|
logFunc func(w http.ResponseWriter, req *http.Request)
|
||||||
runFunc func(podFullName string, uid types.UID, containerName string, cmd []string) ([]byte, error)
|
runFunc func(podFullName string, uid types.UID, containerName string, cmd []string) ([]byte, error)
|
||||||
|
dockerVersionFunc func() (string, error)
|
||||||
containerLogsFunc func(podFullName, containerName, tail string, follow bool, stdout, stderr io.Writer) error
|
containerLogsFunc func(podFullName, containerName, tail string, follow bool, stdout, stderr io.Writer) error
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,6 +62,10 @@ func (fk *fakeKubelet) GetRootInfo(req *info.ContainerInfoRequest) (*info.Contai
|
|||||||
return fk.rootInfoFunc(req)
|
return fk.rootInfoFunc(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fk *fakeKubelet) GetDockerVersion() (string, error) {
|
||||||
|
return fk.dockerVersionFunc()
|
||||||
|
}
|
||||||
|
|
||||||
func (fk *fakeKubelet) GetMachineInfo() (*info.MachineInfo, error) {
|
func (fk *fakeKubelet) GetMachineInfo() (*info.MachineInfo, error) {
|
||||||
return fk.machineInfoFunc()
|
return fk.machineInfoFunc()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user