mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
Kubelet should have a max think time before auto resync
The sync frequency should be part of the syncLoop and resync no less often than every X seconds. The current implementation runs even if a config update was delivered less than X seconds ago.
This commit is contained in:
parent
b43e3865b4
commit
d7f46718a8
@ -115,7 +115,6 @@ func startComponents(manifestURL string) (apiServerURL string) {
|
|||||||
config.NewSourceURL(manifestURL, 5*time.Second, cfg1.Channel("url"))
|
config.NewSourceURL(manifestURL, 5*time.Second, cfg1.Channel("url"))
|
||||||
myKubelet := kubelet.NewIntegrationTestKubelet(machineList[0], &fakeDocker1)
|
myKubelet := kubelet.NewIntegrationTestKubelet(machineList[0], &fakeDocker1)
|
||||||
go util.Forever(func() { myKubelet.Run(cfg1.Updates()) }, 0)
|
go util.Forever(func() { myKubelet.Run(cfg1.Updates()) }, 0)
|
||||||
go util.Forever(cfg1.Sync, 3*time.Second)
|
|
||||||
go util.Forever(func() {
|
go util.Forever(func() {
|
||||||
kubelet.ListenAndServeKubeletServer(myKubelet, cfg1.Channel("http"), http.DefaultServeMux, "localhost", 10250)
|
kubelet.ListenAndServeKubeletServer(myKubelet, cfg1.Channel("http"), http.DefaultServeMux, "localhost", 10250)
|
||||||
}, 0)
|
}, 0)
|
||||||
@ -127,7 +126,6 @@ func startComponents(manifestURL string) (apiServerURL string) {
|
|||||||
config.NewSourceEtcd(config.EtcdKeyForHost(machineList[1]), etcdClient, 30*time.Second, cfg2.Channel("etcd"))
|
config.NewSourceEtcd(config.EtcdKeyForHost(machineList[1]), etcdClient, 30*time.Second, cfg2.Channel("etcd"))
|
||||||
otherKubelet := kubelet.NewIntegrationTestKubelet(machineList[1], &fakeDocker2)
|
otherKubelet := kubelet.NewIntegrationTestKubelet(machineList[1], &fakeDocker2)
|
||||||
go util.Forever(func() { otherKubelet.Run(cfg2.Updates()) }, 0)
|
go util.Forever(func() { otherKubelet.Run(cfg2.Updates()) }, 0)
|
||||||
go util.Forever(cfg2.Sync, 3*time.Second)
|
|
||||||
go util.Forever(func() {
|
go util.Forever(func() {
|
||||||
kubelet.ListenAndServeKubeletServer(otherKubelet, cfg2.Channel("http"), http.DefaultServeMux, "localhost", 10251)
|
kubelet.ListenAndServeKubeletServer(otherKubelet, cfg2.Channel("http"), http.DefaultServeMux, "localhost", 10251)
|
||||||
}, 0)
|
}, 0)
|
||||||
|
@ -148,16 +148,12 @@ func main() {
|
|||||||
dockerClient,
|
dockerClient,
|
||||||
cadvisorClient,
|
cadvisorClient,
|
||||||
etcdClient,
|
etcdClient,
|
||||||
*rootDirectory)
|
*rootDirectory,
|
||||||
|
*syncFrequency)
|
||||||
|
|
||||||
// start the kubelet
|
// start the kubelet
|
||||||
go util.Forever(func() { k.Run(cfg.Updates()) }, 0)
|
go util.Forever(func() { k.Run(cfg.Updates()) }, 0)
|
||||||
|
|
||||||
// resynchronize periodically
|
|
||||||
// TODO: make this part of PodConfig so that it is only delivered after syncFrequency has elapsed without
|
|
||||||
// an update
|
|
||||||
go util.Forever(cfg.Sync, *syncFrequency)
|
|
||||||
|
|
||||||
// start the kubelet server
|
// start the kubelet server
|
||||||
if *enableServer {
|
if *enableServer {
|
||||||
go util.Forever(func() {
|
go util.Forever(func() {
|
||||||
|
@ -64,13 +64,15 @@ func NewMainKubelet(
|
|||||||
dc DockerInterface,
|
dc DockerInterface,
|
||||||
cc CadvisorInterface,
|
cc CadvisorInterface,
|
||||||
ec tools.EtcdClient,
|
ec tools.EtcdClient,
|
||||||
rd string) *Kubelet {
|
rd string,
|
||||||
|
ri time.Duration) *Kubelet {
|
||||||
return &Kubelet{
|
return &Kubelet{
|
||||||
hostname: hn,
|
hostname: hn,
|
||||||
dockerClient: dc,
|
dockerClient: dc,
|
||||||
cadvisorClient: cc,
|
cadvisorClient: cc,
|
||||||
etcdClient: ec,
|
etcdClient: ec,
|
||||||
rootDirectory: rd,
|
rootDirectory: rd,
|
||||||
|
resyncInterval: ri,
|
||||||
podWorkers: newPodWorkers(),
|
podWorkers: newPodWorkers(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -82,6 +84,7 @@ func NewIntegrationTestKubelet(hn string, dc DockerInterface) *Kubelet {
|
|||||||
hostname: hn,
|
hostname: hn,
|
||||||
dockerClient: dc,
|
dockerClient: dc,
|
||||||
dockerPuller: &FakeDockerPuller{},
|
dockerPuller: &FakeDockerPuller{},
|
||||||
|
resyncInterval: 3 * time.Second,
|
||||||
podWorkers: newPodWorkers(),
|
podWorkers: newPodWorkers(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,6 +95,7 @@ type Kubelet struct {
|
|||||||
dockerClient DockerInterface
|
dockerClient DockerInterface
|
||||||
rootDirectory string
|
rootDirectory string
|
||||||
podWorkers podWorkers
|
podWorkers podWorkers
|
||||||
|
resyncInterval time.Duration
|
||||||
|
|
||||||
// Optional, no events will be sent without it
|
// Optional, no events will be sent without it
|
||||||
etcdClient tools.EtcdClient
|
etcdClient tools.EtcdClient
|
||||||
@ -561,14 +565,15 @@ func filterHostPortConflicts(pods []Pod) []Pod {
|
|||||||
// no changes are seen to the configuration, will synchronize the last known desired
|
// no changes are seen to the configuration, will synchronize the last known desired
|
||||||
// state every sync_frequency seconds. Never returns.
|
// state every sync_frequency seconds. Never returns.
|
||||||
func (kl *Kubelet) syncLoop(updates <-chan PodUpdate, handler SyncHandler) {
|
func (kl *Kubelet) syncLoop(updates <-chan PodUpdate, handler SyncHandler) {
|
||||||
for {
|
|
||||||
var pods []Pod
|
var pods []Pod
|
||||||
|
for {
|
||||||
select {
|
select {
|
||||||
case u := <-updates:
|
case u := <-updates:
|
||||||
switch u.Op {
|
switch u.Op {
|
||||||
case SET:
|
case SET:
|
||||||
glog.Infof("Containers changed [%s]", kl.hostname)
|
glog.Infof("Containers changed [%s]", kl.hostname)
|
||||||
pods = u.Pods
|
pods = u.Pods
|
||||||
|
pods = filterHostPortConflicts(pods)
|
||||||
|
|
||||||
case UPDATE:
|
case UPDATE:
|
||||||
//TODO: implement updates of containers
|
//TODO: implement updates of containers
|
||||||
@ -578,9 +583,11 @@ func (kl *Kubelet) syncLoop(updates <-chan PodUpdate, handler SyncHandler) {
|
|||||||
default:
|
default:
|
||||||
panic("syncLoop does not support incremental changes")
|
panic("syncLoop does not support incremental changes")
|
||||||
}
|
}
|
||||||
|
case <-time.After(kl.resyncInterval):
|
||||||
|
if pods == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pods = filterHostPortConflicts(pods)
|
|
||||||
|
|
||||||
err := handler.SyncPods(pods)
|
err := handler.SyncPods(pods)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user