core.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. /*
  2. Copyright 2016 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. // Package app implements a server that runs a set of active
  14. // components. This includes replication controllers, service endpoints and
  15. // nodes.
  16. //
  17. package app
  18. import (
  19. "fmt"
  20. "net"
  21. "net/http"
  22. "strings"
  23. "time"
  24. "k8s.io/klog"
  25. "k8s.io/api/core/v1"
  26. "k8s.io/apimachinery/pkg/runtime/schema"
  27. utilfeature "k8s.io/apiserver/pkg/util/feature"
  28. cacheddiscovery "k8s.io/client-go/discovery/cached/memory"
  29. "k8s.io/client-go/dynamic"
  30. clientset "k8s.io/client-go/kubernetes"
  31. restclient "k8s.io/client-go/rest"
  32. "k8s.io/kubernetes/pkg/controller"
  33. cloudcontroller "k8s.io/kubernetes/pkg/controller/cloud"
  34. endpointcontroller "k8s.io/kubernetes/pkg/controller/endpoint"
  35. "k8s.io/kubernetes/pkg/controller/garbagecollector"
  36. namespacecontroller "k8s.io/kubernetes/pkg/controller/namespace"
  37. nodeipamcontroller "k8s.io/kubernetes/pkg/controller/nodeipam"
  38. "k8s.io/kubernetes/pkg/controller/nodeipam/ipam"
  39. lifecyclecontroller "k8s.io/kubernetes/pkg/controller/nodelifecycle"
  40. "k8s.io/kubernetes/pkg/controller/podgc"
  41. replicationcontroller "k8s.io/kubernetes/pkg/controller/replication"
  42. resourcequotacontroller "k8s.io/kubernetes/pkg/controller/resourcequota"
  43. routecontroller "k8s.io/kubernetes/pkg/controller/route"
  44. servicecontroller "k8s.io/kubernetes/pkg/controller/service"
  45. serviceaccountcontroller "k8s.io/kubernetes/pkg/controller/serviceaccount"
  46. ttlcontroller "k8s.io/kubernetes/pkg/controller/ttl"
  47. "k8s.io/kubernetes/pkg/controller/ttlafterfinished"
  48. "k8s.io/kubernetes/pkg/controller/volume/attachdetach"
  49. "k8s.io/kubernetes/pkg/controller/volume/expand"
  50. persistentvolumecontroller "k8s.io/kubernetes/pkg/controller/volume/persistentvolume"
  51. "k8s.io/kubernetes/pkg/controller/volume/pvcprotection"
  52. "k8s.io/kubernetes/pkg/controller/volume/pvprotection"
  53. "k8s.io/kubernetes/pkg/features"
  54. "k8s.io/kubernetes/pkg/quota/v1/generic"
  55. quotainstall "k8s.io/kubernetes/pkg/quota/v1/install"
  56. "k8s.io/kubernetes/pkg/util/metrics"
  57. )
  58. func startServiceController(ctx ControllerContext) (http.Handler, bool, error) {
  59. serviceController, err := servicecontroller.New(
  60. ctx.Cloud,
  61. ctx.ClientBuilder.ClientOrDie("service-controller"),
  62. ctx.InformerFactory.Core().V1().Services(),
  63. ctx.InformerFactory.Core().V1().Nodes(),
  64. ctx.ComponentConfig.KubeCloudShared.ClusterName,
  65. )
  66. if err != nil {
  67. // This error shouldn't fail. It lives like this as a legacy.
  68. klog.Errorf("Failed to start service controller: %v", err)
  69. return nil, false, nil
  70. }
  71. go serviceController.Run(ctx.Stop, int(ctx.ComponentConfig.ServiceController.ConcurrentServiceSyncs))
  72. return nil, true, nil
  73. }
  74. func startNodeIpamController(ctx ControllerContext) (http.Handler, bool, error) {
  75. var clusterCIDR *net.IPNet
  76. var serviceCIDR *net.IPNet
  77. if !ctx.ComponentConfig.KubeCloudShared.AllocateNodeCIDRs {
  78. return nil, false, nil
  79. }
  80. var err error
  81. if len(strings.TrimSpace(ctx.ComponentConfig.KubeCloudShared.ClusterCIDR)) != 0 {
  82. _, clusterCIDR, err = net.ParseCIDR(ctx.ComponentConfig.KubeCloudShared.ClusterCIDR)
  83. if err != nil {
  84. klog.Warningf("Unsuccessful parsing of cluster CIDR %v: %v", ctx.ComponentConfig.KubeCloudShared.ClusterCIDR, err)
  85. }
  86. }
  87. if len(strings.TrimSpace(ctx.ComponentConfig.NodeIPAMController.ServiceCIDR)) != 0 {
  88. _, serviceCIDR, err = net.ParseCIDR(ctx.ComponentConfig.NodeIPAMController.ServiceCIDR)
  89. if err != nil {
  90. klog.Warningf("Unsuccessful parsing of service CIDR %v: %v", ctx.ComponentConfig.NodeIPAMController.ServiceCIDR, err)
  91. }
  92. }
  93. nodeIpamController, err := nodeipamcontroller.NewNodeIpamController(
  94. ctx.InformerFactory.Core().V1().Nodes(),
  95. ctx.Cloud,
  96. ctx.ClientBuilder.ClientOrDie("node-controller"),
  97. clusterCIDR,
  98. serviceCIDR,
  99. int(ctx.ComponentConfig.NodeIPAMController.NodeCIDRMaskSize),
  100. ipam.CIDRAllocatorType(ctx.ComponentConfig.KubeCloudShared.CIDRAllocatorType),
  101. )
  102. if err != nil {
  103. return nil, true, err
  104. }
  105. go nodeIpamController.Run(ctx.Stop)
  106. return nil, true, nil
  107. }
  108. func startNodeLifecycleController(ctx ControllerContext) (http.Handler, bool, error) {
  109. lifecycleController, err := lifecyclecontroller.NewNodeLifecycleController(
  110. ctx.InformerFactory.Coordination().V1beta1().Leases(),
  111. ctx.InformerFactory.Core().V1().Pods(),
  112. ctx.InformerFactory.Core().V1().Nodes(),
  113. ctx.InformerFactory.Apps().V1().DaemonSets(),
  114. // node lifecycle controller uses existing cluster role from node-controller
  115. ctx.ClientBuilder.ClientOrDie("node-controller"),
  116. ctx.ComponentConfig.KubeCloudShared.NodeMonitorPeriod.Duration,
  117. ctx.ComponentConfig.NodeLifecycleController.NodeStartupGracePeriod.Duration,
  118. ctx.ComponentConfig.NodeLifecycleController.NodeMonitorGracePeriod.Duration,
  119. ctx.ComponentConfig.NodeLifecycleController.PodEvictionTimeout.Duration,
  120. ctx.ComponentConfig.NodeLifecycleController.NodeEvictionRate,
  121. ctx.ComponentConfig.NodeLifecycleController.SecondaryNodeEvictionRate,
  122. ctx.ComponentConfig.NodeLifecycleController.LargeClusterSizeThreshold,
  123. ctx.ComponentConfig.NodeLifecycleController.UnhealthyZoneThreshold,
  124. ctx.ComponentConfig.NodeLifecycleController.EnableTaintManager,
  125. utilfeature.DefaultFeatureGate.Enabled(features.TaintBasedEvictions),
  126. utilfeature.DefaultFeatureGate.Enabled(features.TaintNodesByCondition),
  127. )
  128. if err != nil {
  129. return nil, true, err
  130. }
  131. go lifecycleController.Run(ctx.Stop)
  132. return nil, true, nil
  133. }
  134. func startCloudNodeLifecycleController(ctx ControllerContext) (http.Handler, bool, error) {
  135. cloudNodeLifecycleController, err := cloudcontroller.NewCloudNodeLifecycleController(
  136. ctx.InformerFactory.Core().V1().Nodes(),
  137. // cloud node lifecycle controller uses existing cluster role from node-controller
  138. ctx.ClientBuilder.ClientOrDie("node-controller"),
  139. ctx.Cloud,
  140. ctx.ComponentConfig.KubeCloudShared.NodeMonitorPeriod.Duration,
  141. )
  142. if err != nil {
  143. // the controller manager should continue to run if the "Instances" interface is not
  144. // supported, though it's unlikely for a cloud provider to not support it
  145. klog.Errorf("failed to start cloud node lifecycle controller: %v", err)
  146. return nil, false, nil
  147. }
  148. go cloudNodeLifecycleController.Run(ctx.Stop)
  149. return nil, true, nil
  150. }
  151. func startRouteController(ctx ControllerContext) (http.Handler, bool, error) {
  152. if !ctx.ComponentConfig.KubeCloudShared.AllocateNodeCIDRs || !ctx.ComponentConfig.KubeCloudShared.ConfigureCloudRoutes {
  153. klog.Infof("Will not configure cloud provider routes for allocate-node-cidrs: %v, configure-cloud-routes: %v.", ctx.ComponentConfig.KubeCloudShared.AllocateNodeCIDRs, ctx.ComponentConfig.KubeCloudShared.ConfigureCloudRoutes)
  154. return nil, false, nil
  155. }
  156. if ctx.Cloud == nil {
  157. klog.Warning("configure-cloud-routes is set, but no cloud provider specified. Will not configure cloud provider routes.")
  158. return nil, false, nil
  159. }
  160. routes, ok := ctx.Cloud.Routes()
  161. if !ok {
  162. klog.Warning("configure-cloud-routes is set, but cloud provider does not support routes. Will not configure cloud provider routes.")
  163. return nil, false, nil
  164. }
  165. _, clusterCIDR, err := net.ParseCIDR(ctx.ComponentConfig.KubeCloudShared.ClusterCIDR)
  166. if err != nil {
  167. klog.Warningf("Unsuccessful parsing of cluster CIDR %v: %v", ctx.ComponentConfig.KubeCloudShared.ClusterCIDR, err)
  168. }
  169. routeController := routecontroller.New(routes, ctx.ClientBuilder.ClientOrDie("route-controller"), ctx.InformerFactory.Core().V1().Nodes(), ctx.ComponentConfig.KubeCloudShared.ClusterName, clusterCIDR)
  170. go routeController.Run(ctx.Stop, ctx.ComponentConfig.KubeCloudShared.RouteReconciliationPeriod.Duration)
  171. return nil, true, nil
  172. }
  173. func startPersistentVolumeBinderController(ctx ControllerContext) (http.Handler, bool, error) {
  174. params := persistentvolumecontroller.ControllerParameters{
  175. KubeClient: ctx.ClientBuilder.ClientOrDie("persistent-volume-binder"),
  176. SyncPeriod: ctx.ComponentConfig.PersistentVolumeBinderController.PVClaimBinderSyncPeriod.Duration,
  177. VolumePlugins: ProbeControllerVolumePlugins(ctx.Cloud, ctx.ComponentConfig.PersistentVolumeBinderController.VolumeConfiguration),
  178. Cloud: ctx.Cloud,
  179. ClusterName: ctx.ComponentConfig.KubeCloudShared.ClusterName,
  180. VolumeInformer: ctx.InformerFactory.Core().V1().PersistentVolumes(),
  181. ClaimInformer: ctx.InformerFactory.Core().V1().PersistentVolumeClaims(),
  182. ClassInformer: ctx.InformerFactory.Storage().V1().StorageClasses(),
  183. PodInformer: ctx.InformerFactory.Core().V1().Pods(),
  184. NodeInformer: ctx.InformerFactory.Core().V1().Nodes(),
  185. EnableDynamicProvisioning: ctx.ComponentConfig.PersistentVolumeBinderController.VolumeConfiguration.EnableDynamicProvisioning,
  186. }
  187. volumeController, volumeControllerErr := persistentvolumecontroller.NewController(params)
  188. if volumeControllerErr != nil {
  189. return nil, true, fmt.Errorf("failed to construct persistentvolume controller: %v", volumeControllerErr)
  190. }
  191. go volumeController.Run(ctx.Stop)
  192. return nil, true, nil
  193. }
  194. func startAttachDetachController(ctx ControllerContext) (http.Handler, bool, error) {
  195. if ctx.ComponentConfig.AttachDetachController.ReconcilerSyncLoopPeriod.Duration < time.Second {
  196. return nil, true, fmt.Errorf("duration time must be greater than one second as set via command line option reconcile-sync-loop-period")
  197. }
  198. attachDetachController, attachDetachControllerErr :=
  199. attachdetach.NewAttachDetachController(
  200. ctx.ClientBuilder.ClientOrDie("attachdetach-controller"),
  201. ctx.InformerFactory.Core().V1().Pods(),
  202. ctx.InformerFactory.Core().V1().Nodes(),
  203. ctx.InformerFactory.Core().V1().PersistentVolumeClaims(),
  204. ctx.InformerFactory.Core().V1().PersistentVolumes(),
  205. ctx.InformerFactory.Storage().V1beta1().CSINodes(),
  206. ctx.InformerFactory.Storage().V1beta1().CSIDrivers(),
  207. ctx.Cloud,
  208. ProbeAttachableVolumePlugins(),
  209. GetDynamicPluginProber(ctx.ComponentConfig.PersistentVolumeBinderController.VolumeConfiguration),
  210. ctx.ComponentConfig.AttachDetachController.DisableAttachDetachReconcilerSync,
  211. ctx.ComponentConfig.AttachDetachController.ReconcilerSyncLoopPeriod.Duration,
  212. attachdetach.DefaultTimerConfig,
  213. )
  214. if attachDetachControllerErr != nil {
  215. return nil, true, fmt.Errorf("failed to start attach/detach controller: %v", attachDetachControllerErr)
  216. }
  217. go attachDetachController.Run(ctx.Stop)
  218. return nil, true, nil
  219. }
  220. func startVolumeExpandController(ctx ControllerContext) (http.Handler, bool, error) {
  221. if utilfeature.DefaultFeatureGate.Enabled(features.ExpandPersistentVolumes) {
  222. expandController, expandControllerErr := expand.NewExpandController(
  223. ctx.ClientBuilder.ClientOrDie("expand-controller"),
  224. ctx.InformerFactory.Core().V1().PersistentVolumeClaims(),
  225. ctx.InformerFactory.Core().V1().PersistentVolumes(),
  226. ctx.InformerFactory.Storage().V1().StorageClasses(),
  227. ctx.Cloud,
  228. ProbeExpandableVolumePlugins(ctx.ComponentConfig.PersistentVolumeBinderController.VolumeConfiguration))
  229. if expandControllerErr != nil {
  230. return nil, true, fmt.Errorf("failed to start volume expand controller : %v", expandControllerErr)
  231. }
  232. go expandController.Run(ctx.Stop)
  233. return nil, true, nil
  234. }
  235. return nil, false, nil
  236. }
  237. func startEndpointController(ctx ControllerContext) (http.Handler, bool, error) {
  238. go endpointcontroller.NewEndpointController(
  239. ctx.InformerFactory.Core().V1().Pods(),
  240. ctx.InformerFactory.Core().V1().Services(),
  241. ctx.InformerFactory.Core().V1().Endpoints(),
  242. ctx.ClientBuilder.ClientOrDie("endpoint-controller"),
  243. ).Run(int(ctx.ComponentConfig.EndpointController.ConcurrentEndpointSyncs), ctx.Stop)
  244. return nil, true, nil
  245. }
  246. func startReplicationController(ctx ControllerContext) (http.Handler, bool, error) {
  247. go replicationcontroller.NewReplicationManager(
  248. ctx.InformerFactory.Core().V1().Pods(),
  249. ctx.InformerFactory.Core().V1().ReplicationControllers(),
  250. ctx.ClientBuilder.ClientOrDie("replication-controller"),
  251. replicationcontroller.BurstReplicas,
  252. ).Run(int(ctx.ComponentConfig.ReplicationController.ConcurrentRCSyncs), ctx.Stop)
  253. return nil, true, nil
  254. }
  255. func startPodGCController(ctx ControllerContext) (http.Handler, bool, error) {
  256. go podgc.NewPodGC(
  257. ctx.ClientBuilder.ClientOrDie("pod-garbage-collector"),
  258. ctx.InformerFactory.Core().V1().Pods(),
  259. int(ctx.ComponentConfig.PodGCController.TerminatedPodGCThreshold),
  260. ).Run(ctx.Stop)
  261. return nil, true, nil
  262. }
  263. func startResourceQuotaController(ctx ControllerContext) (http.Handler, bool, error) {
  264. resourceQuotaControllerClient := ctx.ClientBuilder.ClientOrDie("resourcequota-controller")
  265. discoveryFunc := resourceQuotaControllerClient.Discovery().ServerPreferredNamespacedResources
  266. listerFuncForResource := generic.ListerFuncForResourceFunc(ctx.InformerFactory.ForResource)
  267. quotaConfiguration := quotainstall.NewQuotaConfigurationForControllers(listerFuncForResource)
  268. resourceQuotaControllerOptions := &resourcequotacontroller.ResourceQuotaControllerOptions{
  269. QuotaClient: resourceQuotaControllerClient.CoreV1(),
  270. ResourceQuotaInformer: ctx.InformerFactory.Core().V1().ResourceQuotas(),
  271. ResyncPeriod: controller.StaticResyncPeriodFunc(ctx.ComponentConfig.ResourceQuotaController.ResourceQuotaSyncPeriod.Duration),
  272. InformerFactory: ctx.GenericInformerFactory,
  273. ReplenishmentResyncPeriod: ctx.ResyncPeriod,
  274. DiscoveryFunc: discoveryFunc,
  275. IgnoredResourcesFunc: quotaConfiguration.IgnoredResources,
  276. InformersStarted: ctx.InformersStarted,
  277. Registry: generic.NewRegistry(quotaConfiguration.Evaluators()),
  278. }
  279. if resourceQuotaControllerClient.CoreV1().RESTClient().GetRateLimiter() != nil {
  280. if err := metrics.RegisterMetricAndTrackRateLimiterUsage("resource_quota_controller", resourceQuotaControllerClient.CoreV1().RESTClient().GetRateLimiter()); err != nil {
  281. return nil, true, err
  282. }
  283. }
  284. resourceQuotaController, err := resourcequotacontroller.NewResourceQuotaController(resourceQuotaControllerOptions)
  285. if err != nil {
  286. return nil, false, err
  287. }
  288. go resourceQuotaController.Run(int(ctx.ComponentConfig.ResourceQuotaController.ConcurrentResourceQuotaSyncs), ctx.Stop)
  289. // Periodically the quota controller to detect new resource types
  290. go resourceQuotaController.Sync(discoveryFunc, 30*time.Second, ctx.Stop)
  291. return nil, true, nil
  292. }
  293. func startNamespaceController(ctx ControllerContext) (http.Handler, bool, error) {
  294. // the namespace cleanup controller is very chatty. It makes lots of discovery calls and then it makes lots of delete calls
  295. // the ratelimiter negatively affects its speed. Deleting 100 total items in a namespace (that's only a few of each resource
  296. // including events), takes ~10 seconds by default.
  297. nsKubeconfig := ctx.ClientBuilder.ConfigOrDie("namespace-controller")
  298. nsKubeconfig.QPS *= 20
  299. nsKubeconfig.Burst *= 100
  300. namespaceKubeClient := clientset.NewForConfigOrDie(nsKubeconfig)
  301. return startModifiedNamespaceController(ctx, namespaceKubeClient, nsKubeconfig)
  302. }
  303. func startModifiedNamespaceController(ctx ControllerContext, namespaceKubeClient clientset.Interface, nsKubeconfig *restclient.Config) (http.Handler, bool, error) {
  304. dynamicClient, err := dynamic.NewForConfig(nsKubeconfig)
  305. if err != nil {
  306. return nil, true, err
  307. }
  308. discoverResourcesFn := namespaceKubeClient.Discovery().ServerPreferredNamespacedResources
  309. namespaceController := namespacecontroller.NewNamespaceController(
  310. namespaceKubeClient,
  311. dynamicClient,
  312. discoverResourcesFn,
  313. ctx.InformerFactory.Core().V1().Namespaces(),
  314. ctx.ComponentConfig.NamespaceController.NamespaceSyncPeriod.Duration,
  315. v1.FinalizerKubernetes,
  316. )
  317. go namespaceController.Run(int(ctx.ComponentConfig.NamespaceController.ConcurrentNamespaceSyncs), ctx.Stop)
  318. return nil, true, nil
  319. }
  320. func startServiceAccountController(ctx ControllerContext) (http.Handler, bool, error) {
  321. sac, err := serviceaccountcontroller.NewServiceAccountsController(
  322. ctx.InformerFactory.Core().V1().ServiceAccounts(),
  323. ctx.InformerFactory.Core().V1().Namespaces(),
  324. ctx.ClientBuilder.ClientOrDie("service-account-controller"),
  325. serviceaccountcontroller.DefaultServiceAccountsControllerOptions(),
  326. )
  327. if err != nil {
  328. return nil, true, fmt.Errorf("error creating ServiceAccount controller: %v", err)
  329. }
  330. go sac.Run(1, ctx.Stop)
  331. return nil, true, nil
  332. }
  333. func startTTLController(ctx ControllerContext) (http.Handler, bool, error) {
  334. go ttlcontroller.NewTTLController(
  335. ctx.InformerFactory.Core().V1().Nodes(),
  336. ctx.ClientBuilder.ClientOrDie("ttl-controller"),
  337. ).Run(5, ctx.Stop)
  338. return nil, true, nil
  339. }
  340. func startGarbageCollectorController(ctx ControllerContext) (http.Handler, bool, error) {
  341. if !ctx.ComponentConfig.GarbageCollectorController.EnableGarbageCollector {
  342. return nil, false, nil
  343. }
  344. gcClientset := ctx.ClientBuilder.ClientOrDie("generic-garbage-collector")
  345. discoveryClient := cacheddiscovery.NewMemCacheClient(gcClientset.Discovery())
  346. config := ctx.ClientBuilder.ConfigOrDie("generic-garbage-collector")
  347. dynamicClient, err := dynamic.NewForConfig(config)
  348. if err != nil {
  349. return nil, true, err
  350. }
  351. // Get an initial set of deletable resources to prime the garbage collector.
  352. deletableResources := garbagecollector.GetDeletableResources(discoveryClient)
  353. ignoredResources := make(map[schema.GroupResource]struct{})
  354. for _, r := range ctx.ComponentConfig.GarbageCollectorController.GCIgnoredResources {
  355. ignoredResources[schema.GroupResource{Group: r.Group, Resource: r.Resource}] = struct{}{}
  356. }
  357. garbageCollector, err := garbagecollector.NewGarbageCollector(
  358. dynamicClient,
  359. ctx.RESTMapper,
  360. deletableResources,
  361. ignoredResources,
  362. ctx.GenericInformerFactory,
  363. ctx.InformersStarted,
  364. )
  365. if err != nil {
  366. return nil, true, fmt.Errorf("failed to start the generic garbage collector: %v", err)
  367. }
  368. // Start the garbage collector.
  369. workers := int(ctx.ComponentConfig.GarbageCollectorController.ConcurrentGCSyncs)
  370. go garbageCollector.Run(workers, ctx.Stop)
  371. // Periodically refresh the RESTMapper with new discovery information and sync
  372. // the garbage collector.
  373. go garbageCollector.Sync(gcClientset.Discovery(), 30*time.Second, ctx.Stop)
  374. return garbagecollector.NewDebugHandler(garbageCollector), true, nil
  375. }
  376. func startPVCProtectionController(ctx ControllerContext) (http.Handler, bool, error) {
  377. go pvcprotection.NewPVCProtectionController(
  378. ctx.InformerFactory.Core().V1().PersistentVolumeClaims(),
  379. ctx.InformerFactory.Core().V1().Pods(),
  380. ctx.ClientBuilder.ClientOrDie("pvc-protection-controller"),
  381. utilfeature.DefaultFeatureGate.Enabled(features.StorageObjectInUseProtection),
  382. ).Run(1, ctx.Stop)
  383. return nil, true, nil
  384. }
  385. func startPVProtectionController(ctx ControllerContext) (http.Handler, bool, error) {
  386. go pvprotection.NewPVProtectionController(
  387. ctx.InformerFactory.Core().V1().PersistentVolumes(),
  388. ctx.ClientBuilder.ClientOrDie("pv-protection-controller"),
  389. utilfeature.DefaultFeatureGate.Enabled(features.StorageObjectInUseProtection),
  390. ).Run(1, ctx.Stop)
  391. return nil, true, nil
  392. }
  393. func startTTLAfterFinishedController(ctx ControllerContext) (http.Handler, bool, error) {
  394. if !utilfeature.DefaultFeatureGate.Enabled(features.TTLAfterFinished) {
  395. return nil, false, nil
  396. }
  397. go ttlafterfinished.New(
  398. ctx.InformerFactory.Batch().V1().Jobs(),
  399. ctx.ClientBuilder.ClientOrDie("ttl-after-finished-controller"),
  400. ).Run(int(ctx.ComponentConfig.TTLAfterFinishedController.ConcurrentTTLSyncs), ctx.Stop)
  401. return nil, true, nil
  402. }