mirror of https://github.com/k3s-io/k3s
Load cadvisor connection in background.
parent
5d24820dd5
commit
1fc92bef53
|
@ -131,11 +131,6 @@ func main() {
|
||||||
glog.Fatal("Couldn't connect to docker.")
|
glog.Fatal("Couldn't connect to docker.")
|
||||||
}
|
}
|
||||||
|
|
||||||
cadvisorClient, err := cadvisor.NewClient("http://127.0.0.1:4194")
|
|
||||||
if err != nil {
|
|
||||||
glog.Errorf("Error on creating cadvisor client: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
hostname := getHostname()
|
hostname := getHostname()
|
||||||
|
|
||||||
if *rootDirectory == "" {
|
if *rootDirectory == "" {
|
||||||
|
@ -182,7 +177,6 @@ func main() {
|
||||||
k := kubelet.NewMainKubelet(
|
k := kubelet.NewMainKubelet(
|
||||||
getHostname(),
|
getHostname(),
|
||||||
dockerClient,
|
dockerClient,
|
||||||
cadvisorClient,
|
|
||||||
etcdClient,
|
etcdClient,
|
||||||
*rootDirectory,
|
*rootDirectory,
|
||||||
*networkContainerImage,
|
*networkContainerImage,
|
||||||
|
@ -190,6 +184,19 @@ func main() {
|
||||||
float32(*registryPullQPS),
|
float32(*registryPullQPS),
|
||||||
*registryBurst)
|
*registryBurst)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer util.HandleCrash()
|
||||||
|
// TODO: Monitor this connection, reconnect if needed?
|
||||||
|
glog.V(1).Infof("Trying to create cadvisor client.")
|
||||||
|
cadvisorClient, err := cadvisor.NewClient("http://127.0.0.1:4194")
|
||||||
|
if err != nil {
|
||||||
|
glog.Errorf("Error on creating cadvisor client: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
glog.V(1).Infof("Successfully created cadvisor client.")
|
||||||
|
k.SetCadvisorClient(cadvisorClient)
|
||||||
|
}()
|
||||||
|
|
||||||
// TODO: These should probably become more plugin-ish: register a factory func
|
// TODO: These should probably become more plugin-ish: register a factory func
|
||||||
// in each checker's init(), iterate those here.
|
// in each checker's init(), iterate those here.
|
||||||
health.AddHealthChecker(health.NewExecHealthChecker(k))
|
health.AddHealthChecker(health.NewExecHealthChecker(k))
|
||||||
|
|
|
@ -64,7 +64,6 @@ type volumeMap map[string]volume.Interface
|
||||||
func NewMainKubelet(
|
func NewMainKubelet(
|
||||||
hn string,
|
hn string,
|
||||||
dc dockertools.DockerInterface,
|
dc dockertools.DockerInterface,
|
||||||
cc CadvisorInterface,
|
|
||||||
ec tools.EtcdClient,
|
ec tools.EtcdClient,
|
||||||
rd string,
|
rd string,
|
||||||
ni string,
|
ni string,
|
||||||
|
@ -74,7 +73,6 @@ func NewMainKubelet(
|
||||||
return &Kubelet{
|
return &Kubelet{
|
||||||
hostname: hn,
|
hostname: hn,
|
||||||
dockerClient: dc,
|
dockerClient: dc,
|
||||||
cadvisorClient: cc,
|
|
||||||
etcdClient: ec,
|
etcdClient: ec,
|
||||||
rootDirectory: rd,
|
rootDirectory: rd,
|
||||||
resyncInterval: ri,
|
resyncInterval: ri,
|
||||||
|
@ -117,8 +115,6 @@ type Kubelet struct {
|
||||||
|
|
||||||
// Optional, no events will be sent without it
|
// Optional, no events will be sent without it
|
||||||
etcdClient tools.EtcdClient
|
etcdClient tools.EtcdClient
|
||||||
// Optional, no statistics will be available if omitted
|
|
||||||
cadvisorClient CadvisorInterface
|
|
||||||
// Optional, defaults to simple implementaiton
|
// Optional, defaults to simple implementaiton
|
||||||
healthChecker health.HealthChecker
|
healthChecker health.HealthChecker
|
||||||
// Optional, defaults to simple Docker implementation
|
// Optional, defaults to simple Docker implementation
|
||||||
|
@ -133,6 +129,24 @@ type Kubelet struct {
|
||||||
pullQPS float32
|
pullQPS float32
|
||||||
// Optional, maximum burst QPS from the docker registry, must be positive if QPS is > 0.0
|
// Optional, maximum burst QPS from the docker registry, must be positive if QPS is > 0.0
|
||||||
pullBurst int
|
pullBurst int
|
||||||
|
|
||||||
|
// Optional, no statistics will be available if omitted
|
||||||
|
cadvisorClient CadvisorInterface
|
||||||
|
cadvisorLock sync.RWMutex
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCadvisorClient sets the cadvisor client in a thread-safe way.
|
||||||
|
func (kl *Kubelet) SetCadvisorClient(c CadvisorInterface) {
|
||||||
|
kl.cadvisorLock.Lock()
|
||||||
|
defer kl.cadvisorLock.Unlock()
|
||||||
|
kl.cadvisorClient = c
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCadvisorClient gets the cadvisor client.
|
||||||
|
func (kl *Kubelet) GetCadvisorClient() CadvisorInterface {
|
||||||
|
kl.cadvisorLock.RLock()
|
||||||
|
defer kl.cadvisorLock.RUnlock()
|
||||||
|
return kl.cadvisorClient
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run starts the kubelet reacting to config updates
|
// Run starts the kubelet reacting to config updates
|
||||||
|
@ -742,8 +756,8 @@ func getCadvisorContainerInfoRequest(req *info.ContainerInfoRequest) *info.Conta
|
||||||
// container. The container's absolute path refers to its hierarchy in the
|
// container. The container's absolute path refers to its hierarchy in the
|
||||||
// cgroup file system. e.g. The root container, which represents the whole
|
// cgroup file system. e.g. The root container, which represents the whole
|
||||||
// machine, has path "/"; all docker containers have path "/docker/<docker id>"
|
// machine, has path "/"; all docker containers have path "/docker/<docker id>"
|
||||||
func (kl *Kubelet) statsFromContainerPath(containerPath string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) {
|
func (kl *Kubelet) statsFromContainerPath(cc CadvisorInterface, containerPath string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) {
|
||||||
cinfo, err := kl.cadvisorClient.ContainerInfo(containerPath, getCadvisorContainerInfoRequest(req))
|
cinfo, err := cc.ContainerInfo(containerPath, getCadvisorContainerInfoRequest(req))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -782,7 +796,8 @@ func (kl *Kubelet) GetPodInfo(podFullName, uuid string) (api.PodInfo, error) {
|
||||||
|
|
||||||
// GetContainerInfo returns stats (from Cadvisor) for a container.
|
// GetContainerInfo returns stats (from Cadvisor) for a container.
|
||||||
func (kl *Kubelet) GetContainerInfo(podFullName, uuid, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) {
|
func (kl *Kubelet) GetContainerInfo(podFullName, uuid, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) {
|
||||||
if kl.cadvisorClient == nil {
|
cc := kl.GetCadvisorClient()
|
||||||
|
if cc == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
dockerContainers, err := dockertools.GetKubeletDockerContainers(kl.dockerClient, false)
|
dockerContainers, err := dockertools.GetKubeletDockerContainers(kl.dockerClient, false)
|
||||||
|
@ -793,16 +808,24 @@ func (kl *Kubelet) GetContainerInfo(podFullName, uuid, containerName string, req
|
||||||
if !found {
|
if !found {
|
||||||
return nil, errors.New("couldn't find container")
|
return nil, errors.New("couldn't find container")
|
||||||
}
|
}
|
||||||
return kl.statsFromContainerPath(fmt.Sprintf("/docker/%s", dockerContainer.ID), req)
|
return kl.statsFromContainerPath(cc, fmt.Sprintf("/docker/%s", dockerContainer.ID), req)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRootInfo returns stats (from Cadvisor) of current machine (root container).
|
// GetRootInfo returns stats (from Cadvisor) of current machine (root container).
|
||||||
func (kl *Kubelet) GetRootInfo(req *info.ContainerInfoRequest) (*info.ContainerInfo, error) {
|
func (kl *Kubelet) GetRootInfo(req *info.ContainerInfoRequest) (*info.ContainerInfo, error) {
|
||||||
return kl.statsFromContainerPath("/", req)
|
cc := kl.GetCadvisorClient()
|
||||||
|
if cc == nil {
|
||||||
|
return nil, fmt.Errorf("no cadvisor connection")
|
||||||
|
}
|
||||||
|
return kl.statsFromContainerPath(cc, "/", req)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (kl *Kubelet) GetMachineInfo() (*info.MachineInfo, error) {
|
func (kl *Kubelet) GetMachineInfo() (*info.MachineInfo, error) {
|
||||||
return kl.cadvisorClient.MachineInfo()
|
cc := kl.GetCadvisorClient()
|
||||||
|
if cc == nil {
|
||||||
|
return nil, fmt.Errorf("no cadvisor connection")
|
||||||
|
}
|
||||||
|
return cc.MachineInfo()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (kl *Kubelet) healthy(podFullName string, currentState api.PodState, container api.Container, dockerContainer *docker.APIContainers) (health.Status, error) {
|
func (kl *Kubelet) healthy(podFullName string, currentState api.PodState, container api.Container, dockerContainer *docker.APIContainers) (health.Status, error) {
|
||||||
|
|
Loading…
Reference in New Issue