Skip to content

Commit

Permalink
NewMainKubelet validates Kubelet config parameters
Browse files Browse the repository at this point in the history
Fixes issue kubernetes#3202.
* Validates SyncFrequency and minimum GC age and propagates error to RunKubelet
* Defaults for Kubelet config and minor cleanup
* cmd Kubelet MinimumGCAge to 1m instead of 0
  • Loading branch information
commonlisp committed Jan 8, 2015
1 parent ded3ef2 commit 06475fc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 21 deletions.
2 changes: 1 addition & 1 deletion cmd/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var (
registryBurst = flag.Int("registry_burst", 10, "Maximum size of a bursty pulls, temporarily allows pulls to burst to this number, while still not exceeding registry_qps. Only used if --registry_qps > 0")
runonce = flag.Bool("runonce", false, "If true, exit after spawning pods from local manifests or remote urls. Exclusive with --etcd_servers and --enable-server")
enableDebuggingHandlers = flag.Bool("enable_debugging_handlers", true, "Enables server endpoints for log collection and local running of containers and commands")
minimumGCAge = flag.Duration("minimum_container_ttl_duration", 0, "Minimum age for a finished container before it is garbage collected. Examples: '300ms', '10s' or '2h45m'")
minimumGCAge = flag.Duration("minimum_container_ttl_duration", 1*time.Minute, "Minimum age for a finished container before it is garbage collected. Examples: '300ms', '10s' or '2h45m'")
maxContainerCount = flag.Int("maximum_dead_containers_per_container", 5, "Maximum number of old instances of a container to retain per container. Each container takes up some disk space. Default: 5.")
authPath = flag.String("auth_path", "", "Path to .kubernetes_auth file, specifying how to authenticate to API server.")
cAdvisorPort = flag.Uint("cadvisor_port", 4194, "The port of the localhost cAdvisor endpoint")
Expand Down
38 changes: 22 additions & 16 deletions pkg/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,29 +61,35 @@ type volumeMap map[string]volume.Interface

// New creates a new Kubelet for use in main
func NewMainKubelet(
hn string,
dc dockertools.DockerInterface,
ec tools.EtcdClient,
rd string,
ni string,
ri time.Duration,
hostname string,
dockerClient dockertools.DockerInterface,
etcdClient tools.EtcdClient,
rootDirectory string,
networkContainerImage string,
resyncInterval time.Duration,
pullQPS float32,
pullBurst int,
minimumGCAge time.Duration,
maxContainerCount int,
sourcesReady SourcesReadyFn,
clusterDomain string,
clusterDNS net.IP) *Kubelet {
clusterDNS net.IP) (*Kubelet, error) {
if resyncInterval <= 0 {
return nil, fmt.Errorf("invalid sync frequency %d", resyncInterval)
}
if minimumGCAge <= 0 {
return nil, fmt.Errorf("invalid minimum GC age %d", minimumGCAge)
}
return &Kubelet{
hostname: hn,
dockerClient: dc,
etcdClient: ec,
rootDirectory: rd,
resyncInterval: ri,
networkContainerImage: ni,
hostname: hostname,
dockerClient: dockerClient,
etcdClient: etcdClient,
rootDirectory: rootDirectory,
resyncInterval: resyncInterval,
networkContainerImage: networkContainerImage,
podWorkers: newPodWorkers(),
dockerIDToRef: map[dockertools.DockerID]*api.ObjectReference{},
runner: dockertools.NewDockerContainerCommandRunner(dc),
runner: dockertools.NewDockerContainerCommandRunner(dockerClient),
httpClient: &http.Client{},
pullQPS: pullQPS,
pullBurst: pullBurst,
Expand All @@ -92,7 +98,7 @@ func NewMainKubelet(
sourcesReady: sourcesReady,
clusterDomain: clusterDomain,
clusterDNS: clusterDNS,
}
}, nil
}

type httpGetter interface {
Expand Down Expand Up @@ -202,7 +208,7 @@ func (kl *Kubelet) purgeOldest(ids []string) error {
if err != nil {
return err
}
if !data.State.Running && (kl.minimumGCAge == 0 || time.Now().Sub(data.State.FinishedAt) > kl.minimumGCAge) {
if !data.State.Running && (time.Now().Sub(data.State.FinishedAt) > kl.minimumGCAge) {
dockerData = append(dockerData, data)
}
}
Expand Down
18 changes: 14 additions & 4 deletions pkg/standalone/standalone.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ func SimpleRunKubelet(etcdClient tools.EtcdClient, dockerClient dockertools.Dock
EnableServer: true,
EnableDebuggingHandlers: true,
SyncFrequency: 3 * time.Second,
MinimumGCAge: 10 * time.Second,
MaxContainerCount: 5,
}
RunKubelet(&kcfg)
}
Expand All @@ -162,7 +164,11 @@ func RunKubelet(kcfg *KubeletConfig) {
}

cfg := makePodSourceConfig(kcfg)
k := createAndInitKubelet(kcfg, cfg)
k, err := createAndInitKubelet(kcfg, cfg)
if err != nil {
glog.Errorf("Failed to create kubelet: %s", err)
return
}
// process pods and exit.
if kcfg.Runonce {
if _, err := k.RunOnce(cfg.Updates()); err != nil {
Expand Down Expand Up @@ -237,11 +243,11 @@ type KubeletConfig struct {
Runonce bool
}

func createAndInitKubelet(kc *KubeletConfig, pc *config.PodConfig) *kubelet.Kubelet {
func createAndInitKubelet(kc *KubeletConfig, pc *config.PodConfig) (*kubelet.Kubelet, error) {
// TODO: block until all sources have delivered at least one update to the channel, or break the sync loop
// up into "per source" synchronizations

k := kubelet.NewMainKubelet(
k, err := kubelet.NewMainKubelet(
kc.Hostname,
kc.DockerClient,
kc.EtcdClient,
Expand All @@ -256,11 +262,15 @@ func createAndInitKubelet(kc *KubeletConfig, pc *config.PodConfig) *kubelet.Kube
kc.ClusterDomain,
net.IP(kc.ClusterDNS))

if err != nil {
return nil, err
}

k.BirthCry()

go k.GarbageCollectLoop()
go kubelet.MonitorCAdvisor(k, kc.CAdvisorPort)
kubelet.InitHealthChecking(k)

return k
return k, nil
}

0 comments on commit 06475fc

Please sign in to comment.