Skip to content

Instantly share code, notes, and snippets.

@j-griffith
Created September 4, 2018 17:24
Show Gist options
  • Select an option

  • Save j-griffith/a8ac7dc5476c453fafc6b31fce9c54c1 to your computer and use it in GitHub Desktop.

Select an option

Save j-griffith/a8ac7dc5476c453fafc6b31fce9c54c1 to your computer and use it in GitHub Desktop.
Minor simplification of flag parsing
diff --git a/cmd/cdi-controller/controller.go b/cmd/cdi-controller/controller.go
index a20c815..6937e7f 100644
--- a/cmd/cdi-controller/controller.go
+++ b/cmd/cdi-controller/controller.go
@@ -2,9 +2,9 @@ package main
import (
"flag"
- "fmt"
"os"
"os/signal"
+ "strconv"
"github.com/golang/glog"
@@ -38,10 +38,16 @@ func init() {
const IMPORTER_IMAGE = "IMPORTER_IMAGE"
const CLONER_IMAGE = "CLONER_IMAGE"
+ var v string
// flags
+ flag.StringVar(&v, "verbosity", strconv.Itoa(DEFAULT_VERBOSE), "(Optional) Overrides default logging verbosity level.")
flag.StringVar(&configPath, "kubeconfig", os.Getenv("KUBECONFIG"), "(Optional) Overrides $KUBECONFIG")
flag.StringVar(&masterURL, "server", "", "(Optional) URL address of a remote api server. Do not set for local clusters.")
flag.Parse()
+ verbose = v
+ if verbose == strconv.Itoa(DEFAULT_VERBOSE) {
+ glog.V(Vuser).Infof("Note: increase the -v level in the controller deployment for more detailed logging, eg. -v=%d or -v=%d\n", Vadmin, Vdebug)
+ }
// env variables
importerImage = os.Getenv(IMPORTER_IMAGE)
@@ -59,19 +65,6 @@ func init() {
pullPolicy = pp
}
- // get the verbose level so it can be passed to the importer pod
- defVerbose := fmt.Sprintf("%d", DEFAULT_VERBOSE) // note flag values are strings
- verbose = defVerbose
- // visit actual flags passed in and if passed check -v and set verbose
- flag.Visit(func(f *flag.Flag) {
- if f.Name == "v" {
- verbose = f.Value.String()
- }
- })
- if verbose == defVerbose {
- glog.V(Vuser).Infof("Note: increase the -v level in the controller deployment for more detailed logging, eg. -v=%d or -v=%d\n", Vadmin, Vdebug)
- }
-
glog.V(Vdebug).Infof("init: complete: cdi controller will create importer using image %q\n", importerImage)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment