Last active
September 16, 2017 09:08
-
-
Save dhensen/ab04e0804df655974064e461b6dfa3c0 to your computer and use it in GitHub Desktop.
Default ingress-class can not be overridden
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
"os" | |
"github.com/spf13/pflag" | |
) | |
func main() { | |
flags := pflag.NewFlagSet("", pflag.ExitOnError) | |
ingressClass := flags.String("ingress-class", "", | |
`Name of the ingress class to route through this controller.`) | |
flags.AddGoFlagSet(flag.CommandLine) | |
ingressClassFoo := flags.Lookup("ingress-class") | |
// Set default value before Parse | |
if ingressClassFoo != nil { | |
ingressClassFoo.Value.Set("haproxy") | |
ingressClassFoo.DefValue = "haproxy" | |
} | |
// Perform Parse | |
flags.Parse(os.Args) | |
// change flag value after Parse | |
ic, _ := flags.GetString("ingress-class") | |
if ic == "" { | |
flags.Set("ingress-class", "haproxy") | |
} | |
fmt.Printf("Ingress class: %s\n", *ingressClass) | |
} | |
//$ go run main.go | |
//Ingress class: haproxy | |
//$ go run main.go --ingress-class=Foo | |
//Ingress class: Foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment