controllers.go 4.0 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"
J
Jeff 已提交
28
	"kubesphere.io/kubesphere/pkg/controller/virtualservice"
29 30
	"kubesphere.io/kubesphere/pkg/informers"
	"kubesphere.io/kubesphere/pkg/simple/client/k8s"
J
Jeff 已提交
31 32 33
	"sigs.k8s.io/controller-runtime/pkg/manager"
)

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

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

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

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

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

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

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

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

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

	controllers := map[string]manager.Runnable{
		"virtualservice-controller":  vsController,
		"destinationrule-controller": drController,
J
Jeff 已提交
93
		"application-controller":     apController,
J
Jeff 已提交
94
		"job-controller":             jobController,
R
runzexia 已提交
95 96
		"s2ibinary-controller":       s2iBinaryController,
		"s2irun-controller":          s2iRunController,
X
Xin Wang 已提交
97
		"volumeexpansion-controller": volumeExpansionController,
J
Jeff 已提交
98 99 100
	}

	for name, ctrl := range controllers {
101 102
		if err := mgr.Add(ctrl); err != nil {
			klog.Error(err, "add controller to manager failed", "name", name)
J
Jeff 已提交
103 104 105 106 107 108
			return err
		}
	}

	return nil
}