-
Notifications
You must be signed in to change notification settings - Fork 81
/
main.go
63 lines (54 loc) · 1.67 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
//go:generate go run pkg/settings/script/main.go ./pkg/settings/install.sh
package main
import (
"os"
"path/filepath"
"time"
"github.com/cnrancher/autok3s/cmd"
"github.com/cnrancher/autok3s/cmd/addon"
"github.com/cnrancher/autok3s/cmd/airgap"
"github.com/cnrancher/autok3s/cmd/sshkey"
"github.com/cnrancher/autok3s/pkg/cli/kubectl"
"github.com/cnrancher/autok3s/pkg/common"
"github.com/cnrancher/autok3s/pkg/metrics"
"github.com/docker/docker/pkg/reexec"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
var (
gitVersion = "dev"
gitCommit string
gitTreeState string
buildDate string
)
func init() {
reexec.Register("kubectl", kubectl.Main)
}
func main() {
args := os.Args[0]
os.Args[0] = filepath.Base(os.Args[0])
if reexec.Init() {
return
}
os.Args[0] = args
rootCmd := cmd.Command()
rootCmd.AddCommand(cmd.CompletionCommand(), cmd.VersionCommand(gitVersion, gitCommit, gitTreeState, buildDate),
cmd.ListCommand(), cmd.CreateCommand(), cmd.JoinCommand(), cmd.KubectlCommand(), cmd.DeleteCommand(),
cmd.SSHCommand(), cmd.DescribeCommand(), cmd.ServeCommand(), cmd.ExplorerCommand(), cmd.UpgradeCommand(),
cmd.TelemetryCommand(), airgap.Command(), sshkey.Command(), cmd.DashboardCommand(), addon.Command())
rootCmd.PersistentPreRun = func(c *cobra.Command, args []string) {
common.InitLogger(logrus.StandardLogger())
common.MetricsPrompt(c)
common.SetupPrometheusMetrics(gitVersion)
go metrics.Report()
if c.Use == cmd.ServeCommand().Use {
metrics.ReportEach(c.Context(), 1*time.Hour)
}
}
rootCmd.PersistentPostRun = func(c *cobra.Command, args []string) {
metrics.Report()
}
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
}