controllers.go 4.2 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"
J
Jeff 已提交
23
	"kubesphere.io/kubesphere/pkg/controller/destinationrule"
J
Jeff 已提交
24
	"kubesphere.io/kubesphere/pkg/controller/job"
R
runzexia 已提交
25 26
	"kubesphere.io/kubesphere/pkg/controller/s2ibinary"
	"kubesphere.io/kubesphere/pkg/controller/s2irun"
X
Xin Wang 已提交
27
	"kubesphere.io/kubesphere/pkg/controller/storage/expansion"
H
hongming 已提交
28
	"kubesphere.io/kubesphere/pkg/controller/user"
J
Jeff 已提交
29
	"kubesphere.io/kubesphere/pkg/controller/virtualservice"
30 31
	"kubesphere.io/kubesphere/pkg/informers"
	"kubesphere.io/kubesphere/pkg/simple/client/k8s"
J
Jeff 已提交
32 33 34
	"sigs.k8s.io/controller-runtime/pkg/manager"
)

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

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

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

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

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

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

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

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

X
Xin Wang 已提交
82
	volumeExpansionController := expansion.NewVolumeExpansionController(
83 84 85 86 87 88 89
		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 已提交
90

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

J
Jeff 已提交
96 97 98
	controllers := map[string]manager.Runnable{
		"virtualservice-controller":  vsController,
		"destinationrule-controller": drController,
J
Jeff 已提交
99
		"application-controller":     apController,
J
Jeff 已提交
100
		"job-controller":             jobController,
R
runzexia 已提交
101 102
		"s2ibinary-controller":       s2iBinaryController,
		"s2irun-controller":          s2iRunController,
X
Xin Wang 已提交
103
		"volumeexpansion-controller": volumeExpansionController,
H
hongming 已提交
104
		"user-controller":            userController,
J
Jeff 已提交
105 106 107
	}

	for name, ctrl := range controllers {
108 109
		if err := mgr.Add(ctrl); err != nil {
			klog.Error(err, "add controller to manager failed", "name", name)
J
Jeff 已提交
110 111 112 113 114 115
			return err
		}
	}

	return nil
}