From 517beb9a8771028cdddf300fb56851899c79847a Mon Sep 17 00:00:00 2001 From: Yuvraj Date: Mon, 14 Jun 2021 00:06:13 +0530 Subject: [PATCH] Added flytectl config by env variable (#91) * Added flytectl config by env variable * remove -c short command from register flags Signed-off-by: Yuvraj --- .../config/subcommand/register/filesconfig_flags.go | 2 +- flytectl/cmd/register/files.go | 10 +++++----- flytectl/cmd/root.go | 13 ++++++++++--- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/flytectl/cmd/config/subcommand/register/filesconfig_flags.go b/flytectl/cmd/config/subcommand/register/filesconfig_flags.go index dce52b6c8b..ffcb0d7ec4 100755 --- a/flytectl/cmd/config/subcommand/register/filesconfig_flags.go +++ b/flytectl/cmd/config/subcommand/register/filesconfig_flags.go @@ -14,7 +14,7 @@ import ( func (cfg FilesConfig) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags := pflag.NewFlagSet("FilesConfig", pflag.ExitOnError) cmdFlags.StringVarP(&DefaultFilesConfig.Version, fmt.Sprintf("%v%v", prefix, "version"), "v", DefaultFilesConfig.Version, "version of the entity to be registered with flyte.") - cmdFlags.BoolVarP(&DefaultFilesConfig.ContinueOnError, fmt.Sprintf("%v%v", prefix, "continueOnError"), "c", DefaultFilesConfig.ContinueOnError, "continue on error when registering files.") + cmdFlags.BoolVarP(&DefaultFilesConfig.ContinueOnError, fmt.Sprintf("%v%v", prefix, "continueOnError"), "", DefaultFilesConfig.ContinueOnError, "continue on error when registering files.") cmdFlags.BoolVarP(&DefaultFilesConfig.Archive, fmt.Sprintf("%v%v", prefix, "archive"), "a", DefaultFilesConfig.Archive, "pass in archive file either an http link or local path.") cmdFlags.StringVarP(&DefaultFilesConfig.AssumableIamRole, fmt.Sprintf("%v%v", prefix, "assumableIamRole"), "i", DefaultFilesConfig.AssumableIamRole, " Custom assumable iam auth role to register launch plans with.") cmdFlags.StringVarP(&DefaultFilesConfig.K8ServiceAccount, fmt.Sprintf("%v%v", prefix, "k8ServiceAccount"), "k", DefaultFilesConfig.K8ServiceAccount, " custom kubernetes service account auth role to register launch plans with.") diff --git a/flytectl/cmd/register/files.go b/flytectl/cmd/register/files.go index f0762d89a0..f8d07c969e 100644 --- a/flytectl/cmd/register/files.go +++ b/flytectl/cmd/register/files.go @@ -43,7 +43,7 @@ the continueOnError flag. Using short format of continueOnError flag :: - bin/flytectl register file _pb_output/* -d development -p flytesnacks -c + bin/flytectl register file _pb_output/* -d development -p flytesnacks --continueOnError Overriding the default version v1 using version string. :: @@ -54,25 +54,25 @@ Change the o/p format has not effect on registration. The O/p is currently avail :: - bin/flytectl register file _pb_output/* -d development -p flytesnacks -c -o yaml + bin/flytectl register file _pb_output/* -d development -p flytesnacks --continueOnError -o yaml Override IamRole during registration. :: - bin/flytectl register file _pb_output/* -d development -p flytesnacks -c -v v2 -i "arn:aws:iam::123456789:role/dummy" + bin/flytectl register file _pb_output/* -d development -p flytesnacks --continueOnError -v v2 -i "arn:aws:iam::123456789:role/dummy" Override Kubernetes service account during registration. :: - bin/flytectl register file _pb_output/* -d development -p flytesnacks -c -v v2 -k "kubernetes-service-account" + bin/flytectl register file _pb_output/* -d development -p flytesnacks --continueOnError -v v2 -k "kubernetes-service-account" Override Output location prefix during registration. :: - bin/flytectl register file _pb_output/* -d development -p flytesnacks -c -v v2 -l "s3://dummy/prefix" + bin/flytectl register file _pb_output/* -d development -p flytesnacks --continueOnError -v v2 -l "s3://dummy/prefix" Usage ` diff --git a/flytectl/cmd/root.go b/flytectl/cmd/root.go index 15533fd625..cadeba379d 100644 --- a/flytectl/cmd/root.go +++ b/flytectl/cmd/root.go @@ -3,6 +3,7 @@ package cmd import ( "context" "fmt" + "os" f "github.com/flyteorg/flytectl/pkg/filesystemutils" @@ -42,8 +43,7 @@ func newRootCmd() *cobra.Command { DisableAutoGenTag: true, } - rootCmd.PersistentFlags().StringVar(&cfgFile, "config", f.FilePathJoin(f.UserHomeDir(), configFileDir, configFileName), - "config file (default is $HOME/.flyte/config.yaml)") + rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file (default is $HOME/.flyte/config.yaml)") configAccessor.InitializePflags(rootCmd.PersistentFlags()) @@ -68,9 +68,16 @@ func newRootCmd() *cobra.Command { } func initConfig(_ *cobra.Command, _ []string) error { + configFile := f.FilePathJoin(f.UserHomeDir(), configFileDir, configFileName) + if len(os.Getenv("FLYTECTL_CONFIG")) > 0 { + configFile = os.Getenv("FLYTECTL_CONFIG") + } + if len(cfgFile) > 0 { + configFile = cfgFile + } configAccessor = viper.NewAccessor(stdConfig.Options{ StrictMode: true, - SearchPaths: []string{cfgFile}, + SearchPaths: []string{configFile}, }) err := configAccessor.UpdateConfig(context.TODO())