This repository has been archived by the owner on Feb 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathmain.go
115 lines (103 loc) · 2.67 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//go:generate go run pkg/codegen/cleanup/main.go
//go:generate go run pkg/codegen/main.go
//go:generate go run main.go --write-crds ./charts/rancher-operator-crd/templates/crds.yaml
//go:generate go run main.go --write-capi-crds ./charts/rancher-operator-crd/charts/capi/templates/crds.yaml
package main
import (
"context"
"fmt"
"math/rand"
"os"
"time"
"github.com/rancher/rancher-operator/pkg/controllers"
"github.com/rancher/rancher-operator/pkg/crd"
"github.com/rancher/wrangler/pkg/kubeconfig"
"github.com/rancher/wrangler/pkg/signals"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
_ "github.com/rancher/wrangler/pkg/generated/controllers/apiextensions.k8s.io/v1beta1"
)
var (
Version = "v0.0.0-dev"
GitCommit = "HEAD"
KubeConfig string
Context string
Namespace string
WriteCRDs string
WriteCAPICRDs string
EnableCAPI bool
EnableRKE bool
SkipCRD bool
)
func main() {
app := cli.NewApp()
app.Name = "rancher"
app.Version = fmt.Sprintf("%s (%s)", Version, GitCommit)
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "kubeconfig",
EnvVar: "KUBECONFIG",
Destination: &KubeConfig,
},
cli.StringFlag{
Name: "context",
EnvVar: "CONTEXT",
Destination: &Context,
},
cli.StringFlag{
Name: "namespace",
EnvVar: "NAMESPACE",
Destination: &Namespace,
Value: "rancher-operator-system",
},
cli.StringFlag{
Name: "write-crds",
Destination: &WriteCRDs,
},
cli.StringFlag{
Name: "write-capi-crds",
Destination: &WriteCAPICRDs,
},
cli.BoolFlag{
Name: "enable-capi",
Destination: &EnableCAPI,
EnvVar: "ENABLE_CAPI",
},
cli.BoolFlag{
Name: "enable-rke",
Destination: &EnableRKE,
EnvVar: "ENABLE_RKE",
},
cli.BoolFlag{
Name: "skip-crd",
Destination: &SkipCRD,
EnvVar: "SKIP_CRDS",
},
}
app.Action = run
if err := app.Run(os.Args); err != nil {
logrus.Fatal(err)
}
}
func run(c *cli.Context) error {
rand.Seed(time.Now().UnixNano())
if WriteCRDs != "" || WriteCAPICRDs != "" {
if WriteCRDs != "" {
logrus.Info("Writing CRDS to ", WriteCRDs)
return crd.WriteFileOperator(WriteCRDs)
}
if WriteCAPICRDs != "" {
logrus.Info("Writing CAPI CRDS to ", WriteCAPICRDs)
return crd.WriteFileCAPI(WriteCAPICRDs)
}
return nil
}
logrus.Info("Starting controller")
ctx := signals.SetupSignalHandler(context.Background())
clientConfig := kubeconfig.GetNonInteractiveClientConfigWithContext(KubeConfig, Context)
if err := controllers.Register(ctx, EnableCAPI, EnableRKE, !SkipCRD, Namespace, clientConfig); err != nil {
return err
}
<-ctx.Done()
return nil
}