This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
/
root.go
85 lines (66 loc) · 2.28 KB
/
root.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
package entrypoints
import (
"context"
"flag"
"fmt"
"os"
"github.com/flyteorg/flytestdlib/logger"
"github.com/flyteorg/flytestdlib/config"
"github.com/flyteorg/flytestdlib/config/viper"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
var (
cfgFile string
kubeMasterURL string
configAccessor = viper.NewAccessor(config.Options{})
)
// RootCmd represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Use: "flyteadmin",
Short: "Fill in later",
Long: `
To get started run the serve subcommand which will start a server on localhost:8088:
flyteadmin serve
Then you can hit it with the client:
flyteadmin adminservice foo bar baz
Or over HTTP 1.1 with curl:
curl -X POST http://localhost:8088/api/v1/projects'
`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return initConfig(cmd.Flags())
},
}
// Execute adds all child commands to the root command sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() error {
if err := RootCmd.Execute(); err != nil {
fmt.Println(err)
return err
}
return nil
}
func init() {
// allows `$ flyteadmin --logtostderr` to work
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
// Add persistent flags - persistent flags persist through all sub-commands
RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is ./flyteadmin_config.yaml)")
RootCmd.PersistentFlags().StringVar(&kubeMasterURL, "master", "", "The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.")
RootCmd.AddCommand(viper.GetConfigCommand())
// Allow viper to read the value of the flags
configAccessor.InitializePflags(RootCmd.PersistentFlags())
err := flag.CommandLine.Parse([]string{})
if err != nil {
fmt.Println(err)
os.Exit(-1)
}
}
func initConfig(flags *pflag.FlagSet) error {
configAccessor = viper.NewAccessor(config.Options{
SearchPaths: []string{cfgFile, ".", "/etc/flyte/config", "$GOPATH/src/github.com/flyteorg/flyteadmin"},
StrictMode: false,
})
logger.Infof(context.TODO(), "Using config file: %v", configAccessor.ConfigFilesUsed())
configAccessor.InitializePflags(flags)
return configAccessor.UpdateConfig(context.TODO())
}