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
74 lines (59 loc) · 2.02 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
package entrypoints
import (
"context"
"flag"
"fmt"
"os"
"github.com/flyteorg/flytestdlib/config"
"github.com/flyteorg/flytestdlib/config/viper"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
var (
cfgFile string
configAccessor = viper.NewAccessor(config.Options{})
)
// RootCmd represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Use: "flytescheduler",
Short: "Flyte native scheduler to run cron and fixed rate scheduled workflows",
Long: `
Use the run subcommand which will start the scheduler by connecting to DB containing schedules
flytescheduler run --config flyteadmin_config.yaml --admin.endpoint dns:///localhost:8089 --admin.insecure
`,
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 `$ flytescheduler --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.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,
})
fmt.Println("Using config file: ", configAccessor.ConfigFilesUsed())
configAccessor.InitializePflags(flags)
return configAccessor.UpdateConfig(context.TODO())
}