forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
starter.go
83 lines (66 loc) · 2.49 KB
/
starter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package operator
import (
"context"
"os"
"time"
apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
apiextensionsv1beta1informer "k8s.io/apiextensions-apiserver/pkg/client/informers/externalversions/apiextensions/v1beta1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/discovery"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/tools/cache"
configv1client "github.com/openshift/client-go/config/clientset/versioned"
configv1informer "github.com/openshift/client-go/config/informers/externalversions/config/v1"
"github.com/openshift/library-go/pkg/controller/controllercmd"
"github.com/openshift/origin/pkg/monitor/resourcewatch/controller/clusteroperatormetric"
"github.com/openshift/origin/pkg/monitor/resourcewatch/controller/configmonitor"
"github.com/openshift/origin/pkg/monitor/resourcewatch/storage"
)
func RunOperator(ctx context.Context, controllerCtx *controllercmd.ControllerContext) error {
kubeClient, err := apiextensionsclient.NewForConfig(controllerCtx.ProtoKubeConfig)
if err != nil {
return err
}
dynamicClient, err := dynamic.NewForConfig(controllerCtx.KubeConfig)
if err != nil {
return err
}
discoveryClient, err := discovery.NewDiscoveryClientForConfig(controllerCtx.KubeConfig)
if err != nil {
return err
}
repositoryPath := "/repository"
if repositoryPathEnv := os.Getenv("REPOSITORY_PATH"); len(repositoryPathEnv) > 0 {
repositoryPath = repositoryPathEnv
}
configStore, err := storage.NewGitStorage(repositoryPath)
if err != nil {
return err
}
configClient, err := configv1client.NewForConfig(controllerCtx.KubeConfig)
if err != nil {
return err
}
configInformer := configv1informer.NewClusterOperatorInformer(configClient, time.Minute, cache.Indexers{})
crdInformer := apiextensionsv1beta1informer.NewCustomResourceDefinitionInformer(kubeClient, time.Minute, cache.Indexers{})
openshiftConfigObserver := configmonitor.NewConfigObserverController(
dynamicClient,
crdInformer,
discoveryClient,
configStore,
[]schema.GroupVersion{
{
Group: "config.openshift.io", // Track everything under *.config.openshift.io
Version: "v1",
},
},
controllerCtx.EventRecorder,
)
clusterOperatorMetric := clusteroperatormetric.NewClusterOperatorMetricController(configInformer, configClient.ConfigV1(), controllerCtx.EventRecorder)
go crdInformer.Run(ctx.Done())
go configInformer.Run(ctx.Done())
go openshiftConfigObserver.Run(ctx, 1)
go clusterOperatorMetric.Run(ctx, 1)
<-ctx.Done()
return nil
}