forked from rancher/aks-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (52 loc) · 1.94 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
//go:generate go run pkg/codegen/cleanup/main.go
//go:generate go run pkg/codegen/main.go
package main
import (
"flag"
"github.com/rancher/aks-operator/controller"
aksv1 "github.com/rancher/aks-operator/pkg/generated/controllers/aks.cattle.io"
core3 "github.com/rancher/wrangler/pkg/generated/controllers/core"
"github.com/rancher/wrangler/pkg/kubeconfig"
"github.com/rancher/wrangler/pkg/signals"
"github.com/rancher/wrangler/pkg/start"
"github.com/sirupsen/logrus"
)
var (
masterURL string
kubeconfigFile string
)
func init() {
flag.StringVar(&kubeconfigFile, "kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.")
flag.StringVar(&masterURL, "master", "", "The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.")
flag.Parse()
}
func main() {
// set up signals so we handle the first shutdown signal gracefully
ctx := signals.SetupSignalContext()
// This will load the kubeconfig file in a style the same as kubectl
cfg, err := kubeconfig.GetNonInteractiveClientConfig(kubeconfigFile).ClientConfig()
if err != nil {
logrus.Fatalf("Error building kubeconfig: %s", err.Error())
}
// core
core, err := core3.NewFactoryFromConfig(cfg)
if err != nil {
logrus.Fatalf("Error building core factory: %s", err.Error())
}
// Generated sample controller
aks, err := aksv1.NewFactoryFromConfig(cfg)
if err != nil {
logrus.Fatalf("Error building aks factory: %s", err.Error())
}
// The typical pattern is to build all your controller/clients then just pass to each handler
// the bare minimum of what they need. This will eventually help with writing tests. So
// don't pass in something like kubeClient, apps, or sample
controller.Register(ctx,
core.Core().V1().Secret(),
aks.Aks().V1().AKSClusterConfig())
// Start all the controllers
if err := start.All(ctx, 2, aks, core); err != nil {
logrus.Fatalf("Error starting: %s", err.Error())
}
<-ctx.Done()
}