-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
76 lines (59 loc) · 1.63 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
package main
import (
"context"
"fmt"
"math/rand"
"os"
"time"
goflag "flag"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
utilflag "k8s.io/component-base/cli/flag"
"k8s.io/component-base/logs"
"github.com/openshift/library-go/pkg/controller/controllercmd"
"open-cluster-management.io/addon-framework/pkg/version"
"github.com/stolostron/ran-du-addon-controller/controllers"
)
func main() {
rand.Seed(time.Now().UTC().UnixNano())
pflag.CommandLine.SetNormalizeFunc(utilflag.WordSepNormalizeFunc)
pflag.CommandLine.AddGoFlagSet(goflag.CommandLine)
logs.InitLogs()
defer logs.FlushLogs()
command := newCommand()
fmt.Printf("RANDUAddonController version: %s\n", command.Version)
if err := command.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
}
func newCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "ran-du-addon",
Short: "RAN DU 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 := version.Get().String(); len(v) == 0 {
cmd.Version = "<unknown>"
} else {
cmd.Version = v
}
cmd.AddCommand(newControllerCommand())
return cmd
}
func newControllerCommand() *cobra.Command {
cmd := controllercmd.
NewControllerCommandConfig("ran-du-addon-controller", version.Get(), runControllers).
NewCommand()
cmd.Use = "controller"
cmd.Short = "Start the RAN DU addon controller"
return cmd
}
func runControllers(ctx context.Context, controllerContext *controllercmd.ControllerContext) error {
return controllers.StartControllers(ctx, controllerContext.KubeConfig)
}