2014-10-27 17:04:39 +00:00
/ *
Copyright 2014 Google Inc . All rights reserved .
Licensed under the Apache License , Version 2.0 ( the "License" ) ;
you may not use this file except in compliance with the License .
You may obtain a copy of the License at
http : //www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing , software
distributed under the License is distributed on an "AS IS" BASIS ,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
See the License for the specific language governing permissions and
limitations under the License .
* /
2015-02-07 21:30:53 +00:00
// Package app makes it easy to create a kubelet server for various contexts.
package app
2014-10-27 17:04:39 +00:00
import (
"fmt"
2015-02-02 21:30:31 +00:00
"math/rand"
2014-10-27 17:04:39 +00:00
"net"
"time"
2015-02-02 21:30:31 +00:00
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
2014-10-27 17:04:39 +00:00
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
2015-03-03 06:06:20 +00:00
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/record"
2015-01-07 15:18:56 +00:00
"github.com/GoogleCloudPlatform/kubernetes/pkg/clientauth"
2015-01-27 20:16:47 +00:00
"github.com/GoogleCloudPlatform/kubernetes/pkg/credentialprovider"
2015-02-02 21:30:31 +00:00
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/healthz"
2014-10-27 17:04:39 +00:00
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet"
2015-03-06 07:56:30 +00:00
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/cadvisor"
2014-10-27 17:04:39 +00:00
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/config"
2014-11-27 21:28:56 +00:00
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools"
2015-03-19 23:14:13 +00:00
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/network"
2015-02-02 21:30:31 +00:00
"github.com/GoogleCloudPlatform/kubernetes/pkg/master/ports"
2014-10-27 17:04:39 +00:00
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
2015-03-19 05:18:31 +00:00
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
2014-10-27 17:04:39 +00:00
"github.com/golang/glog"
2015-02-02 21:30:31 +00:00
"github.com/spf13/pflag"
2014-10-27 17:04:39 +00:00
)
2015-02-02 21:30:31 +00:00
const defaultRootDir = "/var/lib/kubelet"
// KubeletServer encapsulates all of the parameters necessary for starting up
// a kubelet. These can either be set via command line or directly.
type KubeletServer struct {
2015-01-08 20:41:38 +00:00
Config string
SyncFrequency time . Duration
FileCheckFrequency time . Duration
HTTPCheckFrequency time . Duration
ManifestURL string
EnableServer bool
Address util . IP
Port uint
HostnameOverride string
PodInfraContainerImage string
DockerEndpoint string
RootDirectory string
AllowPrivileged bool
RegistryPullQPS float64
RegistryBurst int
RunOnce bool
EnableDebuggingHandlers bool
MinimumGCAge time . Duration
2015-03-14 17:13:20 +00:00
MaxPerPodContainerCount int
2015-01-08 20:41:38 +00:00
MaxContainerCount int
AuthPath string
2015-03-10 05:39:00 +00:00
CadvisorPort uint
2015-01-08 20:41:38 +00:00
OOMScoreAdj int
APIServerList util . StringList
ClusterDomain string
MasterServiceNamespace string
ClusterDNS util . IP
ReallyCrashForTesting bool
StreamingConnectionIdleTimeout time . Duration
2015-03-16 04:00:46 +00:00
ImageGCHighThresholdPercent int
ImageGCLowThresholdPercent int
2015-03-19 23:14:13 +00:00
NetworkPluginName string
2015-02-02 21:30:31 +00:00
}
// NewKubeletServer will create a new KubeletServer with default values.
func NewKubeletServer ( ) * KubeletServer {
return & KubeletServer {
2015-03-14 00:59:25 +00:00
SyncFrequency : 10 * time . Second ,
FileCheckFrequency : 20 * time . Second ,
HTTPCheckFrequency : 20 * time . Second ,
EnableServer : true ,
Address : util . IP ( net . ParseIP ( "127.0.0.1" ) ) ,
Port : ports . KubeletPort ,
2015-03-16 04:00:46 +00:00
PodInfraContainerImage : kubelet . PodInfraContainerImage ,
RootDirectory : defaultRootDir ,
RegistryBurst : 10 ,
EnableDebuggingHandlers : true ,
MinimumGCAge : 1 * time . Minute ,
MaxPerPodContainerCount : 5 ,
MaxContainerCount : 100 ,
CadvisorPort : 4194 ,
OOMScoreAdj : - 900 ,
MasterServiceNamespace : api . NamespaceDefault ,
ImageGCHighThresholdPercent : 90 ,
ImageGCLowThresholdPercent : 80 ,
2015-03-19 23:14:13 +00:00
NetworkPluginName : "" ,
2015-02-02 21:30:31 +00:00
}
}
// AddFlags adds flags for a specific KubeletServer to the specified FlagSet
func ( s * KubeletServer ) AddFlags ( fs * pflag . FlagSet ) {
fs . StringVar ( & s . Config , "config" , s . Config , "Path to the config file or directory of files" )
fs . DurationVar ( & s . SyncFrequency , "sync_frequency" , s . SyncFrequency , "Max period between synchronizing running containers and config" )
fs . DurationVar ( & s . FileCheckFrequency , "file_check_frequency" , s . FileCheckFrequency , "Duration between checking config files for new data" )
fs . DurationVar ( & s . HTTPCheckFrequency , "http_check_frequency" , s . HTTPCheckFrequency , "Duration between checking http for new data" )
fs . StringVar ( & s . ManifestURL , "manifest_url" , s . ManifestURL , "URL for accessing the container manifest" )
fs . BoolVar ( & s . EnableServer , "enable_server" , s . EnableServer , "Enable the info server" )
fs . Var ( & s . Address , "address" , "The IP address for the info server to serve on (set to 0.0.0.0 for all interfaces)" )
fs . UintVar ( & s . Port , "port" , s . Port , "The port for the info server to serve on" )
fs . StringVar ( & s . HostnameOverride , "hostname_override" , s . HostnameOverride , "If non-empty, will use this string as identification instead of the actual hostname." )
fs . StringVar ( & s . PodInfraContainerImage , "pod_infra_container_image" , s . PodInfraContainerImage , "The image whose network/ipc namespaces containers in each pod will use." )
fs . StringVar ( & s . DockerEndpoint , "docker_endpoint" , s . DockerEndpoint , "If non-empty, use this for the docker endpoint to communicate with" )
fs . StringVar ( & s . RootDirectory , "root_dir" , s . RootDirectory , "Directory path for managing kubelet files (volume mounts,etc)." )
fs . BoolVar ( & s . AllowPrivileged , "allow_privileged" , s . AllowPrivileged , "If true, allow containers to request privileged mode. [default=false]" )
fs . Float64Var ( & s . RegistryPullQPS , "registry_qps" , s . RegistryPullQPS , "If > 0, limit registry pull QPS to this value. If 0, unlimited. [default=0.0]" )
fs . IntVar ( & s . RegistryBurst , "registry_burst" , s . RegistryBurst , "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" )
2015-03-10 16:15:17 +00:00
fs . BoolVar ( & s . RunOnce , "runonce" , s . RunOnce , "If true, exit after spawning pods from local manifests or remote urls. Exclusive with --api_servers, and --enable-server" )
2015-02-02 21:30:31 +00:00
fs . BoolVar ( & s . EnableDebuggingHandlers , "enable_debugging_handlers" , s . EnableDebuggingHandlers , "Enables server endpoints for log collection and local running of containers and commands" )
fs . DurationVar ( & s . MinimumGCAge , "minimum_container_ttl_duration" , s . MinimumGCAge , "Minimum age for a finished container before it is garbage collected. Examples: '300ms', '10s' or '2h45m'" )
2015-03-14 17:13:20 +00:00
fs . IntVar ( & s . MaxPerPodContainerCount , "maximum_dead_containers_per_container" , s . MaxPerPodContainerCount , "Maximum number of old instances of a container to retain per container. Each container takes up some disk space. Default: 5." )
fs . IntVar ( & s . MaxContainerCount , "maximum_dead_containers" , s . MaxContainerCount , "Maximum number of old instances of a containers to retain globally. Each container takes up some disk space. Default: 100." )
2015-02-02 21:30:31 +00:00
fs . StringVar ( & s . AuthPath , "auth_path" , s . AuthPath , "Path to .kubernetes_auth file, specifying how to authenticate to API server." )
2015-03-10 05:39:00 +00:00
fs . UintVar ( & s . CadvisorPort , "cadvisor_port" , s . CadvisorPort , "The port of the localhost cAdvisor endpoint" )
2015-02-02 21:30:31 +00:00
fs . IntVar ( & s . OOMScoreAdj , "oom_score_adj" , s . OOMScoreAdj , "The oom_score_adj value for kubelet process. Values must be within the range [-1000, 1000]" )
fs . Var ( & s . APIServerList , "api_servers" , "List of Kubernetes API servers for publishing events, and reading pods and services. (ip:port), comma separated." )
fs . StringVar ( & s . ClusterDomain , "cluster_domain" , s . ClusterDomain , "Domain for this cluster. If set, kubelet will configure all containers to search this domain in addition to the host's search domains" )
fs . StringVar ( & s . MasterServiceNamespace , "master_service_namespace" , s . MasterServiceNamespace , "The namespace from which the kubernetes master services should be injected into pods" )
fs . Var ( & s . ClusterDNS , "cluster_dns" , "IP address for a cluster DNS server. If set, kubelet will configure all containers to use this for DNS resolution in addition to the host's DNS servers" )
fs . BoolVar ( & s . ReallyCrashForTesting , "really_crash_for_testing" , s . ReallyCrashForTesting , "If true, crash with panics more often." )
2015-01-08 20:41:38 +00:00
fs . DurationVar ( & s . StreamingConnectionIdleTimeout , "streaming_connection_idle_timeout" , 0 , "Maximum time a streaming connection can be idle before the connection is automatically closed. Example: '5m'" )
2015-03-16 04:00:46 +00:00
fs . IntVar ( & s . ImageGCHighThresholdPercent , "image_gc_high_threshold" , s . ImageGCHighThresholdPercent , "The percent of disk usage after which image garbage collection is always run. Default: 90%%" )
fs . IntVar ( & s . ImageGCLowThresholdPercent , "image_gc_low_threshold" , s . ImageGCLowThresholdPercent , "The percent of disk usage before which image garbage collection is never run. Lowest disk usage to garbage collect to. Default: 80%%" )
2015-03-19 23:14:13 +00:00
fs . StringVar ( & s . NetworkPluginName , "network_plugin" , s . NetworkPluginName , "<Warning: Alpha feature> The name of the network plugin to be invoked for various events in kubelet/pod lifecycle" )
2015-02-02 21:30:31 +00:00
}
// Run runs the specified KubeletServer. This should never exit.
func ( s * KubeletServer ) Run ( _ [ ] string ) error {
util . ReallyCrash = s . ReallyCrashForTesting
rand . Seed ( time . Now ( ) . UTC ( ) . UnixNano ( ) )
2015-02-20 01:16:31 +00:00
if err := util . ApplyOomScoreAdj ( 0 , s . OOMScoreAdj ) ; err != nil {
2015-02-02 21:30:31 +00:00
glog . Info ( err )
}
client , err := s . createAPIServerClient ( )
if err != nil && len ( s . APIServerList ) > 0 {
glog . Warningf ( "No API client: %v" , err )
}
2015-02-18 01:26:41 +00:00
glog . Infof ( "Using root directory: %v" , s . RootDirectory )
2015-02-02 21:30:31 +00:00
credentialprovider . SetPreferredDockercfgPath ( s . RootDirectory )
2015-03-10 05:39:00 +00:00
cadvisorInterface , err := cadvisor . New ( s . CadvisorPort )
if err != nil {
return err
}
2015-03-16 04:00:46 +00:00
imageGCPolicy := kubelet . ImageGCPolicy {
HighThresholdPercent : s . ImageGCHighThresholdPercent ,
LowThresholdPercent : s . ImageGCLowThresholdPercent ,
}
2015-02-02 21:30:31 +00:00
kcfg := KubeletConfig {
2015-01-08 20:41:38 +00:00
Address : s . Address ,
AllowPrivileged : s . AllowPrivileged ,
HostnameOverride : s . HostnameOverride ,
RootDirectory : s . RootDirectory ,
ConfigFile : s . Config ,
ManifestURL : s . ManifestURL ,
FileCheckFrequency : s . FileCheckFrequency ,
HTTPCheckFrequency : s . HTTPCheckFrequency ,
PodInfraContainerImage : s . PodInfraContainerImage ,
SyncFrequency : s . SyncFrequency ,
RegistryPullQPS : s . RegistryPullQPS ,
RegistryBurst : s . RegistryBurst ,
MinimumGCAge : s . MinimumGCAge ,
2015-03-14 17:13:20 +00:00
MaxPerPodContainerCount : s . MaxPerPodContainerCount ,
2015-01-08 20:41:38 +00:00
MaxContainerCount : s . MaxContainerCount ,
ClusterDomain : s . ClusterDomain ,
ClusterDNS : s . ClusterDNS ,
Runonce : s . RunOnce ,
Port : s . Port ,
2015-03-10 05:39:00 +00:00
CadvisorInterface : cadvisorInterface ,
2015-01-08 20:41:38 +00:00
EnableServer : s . EnableServer ,
EnableDebuggingHandlers : s . EnableDebuggingHandlers ,
DockerClient : dockertools . ConnectToDockerOrDie ( s . DockerEndpoint ) ,
KubeClient : client ,
MasterServiceNamespace : s . MasterServiceNamespace ,
VolumePlugins : ProbeVolumePlugins ( ) ,
2015-03-19 23:14:13 +00:00
NetworkPlugins : ProbeNetworkPlugins ( ) ,
NetworkPluginName : s . NetworkPluginName ,
2015-01-08 20:41:38 +00:00
StreamingConnectionIdleTimeout : s . StreamingConnectionIdleTimeout ,
2015-03-16 04:00:46 +00:00
ImageGCPolicy : imageGCPolicy ,
2015-02-02 21:30:31 +00:00
}
RunKubelet ( & kcfg )
// runs forever
select { }
}
func ( s * KubeletServer ) setupRunOnce ( ) {
if s . RunOnce {
2015-03-11 23:40:20 +00:00
// Don't use apiserver source, on the presumption that this flag is used
// for bootstrapping some system pods.
2015-02-02 21:30:31 +00:00
if len ( s . APIServerList ) > 0 {
glog . Fatalf ( "invalid option: --runonce and --api_servers are mutually exclusive" )
}
if s . EnableServer {
glog . Infof ( "--runonce is set, disabling server" )
s . EnableServer = false
}
}
}
2015-01-07 15:18:56 +00:00
// TODO: replace this with clientcmd
2015-02-02 21:30:31 +00:00
func ( s * KubeletServer ) createAPIServerClient ( ) ( * client . Client , error ) {
authInfo , err := clientauth . LoadFromFile ( s . AuthPath )
2015-01-07 15:18:56 +00:00
if err != nil {
2015-01-31 02:07:07 +00:00
glog . Warningf ( "Could not load kubernetes auth path: %v. Continuing with defaults." , err )
}
if authInfo == nil {
// authInfo didn't load correctly - continue with defaults.
authInfo = & clientauth . Info { }
2015-01-07 15:18:56 +00:00
}
clientConfig , err := authInfo . MergeWithConfig ( client . Config { } )
if err != nil {
return nil , err
}
2015-02-02 21:30:31 +00:00
if len ( s . APIServerList ) < 1 {
return nil , fmt . Errorf ( "no api servers specified" )
2015-01-07 15:18:56 +00:00
}
// TODO: adapt Kube client to support LB over several servers
2015-02-02 21:30:31 +00:00
if len ( s . APIServerList ) > 1 {
2015-01-18 07:32:34 +00:00
glog . Infof ( "Multiple api servers specified. Picking first one" )
2015-01-07 15:18:56 +00:00
}
2015-02-02 21:30:31 +00:00
clientConfig . Host = s . APIServerList [ 0 ]
2015-01-07 15:18:56 +00:00
c , err := client . New ( & clientConfig )
if err != nil {
return nil , err
}
return c , nil
}
2015-03-11 23:40:20 +00:00
// SimpleRunKubelet is a simple way to start a Kubelet talking to dockerEndpoint, using an API Client.
2014-11-27 21:28:56 +00:00
// Under the hood it calls RunKubelet (below)
2015-03-23 03:02:18 +00:00
func SimpleKubelet ( client * client . Client ,
2015-01-08 15:25:14 +00:00
dockerClient dockertools . DockerInterface ,
hostname , rootDir , manifestURL , address string ,
port uint ,
2014-11-23 15:47:25 +00:00
masterServiceNamespace string ,
2015-03-19 05:18:31 +00:00
volumePlugins [ ] volume . VolumePlugin ,
2015-03-10 05:39:00 +00:00
tlsOptions * kubelet . TLSOptions ,
2015-03-09 22:46:47 +00:00
cadvisorInterface cadvisor . Interface ,
2015-03-23 03:02:18 +00:00
configFilePath string ) * KubeletConfig {
2015-03-16 04:00:46 +00:00
imageGCPolicy := kubelet . ImageGCPolicy {
HighThresholdPercent : 90 ,
LowThresholdPercent : 80 ,
}
2014-11-27 21:28:56 +00:00
kcfg := KubeletConfig {
2015-01-21 00:59:26 +00:00
KubeClient : client ,
DockerClient : dockerClient ,
HostnameOverride : hostname ,
RootDirectory : rootDir ,
ManifestURL : manifestURL ,
PodInfraContainerImage : kubelet . PodInfraContainerImage ,
2015-03-20 16:37:08 +00:00
Port : port ,
Address : util . IP ( net . ParseIP ( address ) ) ,
EnableServer : true ,
EnableDebuggingHandlers : true ,
HTTPCheckFrequency : 1 * time . Second ,
FileCheckFrequency : 1 * time . Second ,
SyncFrequency : 3 * time . Second ,
MinimumGCAge : 10 * time . Second ,
MaxPerPodContainerCount : 5 ,
MaxContainerCount : 100 ,
MasterServiceNamespace : masterServiceNamespace ,
VolumePlugins : volumePlugins ,
TLSOptions : tlsOptions ,
CadvisorInterface : cadvisorInterface ,
ConfigFile : configFilePath ,
ImageGCPolicy : imageGCPolicy ,
2014-11-27 21:28:56 +00:00
}
2015-03-23 03:02:18 +00:00
return & kcfg
2014-11-27 21:28:56 +00:00
}
// RunKubelet is responsible for setting up and running a kubelet. It is used in three different applications:
// 1 Integration tests
// 2 Kubelet binary
// 3 Standalone 'kubernetes' binary
// Eventually, #2 will be replaced with instances of #3
func RunKubelet ( kcfg * KubeletConfig ) {
2015-01-14 17:36:09 +00:00
kcfg . Hostname = util . GetHostname ( kcfg . HostnameOverride )
2015-03-03 06:06:20 +00:00
kcfg . Recorder = record . FromSource ( api . EventSource { Component : "kubelet" , Host : kcfg . Hostname } )
2015-01-07 15:18:56 +00:00
if kcfg . KubeClient != nil {
2015-01-14 17:36:09 +00:00
kubelet . SetupEventSending ( kcfg . KubeClient , kcfg . Hostname )
2015-01-07 15:18:56 +00:00
} else {
glog . Infof ( "No api server defined - no events will be sent." )
}
2014-11-27 21:28:56 +00:00
kubelet . SetupLogging ( )
kubelet . SetupCapabilities ( kcfg . AllowPrivileged )
2015-01-27 20:16:47 +00:00
credentialprovider . SetPreferredDockercfgPath ( kcfg . RootDirectory )
2015-02-02 21:30:31 +00:00
podCfg := makePodSourceConfig ( kcfg )
k , err := createAndInitKubelet ( kcfg , podCfg )
2015-01-07 02:31:40 +00:00
if err != nil {
glog . Errorf ( "Failed to create kubelet: %s" , err )
return
}
2014-11-27 21:28:56 +00:00
// process pods and exit.
if kcfg . Runonce {
2015-02-02 21:30:31 +00:00
if _ , err := k . RunOnce ( podCfg . Updates ( ) ) ; err != nil {
2014-11-27 21:28:56 +00:00
glog . Errorf ( "--runonce failed: %v" , err )
}
} else {
2015-02-02 21:30:31 +00:00
startKubelet ( k , podCfg , kcfg )
2014-11-27 21:28:56 +00:00
}
}
2015-02-02 21:30:31 +00:00
func startKubelet ( k * kubelet . Kubelet , podCfg * config . PodConfig , kc * KubeletConfig ) {
2014-11-27 21:28:56 +00:00
// start the kubelet
2015-02-02 21:30:31 +00:00
go util . Forever ( func ( ) { k . Run ( podCfg . Updates ( ) ) } , 0 )
2014-11-27 21:28:56 +00:00
// start the kubelet server
if kc . EnableServer {
go util . Forever ( func ( ) {
2015-03-05 21:30:52 +00:00
kubelet . ListenAndServeKubeletServer ( k , net . IP ( kc . Address ) , kc . Port , kc . TLSOptions , kc . EnableDebuggingHandlers )
2014-11-27 21:28:56 +00:00
} , 0 )
}
}
func makePodSourceConfig ( kc * KubeletConfig ) * config . PodConfig {
// source of all configuration
2015-03-03 06:06:20 +00:00
cfg := config . NewPodConfig ( config . PodConfigNotificationSnapshotAndUpdates , kc . Recorder )
2014-11-27 21:28:56 +00:00
// define file config source
if kc . ConfigFile != "" {
2014-12-17 05:11:27 +00:00
glog . Infof ( "Adding manifest file: %v" , kc . ConfigFile )
2015-03-23 03:06:12 +00:00
config . NewSourceFile ( kc . ConfigFile , kc . Hostname , kc . FileCheckFrequency , cfg . Channel ( kubelet . FileSource ) )
2014-11-27 21:28:56 +00:00
}
// define url config source
if kc . ManifestURL != "" {
2014-12-17 05:11:27 +00:00
glog . Infof ( "Adding manifest url: %v" , kc . ManifestURL )
2015-03-23 03:06:12 +00:00
config . NewSourceURL ( kc . ManifestURL , kc . Hostname , kc . HTTPCheckFrequency , cfg . Channel ( kubelet . HTTPSource ) )
2014-11-27 21:28:56 +00:00
}
2015-01-17 00:38:09 +00:00
if kc . KubeClient != nil {
2014-11-21 21:14:30 +00:00
glog . Infof ( "Watching apiserver" )
config . NewSourceApiserver ( kc . KubeClient , kc . Hostname , cfg . Channel ( kubelet . ApiserverSource ) )
}
2014-11-27 21:28:56 +00:00
return cfg
}
2015-02-02 21:30:31 +00:00
// KubeletConfig is all of the parameters necessary for running a kubelet.
// TODO: This should probably be merged with KubeletServer. The extra object is a consequence of refactoring.
2014-11-27 21:28:56 +00:00
type KubeletConfig struct {
2015-01-08 20:41:38 +00:00
KubeClient * client . Client
DockerClient dockertools . DockerInterface
2015-03-10 05:39:00 +00:00
CadvisorInterface cadvisor . Interface
2015-01-08 20:41:38 +00:00
Address util . IP
AllowPrivileged bool
HostnameOverride string
RootDirectory string
ConfigFile string
ManifestURL string
FileCheckFrequency time . Duration
HTTPCheckFrequency time . Duration
Hostname string
PodInfraContainerImage string
SyncFrequency time . Duration
RegistryPullQPS float64
RegistryBurst int
MinimumGCAge time . Duration
2015-03-14 17:13:20 +00:00
MaxPerPodContainerCount int
2015-01-08 20:41:38 +00:00
MaxContainerCount int
ClusterDomain string
ClusterDNS util . IP
EnableServer bool
EnableDebuggingHandlers bool
Port uint
Runonce bool
MasterServiceNamespace string
2015-03-19 05:18:31 +00:00
VolumePlugins [ ] volume . VolumePlugin
2015-03-19 23:14:13 +00:00
NetworkPlugins [ ] network . NetworkPlugin
NetworkPluginName string
2015-01-08 20:41:38 +00:00
StreamingConnectionIdleTimeout time . Duration
2015-03-03 06:06:20 +00:00
Recorder record . EventRecorder
2015-03-05 21:30:52 +00:00
TLSOptions * kubelet . TLSOptions
2015-03-16 04:00:46 +00:00
ImageGCPolicy kubelet . ImageGCPolicy
2014-11-27 21:28:56 +00:00
}
2015-01-07 02:31:40 +00:00
func createAndInitKubelet ( kc * KubeletConfig , pc * config . PodConfig ) ( * kubelet . Kubelet , error ) {
2014-11-27 21:28:56 +00:00
// TODO: block until all sources have delivered at least one update to the channel, or break the sync loop
// up into "per source" synchronizations
2015-02-27 18:44:44 +00:00
// TODO: KubeletConfig.KubeClient should be a client interface, but client interface misses certain methods
// used by kubelet. Since NewMainKubelet expects a client interface, we need to make sure we are not passing
// a nil pointer to it when what we really want is a nil interface.
var kubeClient client . Interface
if kc . KubeClient == nil {
kubeClient = nil
} else {
kubeClient = kc . KubeClient
}
2015-03-06 07:56:30 +00:00
2015-03-14 17:13:20 +00:00
gcPolicy := kubelet . ContainerGCPolicy {
MinAge : kc . MinimumGCAge ,
MaxPerPodContainer : kc . MaxPerPodContainerCount ,
MaxContainers : kc . MaxContainerCount ,
}
2015-01-07 02:31:40 +00:00
k , err := kubelet . NewMainKubelet (
2014-11-27 21:28:56 +00:00
kc . Hostname ,
kc . DockerClient ,
2015-02-27 18:44:44 +00:00
kubeClient ,
2014-11-27 21:28:56 +00:00
kc . RootDirectory ,
2015-01-21 00:59:26 +00:00
kc . PodInfraContainerImage ,
2014-11-27 21:28:56 +00:00
kc . SyncFrequency ,
float32 ( kc . RegistryPullQPS ) ,
kc . RegistryBurst ,
2015-03-14 17:13:20 +00:00
gcPolicy ,
2015-03-05 18:49:36 +00:00
pc . SeenAllSources ,
2014-11-12 05:21:40 +00:00
kc . ClusterDomain ,
2015-01-08 15:25:14 +00:00
net . IP ( kc . ClusterDNS ) ,
2014-11-23 15:47:25 +00:00
kc . MasterServiceNamespace ,
2015-01-08 20:41:38 +00:00
kc . VolumePlugins ,
2015-03-19 23:14:13 +00:00
kc . NetworkPlugins ,
kc . NetworkPluginName ,
2015-03-03 06:06:20 +00:00
kc . StreamingConnectionIdleTimeout ,
2015-03-06 07:56:30 +00:00
kc . Recorder ,
2015-03-10 05:39:00 +00:00
kc . CadvisorInterface ,
2015-03-16 04:00:46 +00:00
kc . ImageGCPolicy )
2014-11-27 21:28:56 +00:00
2015-01-07 02:31:40 +00:00
if err != nil {
return nil , err
}
2014-11-27 21:28:56 +00:00
k . BirthCry ( )
2015-03-16 04:00:46 +00:00
k . StartGarbageCollection ( )
2014-10-27 17:04:39 +00:00
2015-01-07 02:31:40 +00:00
return k , nil
2014-10-27 17:04:39 +00:00
}