Skip to content

Commit

Permalink
cli: Use custom named map instead of StringToStringVar
Browse files Browse the repository at this point in the history
Out of all the flags having string map type, only these two flags are
StringToStringVar type, which failed validation if the passed value is
json format.

```
2022-05-26T12:03:33.817769447Z level=fatal msg="Incorrect config-map flag subnet-tags-filter" error="{\"type\":\"private\"} must be formatted as key=value" subsys=config
```

Relates: #16014
Fixes: #19961
Signed-off-by: Tam Mach <tam.mach@cilium.io>
  • Loading branch information
sayboras authored and aanm committed Jun 3, 2022
1 parent aa7572b commit 2d35b95
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Documentation/cmdref/cilium-operator-alibabacloud.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Documentation/cmdref/cilium-operator-aws.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Documentation/cmdref/cilium-operator-azure.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Documentation/cmdref/cilium-operator-generic.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Documentation/cmdref/cilium-operator.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions contrib/scripts/check-viper-get-string-map-string.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ if grep -r --exclude-dir={.git,_build,vendor,contrib} -i --include \*.go "viper.
echo "Found viper.GetStringMapString(key) usage. Please use command.GetStringMapString(viper.GetViper(), key) instead";
exit 1
fi

if grep -r --exclude-dir={.git,_build,vendor,contrib} -i --include \*.go "StringToStringVar" .; then
echo "Found flags.StringToStringVar usage. Please use option.NewNamedMapOptions instead";
exit 1
fi
6 changes: 3 additions & 3 deletions operator/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ func init() {
flags.Float64(operatorOption.IPAMAPIQPSLimit, defaults.IPAMAPIQPSLimit, "Queries per second limit when accessing external IPAM APIs")
option.BindEnv(operatorOption.IPAMAPIQPSLimit)

flags.StringToStringVar(&operatorOption.Config.IPAMSubnetsTags, operatorOption.IPAMSubnetsTags, operatorOption.Config.IPAMSubnetsTags,
"Subnets tags in the form of k1=v1,k2=v2 (multiple k/v pairs can also be passed by repeating the CLI flag")
flags.Var(option.NewNamedMapOptions(operatorOption.IPAMSubnetsTags, &operatorOption.Config.IPAMSubnetsTags, nil),
operatorOption.IPAMSubnetsTags, "Subnets tags in the form of k1=v1,k2=v2 (multiple k/v pairs can also be passed by repeating the CLI flag")
option.BindEnv(operatorOption.IPAMSubnetsTags)

flags.StringSliceVar(&operatorOption.Config.IPAMSubnetsIDs, operatorOption.IPAMSubnetsIDs, operatorOption.Config.IPAMSubnetsIDs,
"Subnets IDs (separated by commas)")
option.BindEnv(operatorOption.IPAMSubnetsIDs)

flags.StringToStringVar(&operatorOption.Config.IPAMInstanceTags, operatorOption.IPAMInstanceTags, operatorOption.Config.IPAMInstanceTags,
flags.Var(option.NewNamedMapOptions(operatorOption.IPAMInstanceTags, &operatorOption.Config.IPAMInstanceTags, nil), operatorOption.IPAMInstanceTags,
"EC2 Instance tags in the form of k1=v1,k2=v2 (multiple k/v pairs can also be passed by repeating the CLI flag")
option.BindEnv(operatorOption.IPAMInstanceTags)

Expand Down

0 comments on commit 2d35b95

Please sign in to comment.