-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
108 lines (87 loc) · 3.17 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
package main
import (
"context"
"fmt"
"os"
"time"
goflag "flag"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/version"
utilflag "k8s.io/component-base/cli/flag"
"k8s.io/component-base/logs"
"github.com/openshift/library-go/pkg/controller/controllercmd"
"github.com/stolostron/volsync-addon-controller/controllers"
"github.com/stolostron/volsync-addon-controller/controllers/helmutils"
)
var versionFromGit = "0.0.0"
var commitFromGit = ""
func main() {
pflag.CommandLine.SetNormalizeFunc(utilflag.WordSepNormalizeFunc)
pflag.CommandLine.AddGoFlagSet(goflag.CommandLine)
logs.InitLogs()
defer logs.FlushLogs()
command := newCommand()
fmt.Printf("VolSyncAddonController version: %s\n", command.Version)
embeddedHelmChartsDir := os.Getenv("EMBEDDED_CHARTS_DIR")
// Load local embedded helm charts - will be read in as a charts object
err := helmutils.InitEmbeddedCharts(embeddedHelmChartsDir)
if err != nil {
fmt.Printf("error loading embedded chart: %s", err)
os.Exit(1)
}
if err := command.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
}
func newCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "volsync-addon",
Short: "Volsync addon",
Run: func(cmd *cobra.Command, args []string) {
if err := cmd.Help(); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
}
os.Exit(1)
},
}
if v := getVersion().String(); len(v) == 0 {
cmd.Version = "<unknown>"
} else {
cmd.Version = v
}
cmd.AddCommand(newControllerCommand())
return cmd
}
func newControllerCommand() *cobra.Command {
cmdConfig := controllercmd.
NewControllerCommandConfig("volsync-addon-controller", getVersion(), runControllers)
cmd := cmdConfig.NewCommand()
cmd.Use = "controller"
cmd.Short = "Start the volsync addon controller"
flags := cmd.Flags()
flags.DurationVar(&cmdConfig.LeaseDuration.Duration, "leader-election-lease-duration", 137*time.Second, ""+
"The duration that non-leader candidates will wait after observing a leadership "+
"renewal until attempting to acquire leadership of a led but unrenewed leader "+
"slot. This is effectively the maximum duration that a leader can be stopped "+
"before it is replaced by another candidate. This is only applicable if leader "+
"election is enabled.")
flags.DurationVar(&cmdConfig.RenewDeadline.Duration, "leader-election-renew-deadline", 107*time.Second, ""+
"The interval between attempts by the acting master to renew a leadership slot "+
"before it stops leading. This must be less than or equal to the lease duration. "+
"This is only applicable if leader election is enabled.")
flags.DurationVar(&cmdConfig.RetryPeriod.Duration, "leader-election-retry-period", 26*time.Second, ""+
"The duration the clients should wait between attempting acquisition and renewal "+
"of a leadership. This is only applicable if leader election is enabled.")
return cmd
}
func runControllers(ctx context.Context, controllerContext *controllercmd.ControllerContext) error {
return controllers.StartControllers(ctx, controllerContext.KubeConfig)
}
func getVersion() version.Info {
return version.Info{
GitCommit: commitFromGit,
GitVersion: versionFromGit,
}
}