controllers.go 4.6 KB
Newer Older
H
hongming 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*

 Copyright 2019 The KubeSphere 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.

*/
J
Jeff 已提交
18 19 20
package app

import (
21
	"k8s.io/klog"
J
Jeff 已提交
22
	"kubesphere.io/kubesphere/pkg/controller/application"
Z
zryfish 已提交
23
	"kubesphere.io/kubesphere/pkg/controller/cluster"
J
Jeff 已提交
24
	"kubesphere.io/kubesphere/pkg/controller/destinationrule"
J
Jeff 已提交
25
	"kubesphere.io/kubesphere/pkg/controller/job"
R
runzexia 已提交
26 27
	"kubesphere.io/kubesphere/pkg/controller/s2ibinary"
	"kubesphere.io/kubesphere/pkg/controller/s2irun"
X
Xin Wang 已提交
28
	"kubesphere.io/kubesphere/pkg/controller/storage/expansion"
H
hongming 已提交
29
	"kubesphere.io/kubesphere/pkg/controller/user"
J
Jeff 已提交
30
	"kubesphere.io/kubesphere/pkg/controller/virtualservice"
31 32
	"kubesphere.io/kubesphere/pkg/informers"
	"kubesphere.io/kubesphere/pkg/simple/client/k8s"
J
Jeff 已提交
33 34 35
	"sigs.k8s.io/controller-runtime/pkg/manager"
)

36 37 38 39 40
func AddControllers(
	mgr manager.Manager,
	client k8s.Client,
	informerFactory informers.InformerFactory,
	stopCh <-chan struct{}) error {
J
Jeff 已提交
41

42 43 44 45
	kubernetesInformer := informerFactory.KubernetesSharedInformerFactory()
	istioInformer := informerFactory.IstioSharedInformerFactory()
	kubesphereInformer := informerFactory.KubeSphereSharedInformerFactory()
	applicationInformer := informerFactory.ApplicationSharedInformerFactory()
J
Jeff 已提交
46

47
	vsController := virtualservice.NewVirtualServiceController(kubernetesInformer.Core().V1().Services(),
J
Jeff 已提交
48 49
		istioInformer.Networking().V1alpha3().VirtualServices(),
		istioInformer.Networking().V1alpha3().DestinationRules(),
R
runzexia 已提交
50
		kubesphereInformer.Servicemesh().V1alpha2().Strategies(),
51 52 53
		client.Kubernetes(),
		client.Istio(),
		client.KubeSphere())
J
Jeff 已提交
54

55
	drController := destinationrule.NewDestinationRuleController(kubernetesInformer.Apps().V1().Deployments(),
J
Jeff 已提交
56
		istioInformer.Networking().V1alpha3().DestinationRules(),
57
		kubernetesInformer.Core().V1().Services(),
R
runzexia 已提交
58
		kubesphereInformer.Servicemesh().V1alpha2().ServicePolicies(),
59 60 61
		client.Kubernetes(),
		client.Istio(),
		client.KubeSphere())
J
Jeff 已提交
62

63 64 65
	apController := application.NewApplicationController(kubernetesInformer.Core().V1().Services(),
		kubernetesInformer.Apps().V1().Deployments(),
		kubernetesInformer.Apps().V1().StatefulSets(),
R
runzexia 已提交
66 67
		kubesphereInformer.Servicemesh().V1alpha2().Strategies(),
		kubesphereInformer.Servicemesh().V1alpha2().ServicePolicies(),
J
Jeff 已提交
68
		applicationInformer.App().V1beta1().Applications(),
69 70
		client.Kubernetes(),
		client.Application())
J
Jeff 已提交
71

72
	jobController := job.NewJobController(kubernetesInformer.Batch().V1().Jobs(), client.Kubernetes())
H
hongming 已提交
73

74 75
	s2iBinaryController := s2ibinary.NewController(client.KubeSphere(),
		client.Kubernetes(),
76
		kubesphereInformer.Devops().V1alpha1().S2iBinaries())
R
runzexia 已提交
77

78 79
	s2iRunController := s2irun.NewS2iRunController(client.KubeSphere(),
		client.Kubernetes(),
R
runzexia 已提交
80
		kubesphereInformer.Devops().V1alpha1().S2iBinaries(),
81
		kubesphereInformer.Devops().V1alpha1().S2iRuns())
R
runzexia 已提交
82

X
Xin Wang 已提交
83
	volumeExpansionController := expansion.NewVolumeExpansionController(
84 85 86 87 88 89 90
		client.Kubernetes(),
		kubernetesInformer.Core().V1().PersistentVolumeClaims(),
		kubernetesInformer.Storage().V1().StorageClasses(),
		kubernetesInformer.Core().V1().Pods(),
		kubernetesInformer.Apps().V1().Deployments(),
		kubernetesInformer.Apps().V1().ReplicaSets(),
		kubernetesInformer.Apps().V1().StatefulSets())
J
Jeff 已提交
91

H
hongming 已提交
92 93 94 95 96
	userController := user.NewController(
		client.Kubernetes(),
		client.KubeSphere(),
		kubesphereInformer.Iam().V1alpha2().Users())

Z
zryfish 已提交
97 98 99 100 101 102 103
	clusterController := cluster.NewClusterController(
		client.Kubernetes(),
		kubesphereInformer.Cluster().V1alpha1().Clusters(),
		kubesphereInformer.Cluster().V1alpha1().Agents(),
		client.KubeSphere().ClusterV1alpha1().Agents(),
		client.KubeSphere().ClusterV1alpha1().Clusters())

J
Jeff 已提交
104 105 106
	controllers := map[string]manager.Runnable{
		"virtualservice-controller":  vsController,
		"destinationrule-controller": drController,
J
Jeff 已提交
107
		"application-controller":     apController,
J
Jeff 已提交
108
		"job-controller":             jobController,
R
runzexia 已提交
109 110
		"s2ibinary-controller":       s2iBinaryController,
		"s2irun-controller":          s2iRunController,
X
Xin Wang 已提交
111
		"volumeexpansion-controller": volumeExpansionController,
H
hongming 已提交
112
		"user-controller":            userController,
Z
zryfish 已提交
113
		"cluster-controller":         clusterController,
J
Jeff 已提交
114 115 116
	}

	for name, ctrl := range controllers {
117 118
		if err := mgr.Add(ctrl); err != nil {
			klog.Error(err, "add controller to manager failed", "name", name)
J
Jeff 已提交
119 120 121 122 123 124
			return err
		}
	}

	return nil
}