From 5cf011376211cb61d30b06c6254ec33ce81b956d Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Tue, 3 Jul 2018 13:43:41 +0200 Subject: [PATCH] Add "omitempty" to some SD config YAML field tags (#4338) Especially for Kubernetes SD, this fixes a bug where the rendered configuration says "api_server: null", which when read back is not interpreted as an un-set API server (thus the default is not applied). Signed-off-by: Julius Volz --- discovery/consul/consul.go | 2 +- discovery/kubernetes/kubernetes.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/discovery/consul/consul.go b/discovery/consul/consul.go index 4a7c6cf906..a0bcf13461 100644 --- a/discovery/consul/consul.go +++ b/discovery/consul/consul.go @@ -108,7 +108,7 @@ type SDConfig struct { // See https://www.consul.io/api/catalog.html#list-services // The list of services for which targets are discovered. // Defaults to all services if empty. - Services []string `yaml:"services"` + Services []string `yaml:"services,omitempty"` // An optional tag used to filter instances inside a service. A single tag is supported // here to match the Consul API. ServiceTag string `yaml:"tag,omitempty"` diff --git a/discovery/kubernetes/kubernetes.go b/discovery/kubernetes/kubernetes.go index 637a4eb1db..faf4087ee4 100644 --- a/discovery/kubernetes/kubernetes.go +++ b/discovery/kubernetes/kubernetes.go @@ -84,13 +84,13 @@ func (c *Role) UnmarshalYAML(unmarshal func(interface{}) error) error { // SDConfig is the configuration for Kubernetes service discovery. type SDConfig struct { - APIServer config_util.URL `yaml:"api_server"` + APIServer config_util.URL `yaml:"api_server,omitempty"` Role Role `yaml:"role"` BasicAuth *config_util.BasicAuth `yaml:"basic_auth,omitempty"` BearerToken config_util.Secret `yaml:"bearer_token,omitempty"` BearerTokenFile string `yaml:"bearer_token_file,omitempty"` TLSConfig config_util.TLSConfig `yaml:"tls_config,omitempty"` - NamespaceDiscovery NamespaceDiscovery `yaml:"namespaces"` + NamespaceDiscovery NamespaceDiscovery `yaml:"namespaces,omitempty"` } // UnmarshalYAML implements the yaml.Unmarshaler interface.