Skip to content

Commit

Permalink
Allow setting the IP filter with an env var
Browse files Browse the repository at this point in the history
  • Loading branch information
ederst committed Jun 23, 2022
1 parent 3b9cf7d commit 49de004
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion etcd-manager/cmd/etcd-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
18 changes: 18 additions & 0 deletions etcd-manager/cmd/etcd-manager/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main
import (
"fmt"
"net"
"os"
"reflect"
"testing"
)
Expand Down Expand Up @@ -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)
}

0 comments on commit 49de004

Please sign in to comment.