forked from rancher/system-upgrade-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
105 lines (96 loc) · 2.5 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
//go:generate go run pkg/codegen/cleanup/cleanup.go
//go:generate rm -rf pkg/generated
//go:generate go run pkg/codegen/codegen.go
package main
// Copyright 2019 Rancher Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import (
"fmt"
"os"
"time"
"github.com/rancher/system-upgrade-controller/pkg/upgrade"
"github.com/rancher/system-upgrade-controller/pkg/version"
"github.com/rancher/wrangler/pkg/signals"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"k8s.io/client-go/tools/clientcmd"
)
var (
debug bool
kubeConfig, masterURL string
namespace, name, serviceAccountName string
threads int
)
func main() {
app := cli.NewApp()
app.Name = "system-upgrade-controller"
app.Usage = "in ur system controllin ur upgradez"
app.Version = fmt.Sprintf("%s (%s)", version.Version, version.GitCommit)
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "debug",
EnvVar: "SYSTEM_UPGRADE_CONTROLLER_DEBUG",
Destination: &debug,
},
cli.StringFlag{
Name: "kubeconfig",
EnvVar: "SYSTEM_UPGRADE_CONTROLLER_KUBE_CONFIG",
//Value: "${HOME}/.kube/config",
Destination: &kubeConfig,
},
cli.StringFlag{
Name: "master",
EnvVar: "SYSTEM_UPGRADE_CONTROLLER_MASTER_URL",
Destination: &masterURL,
},
cli.StringFlag{
Name: "name",
EnvVar: "SYSTEM_UPGRADE_CONTROLLER_NAME",
Required: true,
Destination: &name,
},
cli.StringFlag{
Name: "namespace",
EnvVar: "SYSTEM_UPGRADE_CONTROLLER_NAMESPACE",
Required: true,
Destination: &namespace,
},
cli.StringFlag{
Name: "service-account",
Hidden: true,
Destination: &serviceAccountName,
},
cli.IntFlag{
Name: "threads",
EnvVar: "SYSTEM_UPGRADE_CONTROLLER_THREADS",
Value: 2,
Destination: &threads,
},
}
app.Action = Run
if serviceAccountName != "" {
logrus.Warn("deprecated flag `service-account` is ignored")
}
if err := app.Run(os.Args); err != nil {
logrus.Fatal(err)
}
}
func Run(_ *cli.Context) {
if debug {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetReportCaller(true)
}
cfg, err := clientcmd.BuildConfigFromFlags(masterURL, kubeConfig)
if err != nil {
logrus.Fatal(err)
}
ctl, err := upgrade.NewController(cfg, namespace, name, 2*time.Hour)
if err != nil {
logrus.Fatal(err)
}
ctx := signals.SetupSignalContext()
if err := ctl.Start(ctx, threads); err != nil {
logrus.Fatalf("Error starting: %v", err)
}
<-ctx.Done()
}