-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.go
100 lines (82 loc) · 2.19 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
/*
* Copyright (c) 2023 NetLOX Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package main
import (
"flag"
"os"
"k8s.io/component-base/logs"
"k8s.io/klog/v2"
"github.com/spf13/cobra"
"github.com/loxilb-io/kube-loxilb/cmd"
"github.com/loxilb-io/kube-loxilb/pkg/api"
"github.com/loxilb-io/kube-loxilb/pkg/log"
)
func Execute() {
var rootCmd = &cobra.Command{
Use: "kube-loxilb",
Short: "loxilb-k8s",
Long: "loxilb-k8s",
}
client, err := api.NewLoxiClient("http://127.0.0.1:11111", nil, nil, false)
if err != nil {
return
}
rootCmd.AddCommand(cmd.GetCmd(client))
rootCmd.AddCommand(cmd.CreateCmd(client))
rootCmd.AddCommand(cmd.DeleteCmd(client))
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
}
func main() {
logs.InitLogs()
defer logs.FlushLogs()
command := newAgentCommand()
if err := command.Execute(); err != nil {
logs.FlushLogs()
os.Exit(1)
}
//Execute()
}
func newAgentCommand() *cobra.Command {
opts := newOptions()
cmd := &cobra.Command{
Use: "loxilb-agent",
Long: "The loxilb agent runs on each node.",
Run: func(cmd *cobra.Command, args []string) {
log.InitLogFileLimits(cmd.Flags())
log.InitLogLevel(cmd.Flags())
if err := opts.complete(args); err != nil {
klog.Errorf("Failed to options complete. err: %v", err)
os.Exit(255)
}
if err := opts.validate(args); err != nil {
klog.Errorf("Failed to options validate. err: %v", err)
os.Exit(255)
}
if err := run(opts); err != nil {
klog.Errorf("Error running agent. err: %v", err)
os.Exit(255)
}
},
Version: "beta",
}
flags := cmd.Flags()
opts.addFlags(flags)
log.AddFlags(flags)
flags.AddGoFlagSet(flag.CommandLine)
return cmd
}