Skip to content

Commit

Permalink
fix(server): allow passing loglevels as env vars to Server (#12145)
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Gilgur <agilgur5@gmail.com>
  • Loading branch information
agilgur5 authored and isubasinghe committed May 5, 2024
1 parent e8e9c2a commit 6daa22b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
23 changes: 23 additions & 0 deletions cmd/argo/commands/root.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package commands

import (
"fmt"
"strings"

"github.com/argoproj/pkg/cli"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"

"github.com/argoproj/argo-workflows/v3"
"github.com/argoproj/argo-workflows/v3/cmd/argo/commands/archive"
Expand Down Expand Up @@ -133,5 +138,23 @@ If your server is behind an ingress with a path (you'll be running "argo server
command.PersistentFlags().IntVar(&glogLevel, "gloglevel", 0, "Set the glog logging level")
command.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enabled verbose logging, i.e. --loglevel debug")

// set-up env vars for the CLI such that ARGO_* env vars can be used instead of flags
viper.AutomaticEnv()
viper.SetEnvPrefix("ARGO")
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_", ".", "_"))
// bind flags to env vars (https://github.com/spf13/viper/tree/v1.17.0#working-with-flags)
if err := viper.BindPFlags(command.PersistentFlags()); err != nil {
log.Fatal(err)
}
// workaround for handling required flags (https://github.com/spf13/viper/issues/397#issuecomment-544272457)
command.PersistentFlags().VisitAll(func(f *pflag.Flag) {
if !f.Changed && viper.IsSet(f.Name) {
val := viper.Get(f.Name)
if err := command.PersistentFlags().Set(f.Name, fmt.Sprintf("%v", val)); err != nil {
log.Fatal(err)
}
}
})

return command
}
3 changes: 3 additions & 0 deletions cmd/argo/commands/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,15 @@ See %s`, help.ArgoServer),
command.Flags().Float32Var(&kubeAPIQPS, "kube-api-qps", 20.0, "QPS to use while talking with kube-apiserver.")
command.Flags().IntVar(&kubeAPIBurst, "kube-api-burst", 30, "Burst to use while talking with kube-apiserver.")

// set-up env vars for the CLI such that ARGO_* env vars can be used instead of flags
viper.AutomaticEnv()
viper.SetEnvPrefix("ARGO")
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_", ".", "_"))
// bind flags to env vars (https://github.com/spf13/viper/tree/v1.17.0#working-with-flags)
if err := viper.BindPFlags(command.Flags()); err != nil {
log.Fatal(err)
}
// workaround for handling required flags (https://github.com/spf13/viper/issues/397#issuecomment-544272457)
command.Flags().VisitAll(func(f *pflag.Flag) {
if !f.Changed && viper.IsSet(f.Name) {
val := viper.Get(f.Name)
Expand Down
3 changes: 3 additions & 0 deletions cmd/workflow-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,15 @@ func NewRootCommand() *cobra.Command {
command.Flags().StringVar(&managedNamespace, "managed-namespace", "", "namespace that workflow-controller watches, default to the installation namespace")
command.Flags().BoolVar(&executorPlugins, "executor-plugins", false, "enable executor plugins")

// set-up env vars for the CLI such that ARGO_* env vars can be used instead of flags
viper.AutomaticEnv()
viper.SetEnvPrefix("ARGO")
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_", ".", "_"))
// bind flags to env vars (https://github.com/spf13/viper/tree/v1.17.0#working-with-flags)
if err := viper.BindPFlags(command.Flags()); err != nil {
log.Fatal(err)
}
// workaround for handling required flags (https://github.com/spf13/viper/issues/397#issuecomment-544272457)
command.Flags().VisitAll(func(f *pflag.Flag) {
if !f.Changed && viper.IsSet(f.Name) {
val := viper.Get(f.Name)
Expand Down

0 comments on commit 6daa22b

Please sign in to comment.