2016-12-05 14:04:32 +00:00
|
|
|
/*
|
|
|
|
Copyright 2016 The Kubernetes Authors.
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Package app implements a server that runs a set of active
|
|
|
|
// components. This includes replication controllers, service endpoints and
|
|
|
|
// nodes.
|
|
|
|
//
|
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2017-06-01 16:03:18 +00:00
|
|
|
"net"
|
2017-07-13 13:08:43 +00:00
|
|
|
"strings"
|
2017-06-01 16:03:18 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/golang/glog"
|
2016-12-05 14:04:32 +00:00
|
|
|
|
2018-07-25 19:45:54 +00:00
|
|
|
"net/http"
|
|
|
|
|
2017-06-22 18:24:23 +00:00
|
|
|
"k8s.io/api/core/v1"
|
2017-01-11 14:09:48 +00:00
|
|
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
2017-06-01 16:03:18 +00:00
|
|
|
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
2017-05-17 22:54:58 +00:00
|
|
|
cacheddiscovery "k8s.io/client-go/discovery/cached"
|
2017-01-25 19:00:30 +00:00
|
|
|
"k8s.io/client-go/dynamic"
|
2017-06-23 20:56:37 +00:00
|
|
|
clientset "k8s.io/client-go/kubernetes"
|
2018-08-22 10:49:05 +00:00
|
|
|
csiclientset "k8s.io/csi-api/pkg/client/clientset/versioned"
|
2016-12-05 14:04:32 +00:00
|
|
|
"k8s.io/kubernetes/pkg/controller"
|
|
|
|
endpointcontroller "k8s.io/kubernetes/pkg/controller/endpoint"
|
|
|
|
"k8s.io/kubernetes/pkg/controller/garbagecollector"
|
|
|
|
namespacecontroller "k8s.io/kubernetes/pkg/controller/namespace"
|
2017-10-11 23:36:39 +00:00
|
|
|
nodeipamcontroller "k8s.io/kubernetes/pkg/controller/nodeipam"
|
|
|
|
"k8s.io/kubernetes/pkg/controller/nodeipam/ipam"
|
|
|
|
lifecyclecontroller "k8s.io/kubernetes/pkg/controller/nodelifecycle"
|
2016-12-05 14:04:32 +00:00
|
|
|
"k8s.io/kubernetes/pkg/controller/podgc"
|
|
|
|
replicationcontroller "k8s.io/kubernetes/pkg/controller/replication"
|
|
|
|
resourcequotacontroller "k8s.io/kubernetes/pkg/controller/resourcequota"
|
2017-06-01 16:03:18 +00:00
|
|
|
routecontroller "k8s.io/kubernetes/pkg/controller/route"
|
|
|
|
servicecontroller "k8s.io/kubernetes/pkg/controller/service"
|
2016-12-05 14:04:32 +00:00
|
|
|
serviceaccountcontroller "k8s.io/kubernetes/pkg/controller/serviceaccount"
|
2017-01-30 10:48:15 +00:00
|
|
|
ttlcontroller "k8s.io/kubernetes/pkg/controller/ttl"
|
2017-06-01 16:03:18 +00:00
|
|
|
"k8s.io/kubernetes/pkg/controller/volume/attachdetach"
|
2017-09-04 07:02:34 +00:00
|
|
|
"k8s.io/kubernetes/pkg/controller/volume/expand"
|
2017-06-01 16:03:18 +00:00
|
|
|
persistentvolumecontroller "k8s.io/kubernetes/pkg/controller/volume/persistentvolume"
|
2017-11-15 22:03:43 +00:00
|
|
|
"k8s.io/kubernetes/pkg/controller/volume/pvcprotection"
|
2018-01-24 14:28:04 +00:00
|
|
|
"k8s.io/kubernetes/pkg/controller/volume/pvprotection"
|
2017-06-01 16:03:18 +00:00
|
|
|
"k8s.io/kubernetes/pkg/features"
|
2017-10-27 15:07:53 +00:00
|
|
|
"k8s.io/kubernetes/pkg/quota/generic"
|
2016-12-05 14:04:32 +00:00
|
|
|
quotainstall "k8s.io/kubernetes/pkg/quota/install"
|
2017-07-19 19:36:45 +00:00
|
|
|
"k8s.io/kubernetes/pkg/util/metrics"
|
2016-12-05 14:04:32 +00:00
|
|
|
)
|
|
|
|
|
2018-07-25 19:45:54 +00:00
|
|
|
func startServiceController(ctx ControllerContext) (http.Handler, bool, error) {
|
2017-06-01 16:03:18 +00:00
|
|
|
serviceController, err := servicecontroller.New(
|
|
|
|
ctx.Cloud,
|
|
|
|
ctx.ClientBuilder.ClientOrDie("service-controller"),
|
|
|
|
ctx.InformerFactory.Core().V1().Services(),
|
|
|
|
ctx.InformerFactory.Core().V1().Nodes(),
|
2018-04-12 03:12:10 +00:00
|
|
|
ctx.ComponentConfig.KubeCloudShared.ClusterName,
|
2017-06-01 16:03:18 +00:00
|
|
|
)
|
|
|
|
if err != nil {
|
2017-10-31 14:19:55 +00:00
|
|
|
// This error shouldn't fail. It lives like this as a legacy.
|
2017-06-01 16:03:18 +00:00
|
|
|
glog.Errorf("Failed to start service controller: %v", err)
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, false, nil
|
2017-06-01 16:03:18 +00:00
|
|
|
}
|
2018-04-12 03:12:10 +00:00
|
|
|
go serviceController.Run(ctx.Stop, int(ctx.ComponentConfig.ServiceController.ConcurrentServiceSyncs))
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, true, nil
|
2017-06-01 16:03:18 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 19:45:54 +00:00
|
|
|
func startNodeIpamController(ctx ControllerContext) (http.Handler, bool, error) {
|
2017-11-01 11:51:07 +00:00
|
|
|
var clusterCIDR *net.IPNet = nil
|
|
|
|
var serviceCIDR *net.IPNet = nil
|
2018-04-24 02:01:01 +00:00
|
|
|
|
|
|
|
if !ctx.ComponentConfig.KubeCloudShared.AllocateNodeCIDRs {
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, false, nil
|
2018-04-24 02:01:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var err error
|
|
|
|
if len(strings.TrimSpace(ctx.ComponentConfig.KubeCloudShared.ClusterCIDR)) != 0 {
|
|
|
|
_, clusterCIDR, err = net.ParseCIDR(ctx.ComponentConfig.KubeCloudShared.ClusterCIDR)
|
|
|
|
if err != nil {
|
|
|
|
glog.Warningf("Unsuccessful parsing of cluster CIDR %v: %v", ctx.ComponentConfig.KubeCloudShared.ClusterCIDR, err)
|
2017-07-13 13:08:43 +00:00
|
|
|
}
|
2018-04-24 02:01:01 +00:00
|
|
|
}
|
2017-07-13 13:08:43 +00:00
|
|
|
|
2018-04-24 02:01:01 +00:00
|
|
|
if len(strings.TrimSpace(ctx.ComponentConfig.NodeIpamController.ServiceCIDR)) != 0 {
|
|
|
|
_, serviceCIDR, err = net.ParseCIDR(ctx.ComponentConfig.NodeIpamController.ServiceCIDR)
|
|
|
|
if err != nil {
|
|
|
|
glog.Warningf("Unsuccessful parsing of service CIDR %v: %v", ctx.ComponentConfig.NodeIpamController.ServiceCIDR, err)
|
2017-07-13 13:08:43 +00:00
|
|
|
}
|
2017-06-01 16:03:18 +00:00
|
|
|
}
|
2017-07-13 13:08:43 +00:00
|
|
|
|
2017-10-11 23:36:39 +00:00
|
|
|
nodeIpamController, err := nodeipamcontroller.NewNodeIpamController(
|
|
|
|
ctx.InformerFactory.Core().V1().Nodes(),
|
|
|
|
ctx.Cloud,
|
|
|
|
ctx.ClientBuilder.ClientOrDie("node-controller"),
|
|
|
|
clusterCIDR,
|
|
|
|
serviceCIDR,
|
2018-04-12 03:12:10 +00:00
|
|
|
int(ctx.ComponentConfig.NodeIpamController.NodeCIDRMaskSize),
|
|
|
|
ipam.CIDRAllocatorType(ctx.ComponentConfig.KubeCloudShared.CIDRAllocatorType),
|
2017-10-11 23:36:39 +00:00
|
|
|
)
|
|
|
|
if err != nil {
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, true, err
|
2017-10-11 23:36:39 +00:00
|
|
|
}
|
|
|
|
go nodeIpamController.Run(ctx.Stop)
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, true, nil
|
2017-10-11 23:36:39 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 19:45:54 +00:00
|
|
|
func startNodeLifecycleController(ctx ControllerContext) (http.Handler, bool, error) {
|
2017-10-11 23:36:39 +00:00
|
|
|
lifecycleController, err := lifecyclecontroller.NewNodeLifecycleController(
|
2017-06-01 16:03:18 +00:00
|
|
|
ctx.InformerFactory.Core().V1().Pods(),
|
|
|
|
ctx.InformerFactory.Core().V1().Nodes(),
|
|
|
|
ctx.InformerFactory.Extensions().V1beta1().DaemonSets(),
|
|
|
|
ctx.Cloud,
|
|
|
|
ctx.ClientBuilder.ClientOrDie("node-controller"),
|
2018-04-12 03:12:10 +00:00
|
|
|
ctx.ComponentConfig.KubeCloudShared.NodeMonitorPeriod.Duration,
|
|
|
|
ctx.ComponentConfig.NodeLifecycleController.NodeStartupGracePeriod.Duration,
|
|
|
|
ctx.ComponentConfig.NodeLifecycleController.NodeMonitorGracePeriod.Duration,
|
|
|
|
ctx.ComponentConfig.NodeLifecycleController.PodEvictionTimeout.Duration,
|
|
|
|
ctx.ComponentConfig.NodeLifecycleController.NodeEvictionRate,
|
|
|
|
ctx.ComponentConfig.NodeLifecycleController.SecondaryNodeEvictionRate,
|
|
|
|
ctx.ComponentConfig.NodeLifecycleController.LargeClusterSizeThreshold,
|
|
|
|
ctx.ComponentConfig.NodeLifecycleController.UnhealthyZoneThreshold,
|
|
|
|
ctx.ComponentConfig.NodeLifecycleController.EnableTaintManager,
|
2017-06-01 16:03:18 +00:00
|
|
|
utilfeature.DefaultFeatureGate.Enabled(features.TaintBasedEvictions),
|
2017-07-19 15:51:19 +00:00
|
|
|
utilfeature.DefaultFeatureGate.Enabled(features.TaintNodesByCondition),
|
2017-06-01 16:03:18 +00:00
|
|
|
)
|
|
|
|
if err != nil {
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, true, err
|
2017-06-01 16:03:18 +00:00
|
|
|
}
|
2017-10-11 23:36:39 +00:00
|
|
|
go lifecycleController.Run(ctx.Stop)
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, true, nil
|
2017-06-01 16:03:18 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 19:45:54 +00:00
|
|
|
func startRouteController(ctx ControllerContext) (http.Handler, bool, error) {
|
2018-04-12 03:12:10 +00:00
|
|
|
if !ctx.ComponentConfig.KubeCloudShared.AllocateNodeCIDRs || !ctx.ComponentConfig.KubeCloudShared.ConfigureCloudRoutes {
|
|
|
|
glog.Infof("Will not configure cloud provider routes for allocate-node-cidrs: %v, configure-cloud-routes: %v.", ctx.ComponentConfig.KubeCloudShared.AllocateNodeCIDRs, ctx.ComponentConfig.KubeCloudShared.ConfigureCloudRoutes)
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, false, nil
|
2017-06-01 16:03:18 +00:00
|
|
|
}
|
2017-07-25 08:21:48 +00:00
|
|
|
if ctx.Cloud == nil {
|
|
|
|
glog.Warning("configure-cloud-routes is set, but no cloud provider specified. Will not configure cloud provider routes.")
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, false, nil
|
2017-07-25 08:21:48 +00:00
|
|
|
}
|
|
|
|
routes, ok := ctx.Cloud.Routes()
|
|
|
|
if !ok {
|
|
|
|
glog.Warning("configure-cloud-routes is set, but cloud provider does not support routes. Will not configure cloud provider routes.")
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, false, nil
|
2017-07-25 08:21:48 +00:00
|
|
|
}
|
2018-04-12 03:12:10 +00:00
|
|
|
_, clusterCIDR, err := net.ParseCIDR(ctx.ComponentConfig.KubeCloudShared.ClusterCIDR)
|
2017-11-01 11:51:07 +00:00
|
|
|
if err != nil {
|
2018-04-12 03:12:10 +00:00
|
|
|
glog.Warningf("Unsuccessful parsing of cluster CIDR %v: %v", ctx.ComponentConfig.KubeCloudShared.ClusterCIDR, err)
|
2017-11-01 11:51:07 +00:00
|
|
|
}
|
2018-04-12 03:12:10 +00:00
|
|
|
routeController := routecontroller.New(routes, ctx.ClientBuilder.ClientOrDie("route-controller"), ctx.InformerFactory.Core().V1().Nodes(), ctx.ComponentConfig.KubeCloudShared.ClusterName, clusterCIDR)
|
|
|
|
go routeController.Run(ctx.Stop, ctx.ComponentConfig.KubeCloudShared.RouteReconciliationPeriod.Duration)
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, true, nil
|
2017-06-01 16:03:18 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 19:45:54 +00:00
|
|
|
func startPersistentVolumeBinderController(ctx ControllerContext) (http.Handler, bool, error) {
|
2017-06-01 16:03:18 +00:00
|
|
|
params := persistentvolumecontroller.ControllerParameters{
|
|
|
|
KubeClient: ctx.ClientBuilder.ClientOrDie("persistent-volume-binder"),
|
2018-04-12 03:12:10 +00:00
|
|
|
SyncPeriod: ctx.ComponentConfig.PersistentVolumeBinderController.PVClaimBinderSyncPeriod.Duration,
|
|
|
|
VolumePlugins: ProbeControllerVolumePlugins(ctx.Cloud, ctx.ComponentConfig.PersistentVolumeBinderController.VolumeConfiguration),
|
2017-06-01 16:03:18 +00:00
|
|
|
Cloud: ctx.Cloud,
|
2018-04-12 03:12:10 +00:00
|
|
|
ClusterName: ctx.ComponentConfig.KubeCloudShared.ClusterName,
|
2017-06-01 16:03:18 +00:00
|
|
|
VolumeInformer: ctx.InformerFactory.Core().V1().PersistentVolumes(),
|
|
|
|
ClaimInformer: ctx.InformerFactory.Core().V1().PersistentVolumeClaims(),
|
|
|
|
ClassInformer: ctx.InformerFactory.Storage().V1().StorageClasses(),
|
2018-02-05 14:40:25 +00:00
|
|
|
PodInformer: ctx.InformerFactory.Core().V1().Pods(),
|
2018-05-23 08:12:20 +00:00
|
|
|
NodeInformer: ctx.InformerFactory.Core().V1().Nodes(),
|
2018-04-12 03:12:10 +00:00
|
|
|
EnableDynamicProvisioning: ctx.ComponentConfig.PersistentVolumeBinderController.VolumeConfiguration.EnableDynamicProvisioning,
|
2017-06-01 16:03:18 +00:00
|
|
|
}
|
|
|
|
volumeController, volumeControllerErr := persistentvolumecontroller.NewController(params)
|
|
|
|
if volumeControllerErr != nil {
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, true, fmt.Errorf("failed to construct persistentvolume controller: %v", volumeControllerErr)
|
2017-06-01 16:03:18 +00:00
|
|
|
}
|
|
|
|
go volumeController.Run(ctx.Stop)
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, true, nil
|
2017-06-01 16:03:18 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 19:45:54 +00:00
|
|
|
func startAttachDetachController(ctx ControllerContext) (http.Handler, bool, error) {
|
2018-04-12 03:12:10 +00:00
|
|
|
if ctx.ComponentConfig.AttachDetachController.ReconcilerSyncLoopPeriod.Duration < time.Second {
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, true, fmt.Errorf("Duration time must be greater than one second as set via command line option reconcile-sync-loop-period.")
|
2017-06-01 16:03:18 +00:00
|
|
|
}
|
2018-08-22 10:49:05 +00:00
|
|
|
csiClientConfig := ctx.ClientBuilder.ConfigOrDie("attachdetach-controller")
|
|
|
|
// csiClient works with CRDs that support json only
|
|
|
|
csiClientConfig.ContentType = "application/json"
|
|
|
|
|
2017-06-01 16:03:18 +00:00
|
|
|
attachDetachController, attachDetachControllerErr :=
|
|
|
|
attachdetach.NewAttachDetachController(
|
|
|
|
ctx.ClientBuilder.ClientOrDie("attachdetach-controller"),
|
2018-08-22 10:49:05 +00:00
|
|
|
csiclientset.NewForConfigOrDie(csiClientConfig),
|
2017-06-01 16:03:18 +00:00
|
|
|
ctx.InformerFactory.Core().V1().Pods(),
|
|
|
|
ctx.InformerFactory.Core().V1().Nodes(),
|
|
|
|
ctx.InformerFactory.Core().V1().PersistentVolumeClaims(),
|
|
|
|
ctx.InformerFactory.Core().V1().PersistentVolumes(),
|
|
|
|
ctx.Cloud,
|
2017-07-26 00:48:26 +00:00
|
|
|
ProbeAttachableVolumePlugins(),
|
2018-04-12 03:12:10 +00:00
|
|
|
GetDynamicPluginProber(ctx.ComponentConfig.PersistentVolumeBinderController.VolumeConfiguration),
|
|
|
|
ctx.ComponentConfig.AttachDetachController.DisableAttachDetachReconcilerSync,
|
|
|
|
ctx.ComponentConfig.AttachDetachController.ReconcilerSyncLoopPeriod.Duration,
|
2017-06-16 10:15:04 +00:00
|
|
|
attachdetach.DefaultTimerConfig,
|
|
|
|
)
|
2017-06-01 16:03:18 +00:00
|
|
|
if attachDetachControllerErr != nil {
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, true, fmt.Errorf("failed to start attach/detach controller: %v", attachDetachControllerErr)
|
2017-06-01 16:03:18 +00:00
|
|
|
}
|
|
|
|
go attachDetachController.Run(ctx.Stop)
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, true, nil
|
2017-06-01 16:03:18 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 19:45:54 +00:00
|
|
|
func startVolumeExpandController(ctx ControllerContext) (http.Handler, bool, error) {
|
2017-09-04 07:02:34 +00:00
|
|
|
if utilfeature.DefaultFeatureGate.Enabled(features.ExpandPersistentVolumes) {
|
|
|
|
expandController, expandControllerErr := expand.NewExpandController(
|
|
|
|
ctx.ClientBuilder.ClientOrDie("expand-controller"),
|
|
|
|
ctx.InformerFactory.Core().V1().PersistentVolumeClaims(),
|
|
|
|
ctx.InformerFactory.Core().V1().PersistentVolumes(),
|
|
|
|
ctx.Cloud,
|
2018-04-12 03:12:10 +00:00
|
|
|
ProbeExpandableVolumePlugins(ctx.ComponentConfig.PersistentVolumeBinderController.VolumeConfiguration))
|
2017-09-04 07:02:34 +00:00
|
|
|
|
|
|
|
if expandControllerErr != nil {
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, true, fmt.Errorf("Failed to start volume expand controller : %v", expandControllerErr)
|
2017-09-04 07:02:34 +00:00
|
|
|
}
|
|
|
|
go expandController.Run(ctx.Stop)
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, true, nil
|
2017-09-04 07:02:34 +00:00
|
|
|
}
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, false, nil
|
2017-09-04 07:02:34 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 19:45:54 +00:00
|
|
|
func startEndpointController(ctx ControllerContext) (http.Handler, bool, error) {
|
2016-12-05 14:04:32 +00:00
|
|
|
go endpointcontroller.NewEndpointController(
|
2017-02-24 14:52:43 +00:00
|
|
|
ctx.InformerFactory.Core().V1().Pods(),
|
|
|
|
ctx.InformerFactory.Core().V1().Services(),
|
2017-06-19 15:47:29 +00:00
|
|
|
ctx.InformerFactory.Core().V1().Endpoints(),
|
2016-12-05 14:04:32 +00:00
|
|
|
ctx.ClientBuilder.ClientOrDie("endpoint-controller"),
|
2018-04-12 03:12:10 +00:00
|
|
|
).Run(int(ctx.ComponentConfig.EndPointController.ConcurrentEndpointSyncs), ctx.Stop)
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, true, nil
|
2016-12-05 14:04:32 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 19:45:54 +00:00
|
|
|
func startReplicationController(ctx ControllerContext) (http.Handler, bool, error) {
|
2016-12-05 14:04:32 +00:00
|
|
|
go replicationcontroller.NewReplicationManager(
|
2017-02-24 14:52:43 +00:00
|
|
|
ctx.InformerFactory.Core().V1().Pods(),
|
|
|
|
ctx.InformerFactory.Core().V1().ReplicationControllers(),
|
2016-12-05 14:04:32 +00:00
|
|
|
ctx.ClientBuilder.ClientOrDie("replication-controller"),
|
|
|
|
replicationcontroller.BurstReplicas,
|
2018-04-12 03:12:10 +00:00
|
|
|
).Run(int(ctx.ComponentConfig.ReplicationController.ConcurrentRCSyncs), ctx.Stop)
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, true, nil
|
2016-12-05 14:04:32 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 19:45:54 +00:00
|
|
|
func startPodGCController(ctx ControllerContext) (http.Handler, bool, error) {
|
2016-12-05 14:04:32 +00:00
|
|
|
go podgc.NewPodGC(
|
|
|
|
ctx.ClientBuilder.ClientOrDie("pod-garbage-collector"),
|
2017-02-24 14:52:43 +00:00
|
|
|
ctx.InformerFactory.Core().V1().Pods(),
|
2018-04-12 03:12:10 +00:00
|
|
|
int(ctx.ComponentConfig.PodGCController.TerminatedPodGCThreshold),
|
2016-12-05 14:04:32 +00:00
|
|
|
).Run(ctx.Stop)
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, true, nil
|
2016-12-05 14:04:32 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 19:45:54 +00:00
|
|
|
func startResourceQuotaController(ctx ControllerContext) (http.Handler, bool, error) {
|
2016-12-05 14:04:32 +00:00
|
|
|
resourceQuotaControllerClient := ctx.ClientBuilder.ClientOrDie("resourcequota-controller")
|
2017-10-27 15:07:53 +00:00
|
|
|
discoveryFunc := resourceQuotaControllerClient.Discovery().ServerPreferredNamespacedResources
|
|
|
|
listerFuncForResource := generic.ListerFuncForResourceFunc(ctx.InformerFactory.ForResource)
|
|
|
|
quotaConfiguration := quotainstall.NewQuotaConfigurationForControllers(listerFuncForResource)
|
|
|
|
|
2016-12-05 14:04:32 +00:00
|
|
|
resourceQuotaControllerOptions := &resourcequotacontroller.ResourceQuotaControllerOptions{
|
2017-10-25 15:54:32 +00:00
|
|
|
QuotaClient: resourceQuotaControllerClient.CoreV1(),
|
2017-02-24 14:52:43 +00:00
|
|
|
ResourceQuotaInformer: ctx.InformerFactory.Core().V1().ResourceQuotas(),
|
2018-04-12 03:12:10 +00:00
|
|
|
ResyncPeriod: controller.StaticResyncPeriodFunc(ctx.ComponentConfig.ResourceQuotaController.ResourceQuotaSyncPeriod.Duration),
|
2017-10-27 15:07:53 +00:00
|
|
|
InformerFactory: ctx.InformerFactory,
|
2018-02-05 06:48:30 +00:00
|
|
|
ReplenishmentResyncPeriod: ctx.ResyncPeriod,
|
2017-10-27 15:07:53 +00:00
|
|
|
DiscoveryFunc: discoveryFunc,
|
|
|
|
IgnoredResourcesFunc: quotaConfiguration.IgnoredResources,
|
|
|
|
InformersStarted: ctx.InformersStarted,
|
|
|
|
Registry: generic.NewRegistry(quotaConfiguration.Evaluators()),
|
2016-12-05 14:04:32 +00:00
|
|
|
}
|
2017-10-25 15:54:32 +00:00
|
|
|
if resourceQuotaControllerClient.CoreV1().RESTClient().GetRateLimiter() != nil {
|
2017-10-31 14:19:55 +00:00
|
|
|
if err := metrics.RegisterMetricAndTrackRateLimiterUsage("resource_quota_controller", resourceQuotaControllerClient.CoreV1().RESTClient().GetRateLimiter()); err != nil {
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, true, err
|
2017-10-31 14:19:55 +00:00
|
|
|
}
|
2017-07-19 19:36:45 +00:00
|
|
|
}
|
|
|
|
|
2017-10-27 15:07:53 +00:00
|
|
|
resourceQuotaController, err := resourcequotacontroller.NewResourceQuotaController(resourceQuotaControllerOptions)
|
|
|
|
if err != nil {
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, false, err
|
2017-10-27 15:07:53 +00:00
|
|
|
}
|
2018-04-12 03:12:10 +00:00
|
|
|
go resourceQuotaController.Run(int(ctx.ComponentConfig.ResourceQuotaController.ConcurrentResourceQuotaSyncs), ctx.Stop)
|
2017-10-27 15:07:53 +00:00
|
|
|
|
|
|
|
// Periodically the quota controller to detect new resource types
|
|
|
|
go resourceQuotaController.Sync(discoveryFunc, 30*time.Second, ctx.Stop)
|
|
|
|
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, true, nil
|
2016-12-05 14:04:32 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 19:45:54 +00:00
|
|
|
func startNamespaceController(ctx ControllerContext) (http.Handler, bool, error) {
|
2017-04-13 16:45:22 +00:00
|
|
|
// the namespace cleanup controller is very chatty. It makes lots of discovery calls and then it makes lots of delete calls
|
|
|
|
// the ratelimiter negatively affects its speed. Deleting 100 total items in a namespace (that's only a few of each resource
|
|
|
|
// including events), takes ~10 seconds by default.
|
|
|
|
nsKubeconfig := ctx.ClientBuilder.ConfigOrDie("namespace-controller")
|
2018-04-27 14:05:57 +00:00
|
|
|
nsKubeconfig.QPS *= 20
|
|
|
|
nsKubeconfig.Burst *= 100
|
2017-04-13 16:45:22 +00:00
|
|
|
namespaceKubeClient := clientset.NewForConfigOrDie(nsKubeconfig)
|
|
|
|
|
2018-04-24 17:41:40 +00:00
|
|
|
dynamicClient, err := dynamic.NewForConfig(nsKubeconfig)
|
|
|
|
if err != nil {
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, true, err
|
2018-04-24 17:41:40 +00:00
|
|
|
}
|
|
|
|
|
2018-04-23 07:03:33 +00:00
|
|
|
discoverResourcesFn := namespaceKubeClient.Discovery().ServerPreferredNamespacedResources
|
|
|
|
|
2017-02-17 17:34:27 +00:00
|
|
|
namespaceController := namespacecontroller.NewNamespaceController(
|
|
|
|
namespaceKubeClient,
|
2018-04-24 17:41:40 +00:00
|
|
|
dynamicClient,
|
2017-02-17 17:34:27 +00:00
|
|
|
discoverResourcesFn,
|
2017-02-24 14:52:43 +00:00
|
|
|
ctx.InformerFactory.Core().V1().Namespaces(),
|
2018-04-12 03:12:10 +00:00
|
|
|
ctx.ComponentConfig.NamespaceController.NamespaceSyncPeriod.Duration,
|
2017-02-17 17:34:27 +00:00
|
|
|
v1.FinalizerKubernetes,
|
|
|
|
)
|
2018-04-12 03:12:10 +00:00
|
|
|
go namespaceController.Run(int(ctx.ComponentConfig.NamespaceController.ConcurrentNamespaceSyncs), ctx.Stop)
|
2016-12-05 14:04:32 +00:00
|
|
|
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, true, nil
|
2016-12-05 14:04:32 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 19:45:54 +00:00
|
|
|
func startServiceAccountController(ctx ControllerContext) (http.Handler, bool, error) {
|
2017-10-31 14:19:55 +00:00
|
|
|
sac, err := serviceaccountcontroller.NewServiceAccountsController(
|
2017-02-24 14:52:43 +00:00
|
|
|
ctx.InformerFactory.Core().V1().ServiceAccounts(),
|
|
|
|
ctx.InformerFactory.Core().V1().Namespaces(),
|
2016-12-05 14:04:32 +00:00
|
|
|
ctx.ClientBuilder.ClientOrDie("service-account-controller"),
|
|
|
|
serviceaccountcontroller.DefaultServiceAccountsControllerOptions(),
|
2017-10-31 14:19:55 +00:00
|
|
|
)
|
|
|
|
if err != nil {
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, true, fmt.Errorf("error creating ServiceAccount controller: %v", err)
|
2017-10-31 14:19:55 +00:00
|
|
|
}
|
|
|
|
go sac.Run(1, ctx.Stop)
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, true, nil
|
2016-12-05 14:04:32 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 19:45:54 +00:00
|
|
|
func startTTLController(ctx ControllerContext) (http.Handler, bool, error) {
|
2017-01-30 10:48:15 +00:00
|
|
|
go ttlcontroller.NewTTLController(
|
2017-02-24 14:52:43 +00:00
|
|
|
ctx.InformerFactory.Core().V1().Nodes(),
|
2017-01-30 10:48:15 +00:00
|
|
|
ctx.ClientBuilder.ClientOrDie("ttl-controller"),
|
|
|
|
).Run(5, ctx.Stop)
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, true, nil
|
2017-01-30 10:48:15 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 19:45:54 +00:00
|
|
|
func startGarbageCollectorController(ctx ControllerContext) (http.Handler, bool, error) {
|
2018-04-12 03:12:10 +00:00
|
|
|
if !ctx.ComponentConfig.GarbageCollectorController.EnableGarbageCollector {
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, false, nil
|
2016-12-05 14:04:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gcClientset := ctx.ClientBuilder.ClientOrDie("generic-garbage-collector")
|
2017-05-17 22:54:58 +00:00
|
|
|
discoveryClient := cacheddiscovery.NewMemCacheClient(gcClientset.Discovery())
|
2016-12-05 14:04:32 +00:00
|
|
|
|
|
|
|
config := ctx.ClientBuilder.ConfigOrDie("generic-garbage-collector")
|
2018-05-04 18:40:39 +00:00
|
|
|
dynamicClient, err := dynamic.NewForConfig(config)
|
|
|
|
if err != nil {
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, true, err
|
2018-05-04 18:40:39 +00:00
|
|
|
}
|
2017-05-16 17:35:45 +00:00
|
|
|
|
2017-05-17 22:54:58 +00:00
|
|
|
// Get an initial set of deletable resources to prime the garbage collector.
|
2017-11-07 18:19:43 +00:00
|
|
|
deletableResources := garbagecollector.GetDeletableResources(discoveryClient)
|
2017-05-16 17:35:45 +00:00
|
|
|
ignoredResources := make(map[schema.GroupResource]struct{})
|
2018-04-12 03:12:10 +00:00
|
|
|
for _, r := range ctx.ComponentConfig.GarbageCollectorController.GCIgnoredResources {
|
2017-05-16 17:35:45 +00:00
|
|
|
ignoredResources[schema.GroupResource{Group: r.Group, Resource: r.Resource}] = struct{}{}
|
|
|
|
}
|
|
|
|
garbageCollector, err := garbagecollector.NewGarbageCollector(
|
2018-05-04 18:40:39 +00:00
|
|
|
dynamicClient,
|
2018-04-23 07:03:33 +00:00
|
|
|
ctx.RESTMapper,
|
2017-05-17 22:54:58 +00:00
|
|
|
deletableResources,
|
2017-05-16 17:35:45 +00:00
|
|
|
ignoredResources,
|
|
|
|
ctx.InformerFactory,
|
2017-08-24 16:39:55 +00:00
|
|
|
ctx.InformersStarted,
|
2017-05-16 17:35:45 +00:00
|
|
|
)
|
2016-12-05 14:04:32 +00:00
|
|
|
if err != nil {
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, true, fmt.Errorf("Failed to start the generic garbage collector: %v", err)
|
2016-12-05 14:04:32 +00:00
|
|
|
}
|
2017-05-17 22:54:58 +00:00
|
|
|
|
|
|
|
// Start the garbage collector.
|
2018-04-12 03:12:10 +00:00
|
|
|
workers := int(ctx.ComponentConfig.GarbageCollectorController.ConcurrentGCSyncs)
|
2016-12-05 14:04:32 +00:00
|
|
|
go garbageCollector.Run(workers, ctx.Stop)
|
|
|
|
|
2017-05-17 22:54:58 +00:00
|
|
|
// Periodically refresh the RESTMapper with new discovery information and sync
|
|
|
|
// the garbage collector.
|
2017-08-08 19:57:55 +00:00
|
|
|
go garbageCollector.Sync(gcClientset.Discovery(), 30*time.Second, ctx.Stop)
|
2017-05-17 22:54:58 +00:00
|
|
|
|
2018-07-25 19:45:54 +00:00
|
|
|
return garbagecollector.NewDebugHandler(garbageCollector), true, nil
|
2016-12-05 14:04:32 +00:00
|
|
|
}
|
2017-11-15 22:03:43 +00:00
|
|
|
|
2018-07-25 19:45:54 +00:00
|
|
|
func startPVCProtectionController(ctx ControllerContext) (http.Handler, bool, error) {
|
2018-03-18 17:06:29 +00:00
|
|
|
go pvcprotection.NewPVCProtectionController(
|
|
|
|
ctx.InformerFactory.Core().V1().PersistentVolumeClaims(),
|
|
|
|
ctx.InformerFactory.Core().V1().Pods(),
|
|
|
|
ctx.ClientBuilder.ClientOrDie("pvc-protection-controller"),
|
|
|
|
utilfeature.DefaultFeatureGate.Enabled(features.StorageObjectInUseProtection),
|
|
|
|
).Run(1, ctx.Stop)
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, true, nil
|
2017-11-15 22:03:43 +00:00
|
|
|
}
|
2018-01-24 14:28:04 +00:00
|
|
|
|
2018-07-25 19:45:54 +00:00
|
|
|
func startPVProtectionController(ctx ControllerContext) (http.Handler, bool, error) {
|
2018-03-18 17:06:29 +00:00
|
|
|
go pvprotection.NewPVProtectionController(
|
|
|
|
ctx.InformerFactory.Core().V1().PersistentVolumes(),
|
|
|
|
ctx.ClientBuilder.ClientOrDie("pv-protection-controller"),
|
|
|
|
utilfeature.DefaultFeatureGate.Enabled(features.StorageObjectInUseProtection),
|
|
|
|
).Run(1, ctx.Stop)
|
2018-07-25 19:45:54 +00:00
|
|
|
return nil, true, nil
|
2018-01-24 14:28:04 +00:00
|
|
|
}
|