From 49de0044df50262bdc3795cbc26aaf42c94066c2 Mon Sep 17 00:00:00 2001 From: ederst Date: Thu, 23 Jun 2022 20:03:04 +0200 Subject: [PATCH] Allow setting the IP filter with an env var --- etcd-manager/cmd/etcd-manager/main.go | 2 +- etcd-manager/cmd/etcd-manager/main_test.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) 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) +}