-
Notifications
You must be signed in to change notification settings - Fork 36
/
main.go
74 lines (61 loc) · 2.32 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
//go:generate go run pkg/codegen/cleanup/main.go
//go:generate go run pkg/codegen/main.go
package main
import (
"flag"
"github.com/rancher/eks-operator/controller"
eksv1 "github.com/rancher/eks-operator/pkg/generated/controllers/eks.cattle.io"
"github.com/rancher/wrangler/v3/pkg/generated/controllers/apps"
core3 "github.com/rancher/wrangler/v3/pkg/generated/controllers/core"
"github.com/rancher/wrangler/v3/pkg/kubeconfig"
"github.com/rancher/wrangler/v3/pkg/signals"
"github.com/rancher/wrangler/v3/pkg/start"
"github.com/sirupsen/logrus"
)
var (
masterURL string
kubeconfigFile string
debug bool
)
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.BoolVar(&debug, "debug", false, "Variable to set log level to debug; default is false")
flag.Parse()
}
func main() {
// set up signals so we handle the first shutdown signal gracefully
ctx := signals.SetupSignalContext()
if debug {
logrus.SetLevel(logrus.DebugLevel)
logrus.Debugf("Loglevel set to [%v]", logrus.DebugLevel)
}
// 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())
}
// Generated apps controller
apps := apps.NewFactoryFromConfigOrDie(cfg)
// core
core, err := core3.NewFactoryFromConfig(cfg)
if err != nil {
logrus.Fatalf("Error building core factory: %s", err.Error())
}
// Generated sample controller
eks, err := eksv1.NewFactoryFromConfig(cfg)
if err != nil {
logrus.Fatalf("Error building eks 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(),
eks.Eks().V1().EKSClusterConfig())
// Start all the controllers
if err := start.All(ctx, 3, apps, eks, core); err != nil {
logrus.Fatalf("Error starting: %s", err.Error())
}
<-ctx.Done()
}