-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
56 lines (47 loc) · 1.3 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
package main
import (
"fmt"
"math/rand"
"os"
"time"
"github.com/spf13/cobra"
"k8s.io/component-base/cli"
"k8s.io/component-base/logs"
_ "k8s.io/component-base/logs/json/register"
"open-cluster-management.io/addon-framework/pkg/version"
meshagent "github.com/stolostron/multicluster-mesh-addon/pkg/agent"
constants "github.com/stolostron/multicluster-mesh-addon/pkg/constants"
meshmanager "github.com/stolostron/multicluster-mesh-addon/pkg/manager"
)
func main() {
rand.Seed(time.Now().UTC().UnixNano())
logsOptions := logs.NewOptions()
command := newCommand(logsOptions)
logsOptions.AddFlags(command.Flags())
code := cli.Run(command)
os.Exit(code)
if err := command.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
}
func newCommand(logsOptions *logs.Options) *cobra.Command {
cmd := &cobra.Command{
Use: "addon",
Short: "multicluster mesh addon",
Run: func(cmd *cobra.Command, args []string) {
if err := logsOptions.ValidateAndApply(); 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(meshmanager.NewControllerCommand())
cmd.AddCommand(meshagent.NewAgentCommand(constants.MeshAddonName))
return cmd
}