diff --git a/internal/pkg/flags/cidrslice.go b/internal/pkg/flags/cidrslice.go index d8e9a0594..6bb595ff3 100644 --- a/internal/pkg/flags/cidrslice.go +++ b/internal/pkg/flags/cidrslice.go @@ -1,7 +1,6 @@ package flags import ( - "fmt" "strings" "github.com/spf13/pflag" @@ -25,7 +24,12 @@ func (f *cidrSliceFlag) String() string { func (f *cidrSliceFlag) Set(value string) error { if value == "" { - return fmt.Errorf("value cannot be empty") + // If it's the first value to be set to the flag, we set it to an empty list + // Otherwise, we just ignore an empty value + if len(f.value) == 0 { + f.value = []string{} + } + return nil } cidrs := strings.Split(value, ",") diff --git a/internal/pkg/flags/flags_test.go b/internal/pkg/flags/flags_test.go index b7326a135..1e77f616b 100644 --- a/internal/pkg/flags/flags_test.go +++ b/internal/pkg/flags/flags_test.go @@ -586,9 +586,17 @@ func TestCIDRSliceFlag(t *testing.T) { isValid: false, }, { - description: "invalid empty value", - value1: utils.Ptr(""), - isValid: false, + description: "empty value to specify empty list", + value1: utils.Ptr(""), + isValid: true, + expectedValue: []string{}, + }, + { + description: "valid value and empty value", + value1: utils.Ptr("198.51.100.14/24"), + value2: utils.Ptr(""), + isValid: true, + expectedValue: []string{"198.51.100.14/24"}, }, { description: "invalid empty value in list",