Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
6913cf4b
Commit
6913cf4b
authored
Oct 08, 2014
by
Brendan Burns
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1666 from lavalamp/fix
Load cadvisor connection in background.
parents
5d24820d
1fc92bef
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
16 deletions
+46
-16
kubelet.go
cmd/kubelet/kubelet.go
+13
-6
kubelet.go
pkg/kubelet/kubelet.go
+33
-10
No files found.
cmd/kubelet/kubelet.go
View file @
6913cf4b
...
@@ -131,11 +131,6 @@ func main() {
...
@@ -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() {
...
@@ -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() {
...
@@ -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
))
...
...
pkg/kubelet/kubelet.go
View file @
6913cf4b
...
@@ -64,7 +64,6 @@ type volumeMap map[string]volume.Interface
...
@@ -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(
...
@@ -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 {
...
@@ -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 {
...
@@ -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
...
@@ -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
(
c
c
CadvisorInterface
,
c
ontainerPath
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) {
...
@@ -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
...
@@ -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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment