Skip to content

Commit

Permalink
pkg/command: allow semicolon in map values in GetStringMapString
Browse files Browse the repository at this point in the history
This is needed to parse entries like:

    cluster-pool-map: \
        "mars=ipv4-cidrs:172.16.0.0/16,172.17.0.0/16;ipv4-mask-size:24
         jupiter=ipv4-cidrs:192.168.0.0/19;ipv4-mask-size:26"

which will be used for IPAM pools in cilium-operator.

Signed-off-by: Tobias Klauser <tobias@cilium.io>
  • Loading branch information
tklauser authored and gandro committed Mar 8, 2023
1 parent cd0b2f8 commit 4947c1a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/command/map_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (
equal = '='
)

var keyValueRegex = regexp.MustCompile(`([\w-:./@]+=([\w-:,./@][\w-:,./@ ]*[\w-:,./@])?[\w-:,./@]*,)*([\w-:./@]+=([\w-:,./@][\w-:,./@ ]*)?[\w-:./@]+)$`)
var keyValueRegex = regexp.MustCompile(`([\w-:;./@]+=([\w-:;,./@][\w-:;,./@ ]*[\w-:;,./@])?[\w-:;,./@]*,)*([\w-:;./@]+=([\w-:;,./@][\w-:;,./@ ]*)?[\w-:;./@]+)$`)

// GetStringMapString contains one enhancement to support k1=v2,k2=v2 compared to original
// implementation of GetStringMapString function
Expand Down
12 changes: 12 additions & 0 deletions pkg/command/map_string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,18 @@ func TestGetStringMapString(t *testing.T) {
},
wantErr: assert.NoError,
},
{
name: "valid kv format for cluster-pool-map",
args: args{
key: "CLUSTER_POOL_MAP",
value: "mars=ipv4-cidrs:172.16.0.0/16,172.17.0.0/16;ipv4-mask-size:24,jupiter=ipv4-cidrs:192.168.0.0/19;ipv4-mask-size:26",
},
want: map[string]string{
"mars": "ipv4-cidrs:172.16.0.0/16,172.17.0.0/16;ipv4-mask-size:24",
"jupiter": "ipv4-cidrs:192.168.0.0/19;ipv4-mask-size:26",
},
wantErr: assert.NoError,
},
{
name: "invalid kv format with extra comma",
args: args{
Expand Down

0 comments on commit 4947c1a

Please sign in to comment.