diff --git a/etcd-manager/cmd/etcd-manager/main.go b/etcd-manager/cmd/etcd-manager/main.go index df224c22b..1c7385b60 100644 --- a/etcd-manager/cmd/etcd-manager/main.go +++ b/etcd-manager/cmd/etcd-manager/main.go @@ -195,7 +195,7 @@ func (o *EtcdManagerOptions) InitDefaults() { o.EtcdInsecure = false o.EtcdManagerMetricsPort = 0 - o.IPFilter = "" + o.IPFilter = os.Getenv("ETCD_MANAGER_IP_FILTER") } func parseIPFilter(o *EtcdManagerOptions) (*net.IPNet, error) { diff --git a/etcd-manager/cmd/etcd-manager/main_test.go b/etcd-manager/cmd/etcd-manager/main_test.go index bfeb7a733..16968326c 100644 --- a/etcd-manager/cmd/etcd-manager/main_test.go +++ b/etcd-manager/cmd/etcd-manager/main_test.go @@ -19,6 +19,7 @@ package main import ( "fmt" "net" + "os" "reflect" "testing" ) @@ -90,3 +91,20 @@ func TestParseIPFilterReturnsParsedIPv6CIDR(t *testing.T) { assertTestResults(t, err, expectedIPFilter, actualIPFilter) } + +func TestParseInitDefaultReturnsEmptyStringForIPFilter(t *testing.T) { + var o EtcdManagerOptions + o.InitDefaults() + + assertTestResults(t, nil, "", o.IPFilter) +} + +func TestParseInitDefaultReturnsValueOfEnvVarForIPFilter(t *testing.T) { + expectedIPFilter := "192.168.0.0/16" + os.Setenv("ETCD_MANAGER_IP_FILTER", expectedIPFilter) + + var o EtcdManagerOptions + o.InitDefaults() + + assertTestResults(t, nil, expectedIPFilter, o.IPFilter) +}