forked from kyma-project/kyma
/
main.go
93 lines (68 loc) · 3.51 KB
/
main.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
84
85
86
87
88
89
90
91
92
93
package main
import (
"flag"
"log"
"time"
"github.com/kyma-project/kyma/components/installer/pkg/actionmanager"
"github.com/kyma-project/kyma/components/installer/pkg/conditionmanager"
"github.com/kyma-project/kyma/components/installer/pkg/consts"
"github.com/kyma-project/kyma/components/installer/pkg/finalizer"
"github.com/kyma-project/kyma/components/installer/pkg/installation"
"github.com/kyma-project/kyma/components/installer/pkg/kymahelm"
"github.com/kyma-project/kyma/components/installer/pkg/release"
"github.com/kyma-project/kyma/components/installer/pkg/servicecatalog"
"github.com/kyma-project/kyma/components/installer/pkg/toolkit"
"github.com/kyma-project/kyma/components/installer/pkg/statusmanager"
"github.com/kyma-project/kyma/components/installer/pkg/steps"
kubeinformers "k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
clientset "github.com/kyma-project/kyma/components/installer/pkg/client/clientset/versioned"
informers "github.com/kyma-project/kyma/components/installer/pkg/client/informers/externalversions"
)
func main() {
log.Println("starting operator...")
stop := make(chan struct{})
kubeconfig := flag.String("kubeconfig", "", "Path to a kubeconfig file")
helmHost := flag.String("helmhost", "tiller-deploy.kube-system.svc.cluster.local:44134", "Helm host")
kymaDir := flag.String("kymadir", "/kyma", "Chart directory")
flag.Parse()
config, err := getClientConfig(*kubeconfig)
if err != nil {
log.Fatalf("Unable to build kubernetes configuration. Error: %v", err)
}
kubeClient, err := kubernetes.NewForConfig(config)
if err != nil {
log.Fatalf("Unable to create kubernetes client. Error: %v", err)
}
internalClient, err := clientset.NewForConfig(config)
if err != nil {
log.Fatalf("Unable to create internal client. Error: %v", err)
}
helmClient := kymahelm.NewClient(*helmHost)
serviceCatalogClient := servicecatalog.NewClient(config)
kymaPackageClient := &steps.KymaPackageClient{}
kubeInformerFactory := kubeinformers.NewSharedInformerFactory(kubeClient, time.Second*30)
internalInformerFactory := informers.NewSharedInformerFactory(internalClient, time.Second*30)
installationLister := internalInformerFactory.Installer().V1alpha1().Installations().Lister()
kymaStatusManager := statusmanager.NewKymaStatusManager(internalClient, installationLister)
kymaActionManager := actionmanager.NewKymaActionManager(internalClient, installationLister)
conditionManager := conditionmanager.New(internalClient, installationLister)
installationFinalizerManager := finalizer.NewManager(consts.InstFinalizer)
releaseFinalizerManager := finalizer.NewManager(consts.RelFinalizer)
kymaCommandExecutor := &toolkit.KymaCommandExecutor{}
installationSteps := steps.New(helmClient, kubeClient, serviceCatalogClient, *kymaDir, kymaStatusManager, kymaActionManager, kymaCommandExecutor, kymaPackageClient)
installationController := installation.NewController(kubeClient, kubeInformerFactory, internalInformerFactory, *kymaDir, installationSteps, conditionManager, installationFinalizerManager, internalClient)
releaseController := release.NewController(kubeClient, internalInformerFactory, releaseFinalizerManager)
kubeInformerFactory.Start(stop)
internalInformerFactory.Start(stop)
installationController.Run(2, stop)
releaseController.Run(2, stop)
}
func getClientConfig(kubeconfig string) (*rest.Config, error) {
if kubeconfig != "" {
return clientcmd.BuildConfigFromFlags("", kubeconfig)
}
return rest.InClusterConfig()
}