Skip to content

Commit

Permalink
Add DNSConfig.String() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Mirić committed Sep 10, 2020
1 parent f06ad67 commit 53c94b9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 9 additions & 3 deletions lib/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"net"
"reflect"
"strconv"
"strings"

"github.com/kubernetes/helm/pkg/strvals"
"github.com/pkg/errors"
Expand Down Expand Up @@ -67,15 +68,20 @@ const (
DNSRandom
)

const DefaultDNSConfigText = "ttl=inf,strategy=first"

func DefaultDNSConfig() DNSConfig {
return DNSConfig{
TTL: null.NewString("inf", false),
Strategy: NullDNSStrategy{DNSFirst, false},
}
}

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() {
Expand All @@ -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
}
Expand Down

0 comments on commit 53c94b9

Please sign in to comment.