diff --git a/cmd/options.go b/cmd/options.go index 45426308d2c..837820e8d5a 100644 --- a/cmd/options.go +++ b/cmd/options.go @@ -91,7 +91,7 @@ func optionFlagSet() *pflag.FlagSet { flags.StringSlice("tag", nil, "add a `tag` to be applied to all samples, as `[name]=[value]`") flags.String("console-output", "", "redirects the console logging to the provided output file") flags.Bool("discard-response-bodies", false, "Read but don't process or save HTTP response bodies") - flags.String("dns", lib.DefaultDNSConfigText, "DNS configuration. Possible ttl values are: 'inf' "+ + flags.String("dns", lib.DefaultDNSConfig().String(), "DNS configuration. Possible ttl values are: 'inf' "+ "for a persistent cache, '0' to disable the cache,\nor a positive duration, e.g. '1s', '1m', etc. "+ "Milliseconds are assumed if no unit is provided.\n"+ "Possible values for the strategy to use to select a single IP are: 'first', 'random' or 'round-robin'.\n") diff --git a/lib/options.go b/lib/options.go index 9d0caed04e4..42f64993eea 100644 --- a/lib/options.go +++ b/lib/options.go @@ -27,6 +27,7 @@ import ( "net" "reflect" "strconv" + "strings" "github.com/kubernetes/helm/pkg/strvals" "github.com/pkg/errors" @@ -67,8 +68,6 @@ const ( DNSRandom ) -const DefaultDNSConfigText = "ttl=inf,strategy=first" - func DefaultDNSConfig() DNSConfig { return DNSConfig{ TTL: null.NewString("inf", false), @@ -76,6 +75,13 @@ func DefaultDNSConfig() DNSConfig { } } +func (c DNSConfig) String() string { + out := make([]string, 0, 2) + out = append(out, fmt.Sprintf("ttl=%s", c.TTL.String)) + out = append(out, fmt.Sprintf("strategy=%s", c.Strategy.String())) + return strings.Join(out, ",") +} + func (c DNSConfig) MarshalJSON() ([]byte, error) { var strat string if c.Strategy.IsADNSStrategy() { @@ -99,7 +105,7 @@ func (c *DNSConfig) UnmarshalJSON(data []byte) error { } func (c *DNSConfig) UnmarshalText(text []byte) error { - if string(text) == DefaultDNSConfigText { + if string(text) == DefaultDNSConfig().String() { *c = DefaultDNSConfig() return nil }