apps.go 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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/http"
  21. "time"
  22. "k8s.io/apimachinery/pkg/runtime/schema"
  23. "k8s.io/client-go/util/flowcontrol"
  24. "k8s.io/kubernetes/pkg/controller/daemon"
  25. "k8s.io/kubernetes/pkg/controller/deployment"
  26. "k8s.io/kubernetes/pkg/controller/replicaset"
  27. "k8s.io/kubernetes/pkg/controller/statefulset"
  28. )
  29. func startDaemonSetController(ctx ControllerContext) (http.Handler, bool, error) {
  30. if !ctx.AvailableResources[schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "daemonsets"}] {
  31. return nil, false, nil
  32. }
  33. dsc, err := daemon.NewDaemonSetsController(
  34. ctx.InformerFactory.Apps().V1().DaemonSets(),
  35. ctx.InformerFactory.Apps().V1().ControllerRevisions(),
  36. ctx.InformerFactory.Core().V1().Pods(),
  37. ctx.InformerFactory.Core().V1().Nodes(),
  38. ctx.ClientBuilder.ClientOrDie("daemon-set-controller"),
  39. flowcontrol.NewBackOff(1*time.Second, 15*time.Minute),
  40. )
  41. if err != nil {
  42. return nil, true, fmt.Errorf("error creating DaemonSets controller: %v", err)
  43. }
  44. go dsc.Run(int(ctx.ComponentConfig.DaemonSetController.ConcurrentDaemonSetSyncs), ctx.Stop)
  45. return nil, true, nil
  46. }
  47. func startStatefulSetController(ctx ControllerContext) (http.Handler, bool, error) {
  48. if !ctx.AvailableResources[schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "statefulsets"}] {
  49. return nil, false, nil
  50. }
  51. go statefulset.NewStatefulSetController(
  52. ctx.InformerFactory.Core().V1().Pods(),
  53. ctx.InformerFactory.Apps().V1().StatefulSets(),
  54. ctx.InformerFactory.Core().V1().PersistentVolumeClaims(),
  55. ctx.InformerFactory.Apps().V1().ControllerRevisions(),
  56. ctx.ClientBuilder.ClientOrDie("statefulset-controller"),
  57. ).Run(1, ctx.Stop)
  58. return nil, true, nil
  59. }
  60. func startReplicaSetController(ctx ControllerContext) (http.Handler, bool, error) {
  61. if !ctx.AvailableResources[schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "replicasets"}] {
  62. return nil, false, nil
  63. }
  64. go replicaset.NewReplicaSetController(
  65. ctx.InformerFactory.Apps().V1().ReplicaSets(),
  66. ctx.InformerFactory.Core().V1().Pods(),
  67. ctx.ClientBuilder.ClientOrDie("replicaset-controller"),
  68. replicaset.BurstReplicas,
  69. ).Run(int(ctx.ComponentConfig.ReplicaSetController.ConcurrentRSSyncs), ctx.Stop)
  70. return nil, true, nil
  71. }
  72. func startDeploymentController(ctx ControllerContext) (http.Handler, bool, error) {
  73. if !ctx.AvailableResources[schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "deployments"}] {
  74. return nil, false, nil
  75. }
  76. dc, err := deployment.NewDeploymentController(
  77. ctx.InformerFactory.Apps().V1().Deployments(),
  78. ctx.InformerFactory.Apps().V1().ReplicaSets(),
  79. ctx.InformerFactory.Core().V1().Pods(),
  80. ctx.ClientBuilder.ClientOrDie("deployment-controller"),
  81. )
  82. if err != nil {
  83. return nil, true, fmt.Errorf("error creating Deployment controller: %v", err)
  84. }
  85. go dc.Run(int(ctx.ComponentConfig.DeploymentController.ConcurrentDeploymentSyncs), ctx.Stop)
  86. return nil, true, nil
  87. }