ceph-csi/vendor/k8s.io/kubernetes/cmd/kube-controller-manager/app/apps.go

98 lines
3.6 KiB
Go
Raw Normal View History

2018-01-09 18:57:14 +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 (
2018-03-06 22:33:18 +00:00
"fmt"
2018-11-26 18:23:56 +00:00
"net/http"
"time"
2018-03-06 22:33:18 +00:00
2018-01-09 18:57:14 +00:00
"k8s.io/apimachinery/pkg/runtime/schema"
2018-11-26 18:23:56 +00:00
"k8s.io/client-go/util/flowcontrol"
2018-03-06 22:33:18 +00:00
"k8s.io/kubernetes/pkg/controller/daemon"
2018-07-18 14:47:22 +00:00
"k8s.io/kubernetes/pkg/controller/deployment"
"k8s.io/kubernetes/pkg/controller/replicaset"
2018-01-09 18:57:14 +00:00
"k8s.io/kubernetes/pkg/controller/statefulset"
)
2018-11-26 18:23:56 +00:00
func startDaemonSetController(ctx ControllerContext) (http.Handler, bool, error) {
2018-03-06 22:33:18 +00:00
if !ctx.AvailableResources[schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "daemonsets"}] {
2018-11-26 18:23:56 +00:00
return nil, false, nil
2018-03-06 22:33:18 +00:00
}
dsc, err := daemon.NewDaemonSetsController(
ctx.InformerFactory.Apps().V1().DaemonSets(),
ctx.InformerFactory.Apps().V1().ControllerRevisions(),
ctx.InformerFactory.Core().V1().Pods(),
ctx.InformerFactory.Core().V1().Nodes(),
ctx.ClientBuilder.ClientOrDie("daemon-set-controller"),
2018-11-26 18:23:56 +00:00
flowcontrol.NewBackOff(1*time.Second, 15*time.Minute),
2018-03-06 22:33:18 +00:00
)
if err != nil {
2018-11-26 18:23:56 +00:00
return nil, true, fmt.Errorf("error creating DaemonSets controller: %v", err)
2018-03-06 22:33:18 +00:00
}
2018-07-18 14:47:22 +00:00
go dsc.Run(int(ctx.ComponentConfig.DaemonSetController.ConcurrentDaemonSetSyncs), ctx.Stop)
2018-11-26 18:23:56 +00:00
return nil, true, nil
2018-03-06 22:33:18 +00:00
}
2018-11-26 18:23:56 +00:00
func startStatefulSetController(ctx ControllerContext) (http.Handler, bool, error) {
2018-07-18 14:47:22 +00:00
if !ctx.AvailableResources[schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "statefulsets"}] {
2018-11-26 18:23:56 +00:00
return nil, false, nil
2018-01-09 18:57:14 +00:00
}
go statefulset.NewStatefulSetController(
ctx.InformerFactory.Core().V1().Pods(),
2018-03-06 22:33:18 +00:00
ctx.InformerFactory.Apps().V1().StatefulSets(),
2018-01-09 18:57:14 +00:00
ctx.InformerFactory.Core().V1().PersistentVolumeClaims(),
2018-03-06 22:33:18 +00:00
ctx.InformerFactory.Apps().V1().ControllerRevisions(),
2018-01-09 18:57:14 +00:00
ctx.ClientBuilder.ClientOrDie("statefulset-controller"),
).Run(1, ctx.Stop)
2018-11-26 18:23:56 +00:00
return nil, true, nil
2018-01-09 18:57:14 +00:00
}
2018-07-18 14:47:22 +00:00
2018-11-26 18:23:56 +00:00
func startReplicaSetController(ctx ControllerContext) (http.Handler, bool, error) {
2018-07-18 14:47:22 +00:00
if !ctx.AvailableResources[schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "replicasets"}] {
2018-11-26 18:23:56 +00:00
return nil, false, nil
2018-07-18 14:47:22 +00:00
}
go replicaset.NewReplicaSetController(
ctx.InformerFactory.Apps().V1().ReplicaSets(),
ctx.InformerFactory.Core().V1().Pods(),
ctx.ClientBuilder.ClientOrDie("replicaset-controller"),
replicaset.BurstReplicas,
).Run(int(ctx.ComponentConfig.ReplicaSetController.ConcurrentRSSyncs), ctx.Stop)
2018-11-26 18:23:56 +00:00
return nil, true, nil
2018-07-18 14:47:22 +00:00
}
2018-11-26 18:23:56 +00:00
func startDeploymentController(ctx ControllerContext) (http.Handler, bool, error) {
2018-07-18 14:47:22 +00:00
if !ctx.AvailableResources[schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "deployments"}] {
2018-11-26 18:23:56 +00:00
return nil, false, nil
2018-07-18 14:47:22 +00:00
}
dc, err := deployment.NewDeploymentController(
ctx.InformerFactory.Apps().V1().Deployments(),
ctx.InformerFactory.Apps().V1().ReplicaSets(),
ctx.InformerFactory.Core().V1().Pods(),
ctx.ClientBuilder.ClientOrDie("deployment-controller"),
)
if err != nil {
2018-11-26 18:23:56 +00:00
return nil, true, fmt.Errorf("error creating Deployment controller: %v", err)
2018-07-18 14:47:22 +00:00
}
go dc.Run(int(ctx.ComponentConfig.DeploymentController.ConcurrentDeploymentSyncs), ctx.Stop)
2018-11-26 18:23:56 +00:00
return nil, true, nil
2018-07-18 14:47:22 +00:00
}