2015-01-30 23:31:36 +00:00
/ *
2015-05-01 16:19:44 +00:00
Copyright 2014 The Kubernetes Authors All rights reserved .
2015-01-30 23:31:36 +00:00
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-08 04:07:00 +00:00
// Package app implements a server that runs a set of active
2015-01-30 23:31:36 +00:00
// components. This includes replication controllers, service endpoints and
// nodes.
2015-06-11 13:13:19 +00:00
//
// CAUTION: If you update code in this file, you may need to also update code
2015-06-11 19:34:04 +00:00
// in contrib/mesos/pkg/controllermanager/controllermanager.go
2015-02-08 04:07:00 +00:00
package app
2015-01-30 23:31:36 +00:00
import (
2015-06-23 22:43:59 +00:00
"fmt"
"io/ioutil"
2015-10-06 09:12:00 +00:00
"math/rand"
2015-01-30 23:31:36 +00:00
"net"
"net/http"
2015-03-13 15:44:11 +00:00
"net/http/pprof"
2015-01-30 23:31:36 +00:00
"strconv"
"time"
2015-10-13 00:31:25 +00:00
"k8s.io/kubernetes/pkg/api/unversioned"
2015-08-13 19:01:50 +00:00
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
2015-08-05 22:03:47 +00:00
"k8s.io/kubernetes/pkg/cloudprovider"
2015-11-11 21:19:39 +00:00
"k8s.io/kubernetes/pkg/controller"
2015-08-27 17:18:01 +00:00
"k8s.io/kubernetes/pkg/controller/daemon"
2015-09-03 00:02:22 +00:00
"k8s.io/kubernetes/pkg/controller/deployment"
2015-10-10 03:58:57 +00:00
endpointcontroller "k8s.io/kubernetes/pkg/controller/endpoint"
2015-09-21 22:51:27 +00:00
"k8s.io/kubernetes/pkg/controller/gc"
2015-08-27 12:19:35 +00:00
"k8s.io/kubernetes/pkg/controller/job"
2015-10-10 03:58:57 +00:00
namespacecontroller "k8s.io/kubernetes/pkg/controller/namespace"
nodecontroller "k8s.io/kubernetes/pkg/controller/node"
persistentvolumecontroller "k8s.io/kubernetes/pkg/controller/persistentvolume"
2015-09-10 13:10:07 +00:00
"k8s.io/kubernetes/pkg/controller/podautoscaler"
"k8s.io/kubernetes/pkg/controller/podautoscaler/metrics"
2015-10-10 03:58:57 +00:00
replicationcontroller "k8s.io/kubernetes/pkg/controller/replication"
resourcequotacontroller "k8s.io/kubernetes/pkg/controller/resourcequota"
routecontroller "k8s.io/kubernetes/pkg/controller/route"
servicecontroller "k8s.io/kubernetes/pkg/controller/service"
2015-12-24 21:54:40 +00:00
serviceaccountcontroller "k8s.io/kubernetes/pkg/controller/serviceaccount"
2015-08-05 22:03:47 +00:00
"k8s.io/kubernetes/pkg/healthz"
"k8s.io/kubernetes/pkg/master/ports"
2015-12-24 21:54:40 +00:00
"k8s.io/kubernetes/pkg/serviceaccount"
2015-08-05 22:03:47 +00:00
"k8s.io/kubernetes/pkg/util"
2015-10-28 06:46:44 +00:00
"k8s.io/kubernetes/pkg/util/wait"
2015-04-18 13:31:24 +00:00
2015-01-30 23:31:36 +00:00
"github.com/golang/glog"
2015-04-22 14:46:03 +00:00
"github.com/prometheus/client_golang/prometheus"
2015-10-12 14:33:39 +00:00
"github.com/spf13/cobra"
2015-01-30 23:31:36 +00:00
"github.com/spf13/pflag"
)
2015-02-25 00:15:59 +00:00
// CMServer is the main context object for the controller manager.
2015-01-30 23:31:36 +00:00
type CMServer struct {
2015-08-25 14:54:54 +00:00
Port int
Address net . IP
CloudProvider string
CloudConfigFile string
ConcurrentEndpointSyncs int
ConcurrentRCSyncs int
2015-09-08 18:50:39 +00:00
ConcurrentDSCSyncs int
2015-08-27 12:19:35 +00:00
ConcurrentJobSyncs int
2015-11-11 21:19:39 +00:00
ConcurrentResourceQuotaSyncs int
2015-09-21 07:06:45 +00:00
ConcurrentDeploymentSyncs int
2015-08-25 14:54:54 +00:00
ServiceSyncPeriod time . Duration
NodeSyncPeriod time . Duration
ResourceQuotaSyncPeriod time . Duration
NamespaceSyncPeriod time . Duration
PVClaimBinderSyncPeriod time . Duration
2015-08-31 13:44:37 +00:00
VolumeConfigFlags VolumeConfigFlags
2015-09-21 22:51:27 +00:00
TerminatedPodGCThreshold int
2015-08-25 14:54:54 +00:00
HorizontalPodAutoscalerSyncPeriod time . Duration
2015-09-03 00:02:22 +00:00
DeploymentControllerSyncPeriod time . Duration
2015-10-06 09:12:00 +00:00
MinResyncPeriod time . Duration
2015-08-25 14:54:54 +00:00
RegisterRetryCount int
NodeMonitorGracePeriod time . Duration
NodeStartupGracePeriod time . Duration
NodeMonitorPeriod time . Duration
NodeStatusUpdateRetry int
PodEvictionTimeout time . Duration
DeletingPodsQps float32
DeletingPodsBurst int
ServiceAccountKeyFile string
RootCAFile string
2015-10-12 21:23:50 +00:00
ClusterName string
ClusterCIDR net . IPNet
AllocateNodeCIDRs bool
EnableProfiling bool
2015-04-17 07:18:07 +00:00
2015-10-12 15:56:15 +00:00
Master string
Kubeconfig string
2015-10-20 12:33:48 +00:00
KubeAPIQPS float32
KubeAPIBurst int
2015-01-30 23:31:36 +00:00
}
2015-02-07 19:53:42 +00:00
// NewCMServer creates a new CMServer with a default config.
2015-01-30 23:31:36 +00:00
func NewCMServer ( ) * CMServer {
s := CMServer {
2015-08-25 14:54:54 +00:00
Port : ports . ControllerManagerPort ,
2015-12-08 11:01:14 +00:00
Address : net . ParseIP ( "0.0.0.0" ) ,
2015-08-25 14:54:54 +00:00
ConcurrentEndpointSyncs : 5 ,
ConcurrentRCSyncs : 5 ,
2015-09-08 18:50:39 +00:00
ConcurrentDSCSyncs : 2 ,
2015-08-27 12:19:35 +00:00
ConcurrentJobSyncs : 5 ,
2015-11-11 21:19:39 +00:00
ConcurrentResourceQuotaSyncs : 5 ,
2015-09-21 07:06:45 +00:00
ConcurrentDeploymentSyncs : 5 ,
2015-08-25 14:54:54 +00:00
ServiceSyncPeriod : 5 * time . Minute ,
NodeSyncPeriod : 10 * time . Second ,
2015-11-11 21:19:39 +00:00
ResourceQuotaSyncPeriod : 5 * time . Minute ,
2015-08-25 14:54:54 +00:00
NamespaceSyncPeriod : 5 * time . Minute ,
2015-11-03 13:25:20 +00:00
PVClaimBinderSyncPeriod : 10 * time . Minute ,
2015-09-24 09:09:40 +00:00
HorizontalPodAutoscalerSyncPeriod : 30 * time . Second ,
2015-09-29 23:55:06 +00:00
DeploymentControllerSyncPeriod : 30 * time . Second ,
2015-10-06 09:12:00 +00:00
MinResyncPeriod : 12 * time . Hour ,
2015-08-25 14:54:54 +00:00
RegisterRetryCount : 10 ,
PodEvictionTimeout : 5 * time . Minute ,
2015-10-20 19:04:09 +00:00
NodeMonitorGracePeriod : 40 * time . Second ,
NodeStartupGracePeriod : 60 * time . Second ,
NodeMonitorPeriod : 5 * time . Second ,
2015-08-25 14:54:54 +00:00
ClusterName : "kubernetes" ,
2015-10-06 21:51:58 +00:00
TerminatedPodGCThreshold : 12500 ,
2015-08-31 13:44:37 +00:00
VolumeConfigFlags : VolumeConfigFlags {
// default values here
2015-09-03 03:14:26 +00:00
PersistentVolumeRecyclerMinimumTimeoutNFS : 300 ,
PersistentVolumeRecyclerIncrementTimeoutNFS : 30 ,
PersistentVolumeRecyclerMinimumTimeoutHostPath : 60 ,
PersistentVolumeRecyclerIncrementTimeoutHostPath : 30 ,
2015-10-12 18:27:49 +00:00
EnableHostPathProvisioning : false ,
2015-08-31 13:44:37 +00:00
} ,
2015-10-20 12:33:48 +00:00
KubeAPIQPS : 20.0 ,
KubeAPIBurst : 30 ,
2015-01-30 23:31:36 +00:00
}
return & s
}
2015-10-12 14:33:39 +00:00
// NewControllerManagerCommand creates a *cobra.Command object with default parameters
func NewControllerManagerCommand ( ) * cobra . Command {
s := NewCMServer ( )
s . AddFlags ( pflag . CommandLine )
cmd := & cobra . Command {
Use : "kube-controller-manager" ,
Long : ` The Kubernetes controller manager is a daemon that embeds
the core control loops shipped with Kubernetes . In applications of robotics and
automation , a control loop is a non - terminating loop that regulates the state of
the system . In Kubernetes , a controller is a control loop that watches the shared
state of the cluster through the apiserver and makes changes attempting to move the
current state towards the desired state . Examples of controllers that ship with
Kubernetes today are the replication controller , endpoints controller , namespace
controller , and serviceaccounts controller . ` ,
Run : func ( cmd * cobra . Command , args [ ] string ) {
} ,
}
return cmd
}
2015-08-31 13:44:37 +00:00
// VolumeConfigFlags is used to bind CLI flags to variables. This top-level struct contains *all* enumerated
// CLI flags meant to configure all volume plugins. From this config, the binary will create many instances
// of volume.VolumeConfig which are then passed to the appropriate plugin. The ControllerManager binary is the only
// part of the code which knows what plugins are supported and which CLI flags correspond to each plugin.
type VolumeConfigFlags struct {
2015-09-03 03:14:26 +00:00
PersistentVolumeRecyclerMinimumTimeoutNFS int
PersistentVolumeRecyclerPodTemplateFilePathNFS string
PersistentVolumeRecyclerIncrementTimeoutNFS int
PersistentVolumeRecyclerPodTemplateFilePathHostPath string
PersistentVolumeRecyclerMinimumTimeoutHostPath int
PersistentVolumeRecyclerIncrementTimeoutHostPath int
2015-10-12 18:27:49 +00:00
EnableHostPathProvisioning bool
2015-08-31 13:44:37 +00:00
}
2015-01-30 23:31:36 +00:00
// AddFlags adds flags for a specific CMServer to the specified FlagSet
func ( s * CMServer ) AddFlags ( fs * pflag . FlagSet ) {
fs . IntVar ( & s . Port , "port" , s . Port , "The port that the controller-manager's http service runs on" )
2015-08-05 19:42:13 +00:00
fs . IPVar ( & s . Address , "address" , s . Address , "The IP address to serve on (set to 0.0.0.0 for all interfaces)" )
2015-04-24 06:10:33 +00:00
fs . StringVar ( & s . CloudProvider , "cloud-provider" , s . CloudProvider , "The provider for cloud services. Empty string for no provider." )
fs . StringVar ( & s . CloudConfigFile , "cloud-config" , s . CloudConfigFile , "The path to the cloud provider configuration file. Empty string for no configuration file." )
fs . IntVar ( & s . ConcurrentEndpointSyncs , "concurrent-endpoint-syncs" , s . ConcurrentEndpointSyncs , "The number of endpoint syncing operations that will be done concurrently. Larger number = faster endpoint updating, but more CPU (and network) load" )
2015-04-21 20:40:35 +00:00
fs . IntVar ( & s . ConcurrentRCSyncs , "concurrent_rc_syncs" , s . ConcurrentRCSyncs , "The number of replication controllers that are allowed to sync concurrently. Larger number = more reponsive replica management, but more CPU (and network) load" )
2015-11-11 21:19:39 +00:00
fs . IntVar ( & s . ConcurrentResourceQuotaSyncs , "concurrent-resource-quota-syncs" , s . ConcurrentResourceQuotaSyncs , "The number of resource quotas that are allowed to sync concurrently. Larger number = more responsive quota management, but more CPU (and network) load" )
2015-09-21 07:06:45 +00:00
fs . IntVar ( & s . ConcurrentDeploymentSyncs , "concurrent-deployment-syncs" , s . ConcurrentDeploymentSyncs , "The number of deployment objects that are allowed to sync concurrently. Larger number = more reponsive deployments, but more CPU (and network) load" )
2015-07-27 18:03:13 +00:00
fs . DurationVar ( & s . ServiceSyncPeriod , "service-sync-period" , s . ServiceSyncPeriod , "The period for syncing services with their external load balancers" )
2015-04-24 06:10:33 +00:00
fs . DurationVar ( & s . NodeSyncPeriod , "node-sync-period" , s . NodeSyncPeriod , "" +
2015-01-30 23:31:36 +00:00
"The period for syncing nodes from cloudprovider. Longer periods will result in " +
"fewer calls to cloud provider, but may delay addition of new nodes to cluster." )
2015-04-24 06:10:33 +00:00
fs . DurationVar ( & s . ResourceQuotaSyncPeriod , "resource-quota-sync-period" , s . ResourceQuotaSyncPeriod , "The period for syncing quota usage status in the system" )
fs . DurationVar ( & s . NamespaceSyncPeriod , "namespace-sync-period" , s . NamespaceSyncPeriod , "The period for syncing namespace life-cycle updates" )
fs . DurationVar ( & s . PVClaimBinderSyncPeriod , "pvclaimbinder-sync-period" , s . PVClaimBinderSyncPeriod , "The period for syncing persistent volumes and persistent volume claims" )
2015-10-06 09:12:00 +00:00
fs . DurationVar ( & s . MinResyncPeriod , "min-resync-period" , s . MinResyncPeriod , "The resync period in reflectors will be random between MinResyncPeriod and 2*MinResyncPeriod" )
2015-09-03 03:14:26 +00:00
fs . StringVar ( & s . VolumeConfigFlags . PersistentVolumeRecyclerPodTemplateFilePathNFS , "pv-recycler-pod-template-filepath-nfs" , s . VolumeConfigFlags . PersistentVolumeRecyclerPodTemplateFilePathNFS , "The file path to a pod definition used as a template for NFS persistent volume recycling" )
fs . IntVar ( & s . VolumeConfigFlags . PersistentVolumeRecyclerMinimumTimeoutNFS , "pv-recycler-minimum-timeout-nfs" , s . VolumeConfigFlags . PersistentVolumeRecyclerMinimumTimeoutNFS , "The minimum ActiveDeadlineSeconds to use for an NFS Recycler pod" )
fs . IntVar ( & s . VolumeConfigFlags . PersistentVolumeRecyclerIncrementTimeoutNFS , "pv-recycler-increment-timeout-nfs" , s . VolumeConfigFlags . PersistentVolumeRecyclerIncrementTimeoutNFS , "the increment of time added per Gi to ActiveDeadlineSeconds for an NFS scrubber pod" )
fs . StringVar ( & s . VolumeConfigFlags . PersistentVolumeRecyclerPodTemplateFilePathHostPath , "pv-recycler-pod-template-filepath-hostpath" , s . VolumeConfigFlags . PersistentVolumeRecyclerPodTemplateFilePathHostPath , "The file path to a pod definition used as a template for HostPath persistent volume recycling. This is for development and testing only and will not work in a multi-node cluster." )
fs . IntVar ( & s . VolumeConfigFlags . PersistentVolumeRecyclerMinimumTimeoutHostPath , "pv-recycler-minimum-timeout-hostpath" , s . VolumeConfigFlags . PersistentVolumeRecyclerMinimumTimeoutHostPath , "The minimum ActiveDeadlineSeconds to use for a HostPath Recycler pod. This is for development and testing only and will not work in a multi-node cluster." )
fs . IntVar ( & s . VolumeConfigFlags . PersistentVolumeRecyclerIncrementTimeoutHostPath , "pv-recycler-timeout-increment-hostpath" , s . VolumeConfigFlags . PersistentVolumeRecyclerIncrementTimeoutHostPath , "the increment of time added per Gi to ActiveDeadlineSeconds for a HostPath scrubber pod. This is for development and testing only and will not work in a multi-node cluster." )
2015-10-12 18:27:49 +00:00
fs . BoolVar ( & s . VolumeConfigFlags . EnableHostPathProvisioning , "enable-hostpath-provisioner" , s . VolumeConfigFlags . EnableHostPathProvisioning , "Enable HostPath PV provisioning when running without a cloud provider. This allows testing and development of provisioning features. HostPath provisioning is not supported in any way, won't work in a multi-node cluster, and should not be used for anything other than testing or development." )
2015-09-21 22:51:27 +00:00
fs . IntVar ( & s . TerminatedPodGCThreshold , "terminated-pod-gc-threshold" , s . TerminatedPodGCThreshold , "Number of terminated pods that can exist before the terminated pod garbage collector starts deleting terminated pods. If <= 0, the terminated pod garbage collector is disabled." )
2015-08-25 14:54:54 +00:00
fs . DurationVar ( & s . HorizontalPodAutoscalerSyncPeriod , "horizontal-pod-autoscaler-sync-period" , s . HorizontalPodAutoscalerSyncPeriod , "The period for syncing the number of pods in horizontal pod autoscaler." )
2015-09-03 00:02:22 +00:00
fs . DurationVar ( & s . DeploymentControllerSyncPeriod , "deployment-controller-sync-period" , s . DeploymentControllerSyncPeriod , "Period for syncing the deployments." )
2015-07-27 18:03:13 +00:00
fs . DurationVar ( & s . PodEvictionTimeout , "pod-eviction-timeout" , s . PodEvictionTimeout , "The grace period for deleting pods on failed nodes." )
2015-04-24 06:10:33 +00:00
fs . Float32Var ( & s . DeletingPodsQps , "deleting-pods-qps" , 0.1 , "Number of nodes per second on which pods are deleted in case of node failure." )
fs . IntVar ( & s . DeletingPodsBurst , "deleting-pods-burst" , 10 , "Number of nodes on which pods are bursty deleted in case of node failure. For more details look into RateLimiter." )
fs . IntVar ( & s . RegisterRetryCount , "register-retry-count" , s . RegisterRetryCount , "" +
"The number of retries for initial node registration. Retry interval equals node-sync-period." )
2015-08-08 21:29:57 +00:00
fs . MarkDeprecated ( "register-retry-count" , "This flag is currently no-op and will be deleted." )
2015-10-20 19:04:09 +00:00
fs . DurationVar ( & s . NodeMonitorGracePeriod , "node-monitor-grace-period" , s . NodeMonitorGracePeriod ,
2015-03-27 14:09:51 +00:00
"Amount of time which we allow running Node to be unresponsive before marking it unhealty. " +
"Must be N times more than kubelet's nodeStatusUpdateFrequency, " +
"where N means number of retries allowed for kubelet to post node status." )
2015-10-20 19:04:09 +00:00
fs . DurationVar ( & s . NodeStartupGracePeriod , "node-startup-grace-period" , s . NodeStartupGracePeriod ,
2015-03-27 14:09:51 +00:00
"Amount of time which we allow starting Node to be unresponsive before marking it unhealty." )
2015-10-20 19:04:09 +00:00
fs . DurationVar ( & s . NodeMonitorPeriod , "node-monitor-period" , s . NodeMonitorPeriod ,
2015-03-27 14:09:51 +00:00
"The period for syncing NodeStatus in NodeController." )
2015-05-01 16:02:38 +00:00
fs . StringVar ( & s . ServiceAccountKeyFile , "service-account-private-key-file" , s . ServiceAccountKeyFile , "Filename containing a PEM-encoded private RSA key used to sign service account tokens." )
2015-05-04 11:22:25 +00:00
fs . BoolVar ( & s . EnableProfiling , "profiling" , true , "Enable profiling via web interface host:port/debug/pprof/" )
2015-05-22 22:47:16 +00:00
fs . StringVar ( & s . ClusterName , "cluster-name" , s . ClusterName , "The instance prefix for the cluster" )
2015-08-05 22:44:51 +00:00
fs . IPNetVar ( & s . ClusterCIDR , "cluster-cidr" , s . ClusterCIDR , "CIDR Range for Pods in cluster." )
2015-04-28 15:02:45 +00:00
fs . BoolVar ( & s . AllocateNodeCIDRs , "allocate-node-cidrs" , false , "Should CIDRs for Pods be allocated and set on the cloud provider." )
2015-04-17 07:18:07 +00:00
fs . StringVar ( & s . Master , "master" , s . Master , "The address of the Kubernetes API server (overrides any value in kubeconfig)" )
fs . StringVar ( & s . Kubeconfig , "kubeconfig" , s . Kubeconfig , "Path to kubeconfig file with authorization and master location information." )
2015-06-23 22:43:59 +00:00
fs . StringVar ( & s . RootCAFile , "root-ca-file" , s . RootCAFile , "If set, this root certificate authority will be included in service account's token secret. This must be a valid PEM-encoded CA bundle." )
2015-10-20 12:33:48 +00:00
fs . Float32Var ( & s . KubeAPIQPS , "kube-api-qps" , s . KubeAPIQPS , "QPS to use while talking with kubernetes apiserver" )
fs . IntVar ( & s . KubeAPIBurst , "kube-api-burst" , s . KubeAPIBurst , "Burst to use while talking with kubernetes apiserver" )
2015-01-30 23:31:36 +00:00
}
2015-10-22 18:20:03 +00:00
func ( s * CMServer ) ResyncPeriod ( ) time . Duration {
2015-10-06 09:12:00 +00:00
factor := rand . Float64 ( ) + 1
return time . Duration ( float64 ( s . MinResyncPeriod . Nanoseconds ( ) ) * factor )
}
2015-12-02 12:12:31 +00:00
func clientForUserAgentOrDie ( config client . Config , userAgent string ) * client . Client {
fullUserAgent := client . DefaultKubernetesUserAgent ( ) + "/" + userAgent
config . UserAgent = fullUserAgent
kubeClient , err := client . New ( & config )
if err != nil {
glog . Fatalf ( "Invalid API configuration: %v" , err )
}
return kubeClient
}
2015-01-30 23:31:36 +00:00
// Run runs the CMServer. This should never exit.
func ( s * CMServer ) Run ( _ [ ] string ) error {
2015-11-06 18:34:49 +00:00
kubeconfig , err := clientcmd . BuildConfigFromFlags ( s . Master , s . Kubeconfig )
2015-04-17 07:18:07 +00:00
if err != nil {
return err
}
2015-10-12 15:56:15 +00:00
// Override kubeconfig qps/burst settings from flags
2015-10-20 12:33:48 +00:00
kubeconfig . QPS = s . KubeAPIQPS
kubeconfig . Burst = s . KubeAPIBurst
2015-04-17 07:18:07 +00:00
kubeClient , err := client . New ( kubeconfig )
2015-01-30 23:31:36 +00:00
if err != nil {
glog . Fatalf ( "Invalid API configuration: %v" , err )
}
2015-03-13 15:44:11 +00:00
go func ( ) {
2015-04-22 14:46:03 +00:00
mux := http . NewServeMux ( )
healthz . InstallHandler ( mux )
2015-03-13 15:44:11 +00:00
if s . EnableProfiling {
mux . HandleFunc ( "/debug/pprof/" , pprof . Index )
mux . HandleFunc ( "/debug/pprof/profile" , pprof . Profile )
mux . HandleFunc ( "/debug/pprof/symbol" , pprof . Symbol )
}
2015-04-22 14:46:03 +00:00
mux . Handle ( "/metrics" , prometheus . Handler ( ) )
server := & http . Server {
Addr : net . JoinHostPort ( s . Address . String ( ) , strconv . Itoa ( s . Port ) ) ,
Handler : mux ,
}
glog . Fatal ( server . ListenAndServe ( ) )
2015-03-13 15:44:11 +00:00
} ( )
2015-01-30 23:31:36 +00:00
2015-12-02 12:12:31 +00:00
go endpointcontroller . NewEndpointController ( clientForUserAgentOrDie ( * kubeconfig , "endpoint-controller" ) , s . ResyncPeriod ) .
2015-10-06 09:12:00 +00:00
Run ( s . ConcurrentEndpointSyncs , util . NeverStop )
2015-01-30 23:31:36 +00:00
2015-12-02 12:12:31 +00:00
go replicationcontroller . NewReplicationManager (
clientForUserAgentOrDie ( * kubeconfig , "replication-controller" ) ,
s . ResyncPeriod ,
replicationcontroller . BurstReplicas ,
) . Run ( s . ConcurrentRCSyncs , util . NeverStop )
2015-01-30 23:31:36 +00:00
2015-09-21 22:51:27 +00:00
if s . TerminatedPodGCThreshold > 0 {
2015-12-02 12:12:31 +00:00
go gc . New ( clientForUserAgentOrDie ( * kubeconfig , "garbage-collector" ) , s . ResyncPeriod , s . TerminatedPodGCThreshold ) .
2015-09-21 22:51:27 +00:00
Run ( util . NeverStop )
}
2015-07-01 18:41:49 +00:00
cloud , err := cloudprovider . InitCloudProvider ( s . CloudProvider , s . CloudConfigFile )
if err != nil {
glog . Fatalf ( "Cloud provider could not be initialized: %v" , err )
}
2015-02-07 19:53:42 +00:00
2015-12-02 12:12:31 +00:00
nodeController := nodecontroller . NewNodeController ( cloud , clientForUserAgentOrDie ( * kubeconfig , "node-controller" ) ,
2015-08-21 01:11:40 +00:00
s . PodEvictionTimeout , util . NewTokenBucketRateLimiter ( s . DeletingPodsQps , s . DeletingPodsBurst ) ,
2015-09-29 09:29:51 +00:00
util . NewTokenBucketRateLimiter ( s . DeletingPodsQps , s . DeletingPodsBurst ) ,
2015-08-05 22:44:51 +00:00
s . NodeMonitorGracePeriod , s . NodeStartupGracePeriod , s . NodeMonitorPeriod , & s . ClusterCIDR , s . AllocateNodeCIDRs )
2015-05-22 22:14:48 +00:00
nodeController . Run ( s . NodeSyncPeriod )
2015-01-30 23:31:36 +00:00
2015-12-02 12:12:31 +00:00
serviceController := servicecontroller . New ( cloud , clientForUserAgentOrDie ( * kubeconfig , "service-controller" ) , s . ClusterName )
2015-07-27 18:03:13 +00:00
if err := serviceController . Run ( s . ServiceSyncPeriod , s . NodeSyncPeriod ) ; err != nil {
2015-03-24 17:32:43 +00:00
glog . Errorf ( "Failed to start service controller: %v" , err )
}
2015-05-15 21:49:26 +00:00
if s . AllocateNodeCIDRs {
2015-11-24 02:11:51 +00:00
if cloud == nil {
2015-07-26 00:02:23 +00:00
glog . Warning ( "allocate-node-cidrs is set, but no cloud provider specified. Will not manage routes." )
} else if routes , ok := cloud . Routes ( ) ; ! ok {
glog . Warning ( "allocate-node-cidrs is set, but cloud provider does not support routes. Will not manage routes." )
} else {
2015-12-02 12:12:31 +00:00
routeController := routecontroller . New ( routes , clientForUserAgentOrDie ( * kubeconfig , "route-controller" ) , s . ClusterName , & s . ClusterCIDR )
2015-07-26 00:02:23 +00:00
routeController . Run ( s . NodeSyncPeriod )
2015-05-15 21:49:26 +00:00
}
2015-11-24 02:11:51 +00:00
} else {
glog . Infof ( "allocate-node-cidrs set to %v, node controller not creating routes" , s . AllocateNodeCIDRs )
2015-05-15 21:49:26 +00:00
}
2015-11-11 21:19:39 +00:00
go resourcequotacontroller . NewResourceQuotaController (
2015-12-02 12:12:31 +00:00
clientForUserAgentOrDie ( * kubeconfig , "resourcequota-controller" ) ,
controller . StaticResyncPeriodFunc ( s . ResourceQuotaSyncPeriod ) ) . Run ( s . ConcurrentResourceQuotaSyncs , util . NeverStop )
2015-01-30 23:31:36 +00:00
2015-10-28 06:46:44 +00:00
// If apiserver is not running we should wait for some time and fail only then. This is particularly
// important when we start apiserver and controller manager at the same time.
var versionStrings [ ] string
err = wait . PollImmediate ( time . Second , 10 * time . Second , func ( ) ( bool , error ) {
2015-11-11 12:28:25 +00:00
if versionStrings , err = client . ServerAPIVersions ( kubeconfig ) ; err == nil {
return true , nil
}
glog . Errorf ( "Failed to get api versions from server: %v" , err )
return false , nil
2015-10-28 06:46:44 +00:00
} )
2015-10-12 21:23:50 +00:00
if err != nil {
glog . Fatalf ( "Failed to get api versions from server: %v" , err )
}
2015-10-13 00:31:25 +00:00
versions := & unversioned . APIVersions { Versions : versionStrings }
2015-03-20 16:49:03 +00:00
2015-10-15 23:34:30 +00:00
resourceMap , err := kubeClient . Discovery ( ) . ServerResources ( )
2015-10-12 21:23:50 +00:00
if err != nil {
glog . Fatalf ( "Failed to get supported resources from server: %v" , err )
}
2015-10-02 21:42:18 +00:00
2015-12-02 12:12:31 +00:00
namespacecontroller . NewNamespaceController ( clientForUserAgentOrDie ( * kubeconfig , "namespace-controller" ) , versions , s . NamespaceSyncPeriod ) . Run ( )
2015-10-12 21:23:50 +00:00
groupVersion := "extensions/v1beta1"
resources , found := resourceMap [ groupVersion ]
// TODO: this needs to be dynamic so users don't have to restart their controller manager if they change the apiserver
if containsVersion ( versions , groupVersion ) && found {
glog . Infof ( "Starting %s apis" , groupVersion )
if containsResource ( resources , "horizontalpodautoscalers" ) {
glog . Infof ( "Starting horizontal pod controller." )
2015-12-02 12:12:31 +00:00
hpaClient := clientForUserAgentOrDie ( * kubeconfig , "horizontal-pod-autoscaler" )
metricsClient := metrics . NewHeapsterMetricsClient (
hpaClient ,
metrics . DefaultHeapsterNamespace ,
metrics . DefaultHeapsterScheme ,
metrics . DefaultHeapsterService ,
metrics . DefaultHeapsterPort ,
)
2015-11-02 15:18:53 +00:00
podautoscaler . NewHorizontalController ( hpaClient , hpaClient , hpaClient , metricsClient ) .
2015-10-12 21:23:50 +00:00
Run ( s . HorizontalPodAutoscalerSyncPeriod )
}
2015-10-02 21:42:18 +00:00
2015-10-12 21:23:50 +00:00
if containsResource ( resources , "daemonsets" ) {
glog . Infof ( "Starting daemon set controller" )
2015-12-02 12:12:31 +00:00
go daemon . NewDaemonSetsController ( clientForUserAgentOrDie ( * kubeconfig , "daemon-set-controller" ) , s . ResyncPeriod ) .
2015-10-12 21:23:50 +00:00
Run ( s . ConcurrentDSCSyncs , util . NeverStop )
}
if containsResource ( resources , "jobs" ) {
glog . Infof ( "Starting job controller" )
2015-12-02 12:12:31 +00:00
go job . NewJobController ( clientForUserAgentOrDie ( * kubeconfig , "job-controller" ) , s . ResyncPeriod ) .
2015-10-12 21:23:50 +00:00
Run ( s . ConcurrentJobSyncs , util . NeverStop )
}
2015-10-02 21:42:18 +00:00
2015-10-12 21:23:50 +00:00
if containsResource ( resources , "deployments" ) {
glog . Infof ( "Starting deployment controller" )
2015-11-18 23:12:11 +00:00
go deployment . NewDeploymentController ( clientForUserAgentOrDie ( * kubeconfig , "deployment-controller" ) , s . ResyncPeriod ) .
2015-09-21 07:06:45 +00:00
Run ( s . ConcurrentDeploymentSyncs , util . NeverStop )
2015-10-12 21:23:50 +00:00
}
2015-09-03 00:02:22 +00:00
}
2015-09-03 14:50:53 +00:00
2015-10-12 18:27:49 +00:00
volumePlugins := ProbeRecyclableVolumePlugins ( s . VolumeConfigFlags )
provisioner , err := NewVolumeProvisioner ( cloud , s . VolumeConfigFlags )
if err != nil {
glog . Fatal ( "A Provisioner could not be created, but one was expected. Provisioning will not work. This functionality is considered an early Alpha version." )
}
2015-12-02 12:12:31 +00:00
pvclaimBinder := persistentvolumecontroller . NewPersistentVolumeClaimBinder ( clientForUserAgentOrDie ( * kubeconfig , "persistent-volume-binder" ) , s . PVClaimBinderSyncPeriod )
2015-05-13 00:44:29 +00:00
pvclaimBinder . Run ( )
2015-09-03 03:14:26 +00:00
2015-10-12 18:27:49 +00:00
pvRecycler , err := persistentvolumecontroller . NewPersistentVolumeRecycler ( clientForUserAgentOrDie ( * kubeconfig , "persistent-volume-recycler" ) , s . PVClaimBinderSyncPeriod , ProbeRecyclableVolumePlugins ( s . VolumeConfigFlags ) , cloud )
2015-05-29 20:34:32 +00:00
if err != nil {
glog . Fatalf ( "Failed to start persistent volume recycler: %+v" , err )
}
pvRecycler . Run ( )
2015-04-16 17:26:08 +00:00
2015-10-12 18:27:49 +00:00
if provisioner != nil {
pvController , err := persistentvolumecontroller . NewPersistentVolumeProvisionerController ( persistentvolumecontroller . NewControllerClient ( clientForUserAgentOrDie ( * kubeconfig , "persistent-volume-provisioner" ) ) , s . PVClaimBinderSyncPeriod , volumePlugins , provisioner , cloud )
if err != nil {
glog . Fatalf ( "Failed to start persistent volume provisioner controller: %+v" , err )
}
pvController . Run ( )
}
2015-06-23 22:43:59 +00:00
var rootCA [ ] byte
if s . RootCAFile != "" {
2015-06-25 18:40:48 +00:00
rootCA , err = ioutil . ReadFile ( s . RootCAFile )
2015-06-23 22:43:59 +00:00
if err != nil {
return fmt . Errorf ( "error reading root-ca-file at %s: %v" , s . RootCAFile , err )
}
if _ , err := util . CertsFromPEM ( rootCA ) ; err != nil {
return fmt . Errorf ( "error parsing root-ca-file at %s: %v" , s . RootCAFile , err )
}
} else {
rootCA = kubeconfig . CAData
}
2015-05-01 16:02:38 +00:00
if len ( s . ServiceAccountKeyFile ) > 0 {
privateKey , err := serviceaccount . ReadPrivateKey ( s . ServiceAccountKeyFile )
if err != nil {
glog . Errorf ( "Error reading key for service account token controller: %v" , err )
} else {
2015-12-24 21:54:40 +00:00
serviceaccountcontroller . NewTokensController (
2015-12-02 12:12:31 +00:00
clientForUserAgentOrDie ( * kubeconfig , "tokens-controller" ) ,
2015-12-24 21:54:40 +00:00
serviceaccountcontroller . TokensControllerOptions {
2015-06-23 22:43:59 +00:00
TokenGenerator : serviceaccount . JWTTokenGenerator ( privateKey ) ,
RootCA : rootCA ,
} ,
2015-05-01 16:02:38 +00:00
) . Run ( )
}
}
2015-12-24 21:54:40 +00:00
serviceaccountcontroller . NewServiceAccountsController (
2015-12-02 12:12:31 +00:00
clientForUserAgentOrDie ( * kubeconfig , "service-account-controller" ) ,
2015-12-24 21:54:40 +00:00
serviceaccountcontroller . DefaultServiceAccountsControllerOptions ( ) ,
2015-05-01 16:02:38 +00:00
) . Run ( )
2015-04-21 03:25:56 +00:00
2015-01-30 23:31:36 +00:00
select { }
}
2015-10-12 21:23:50 +00:00
2015-10-13 00:31:25 +00:00
func containsVersion ( versions * unversioned . APIVersions , version string ) bool {
2015-10-12 21:23:50 +00:00
for ix := range versions . Versions {
if versions . Versions [ ix ] == version {
return true
}
}
return false
}
2015-10-13 00:31:25 +00:00
func containsResource ( resources * unversioned . APIResourceList , resourceName string ) bool {
2015-10-12 21:23:50 +00:00
for ix := range resources . APIResources {
resource := resources . APIResources [ ix ]
if resource . Name == resourceName {
return true
}
}
return false
}