Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd: subnet-tags-filter: k=v (and other options) silently fail when provided via ConfigMap #18328

Closed
gandro opened this issue Dec 22, 2021 · 3 comments · Fixed by #18478
Closed
Assignees
Labels
area/cli Impacts the command line interface of any command in the repository. kind/bug This is a bug in the Cilium logic.

Comments

@gandro
Copy link
Member

gandro commented Dec 22, 2021

When providing the flags like subnet-tags-filter via ConfigMap, we have assumed and documented that these flags (relying on GetStringMapString) can be populated via a k=v syntax. However, it turns out that when specified via ConfigMap, it needs to be JSON syntax ({"k":"v"}), and not the k=v syntax as documented. The latter syntax only works if directly passed via command-line argument.

As a result, using subnet-tags-filter: foo=bar in the ConfigMap will cause cilium-operator to read the flag as nil and not use any subnet filters at all

Affected flags:

pkg/option/config.go
2771:	if m := viper.GetStringMapString(FixedIdentityMapping); len(m) != 0 {
2777:	if m := viper.GetStringMapString(KVStoreOpt); len(m) != 0 {
2781:	if m := viper.GetStringMapString(LogOpt); len(m) != 0 {
2785:	if m := viper.GetStringMapString(APIRateLimitName); len(m) != 0 {

operator/option/config.go
449:	if m := viper.GetStringMapString(IPAMSubnetsTags); len(m) != 0 {
453:	if m := viper.GetStringMapString(AWSInstanceLimitMapping); len(m) != 0 {
457:	if m := viper.GetStringMapString(ENITags); len(m) != 0 {

Upstream issue: spf13/viper#911

We should replace viper.GetStringMapString by something which behaves the same regardless of wheater the flag has been provided via command-line argument or config-dir (i.e. ConfigMap) entry.

@gandro gandro added kind/bug This is a bug in the Cilium logic. area/cli Impacts the command line interface of any command in the repository. needs-backport/1.9 labels Dec 22, 2021
@sayboras
Copy link
Member

Let me give it a crack

@sayboras
Copy link
Member

sayboras commented Jan 14, 2022

Just want to confirm the current behaviour.

We are having below validation, which basically will check the flag value. And for the flag, only k=v format is accepted. So is either format not working at all right now ?

  • json format got rejected by below validation
  • kv format failed to parse due to upstream issue in viper.

if err := flag.Value.Set(val); err != nil {

json format
$ cat tmp/subnet-tags-filter 
{"k1":"v1", "k2":"v2"}% 

$ /usr/lib/go-1.17/bin/go build -o /tmp/GoLand/___2go_build_github_com_cilium_cilium_operator github.com/cilium/cilium/operator #gosetup
/tmp/GoLand/___2go_build_github_com_cilium_cilium_operator --config-dir tmp/
level=fatal msg="Incorrect config-map flag subnet-tags-filter" error="{\"k1\":\"v1\", \"k2\":\"v2\"} must be formatted as key=value" subsys=config
kv format
$ cat tmp/subnet-tags-filter
k1=v1,k2=v2% 

/usr/lib/go-1.17/bin/go build -o /tmp/GoLand/___2go_build_github_com_cilium_cilium_operator github.com/cilium/cilium/operator #gosetup
/tmp/GoLand/___2go_build_github_com_cilium_cilium_operator --config-dir tmp/
level=info msg="Started gops server" address="127.0.0.1:9891" subsys=___2go_build_github_com_cilium_cilium_operator
level=warning msg="Running Cilium with \"kvstore\"=\"\" requires identity allocation via CRDs. Changing identity-allocation-mode to \"crd\"" subsys=config
...
level=info msg="  --skip-crd-creation='false'" subsys=___2go_build_github_com_cilium_cilium_operator
level=info msg="  --subnet-ids-filter=''" subsys=___2go_build_github_com_cilium_cilium_operator
level=info msg="  --subnet-ids-filter=''" subsys=___2go_build_github_com_cilium_cilium_operator --> this is empty
level=info msg="  --synchronize-k8s-nodes='true'" subsys=___2go_build_github_com_cilium_cilium_operator
...
level=info msg="Cilium Operator  go version go1.17 linux/amd64" subsys=___2go_build_github_com_cilium_cilium_operator

@gandro
Copy link
Member Author

gandro commented Jan 17, 2022

@sayboras Yes, that looks consistent with my observations. Note that in Cilium v1.10 the former (JSON in ConfigMap) seems to be accepted, but this changed in v1.11.

sayboras added a commit to sayboras/cilium that referenced this issue Jan 20, 2022
As mentioned in below upstream issue, there is a discrepancy in viper
while reading string map string data type i.e. kv pair format was not
supported, only `{"k":"v"}` format is allowed. This commit is to wrap
GetStringMapString implementation to handle such case.

Also, during the bootstrap, if there is any flag having invalid value,
fatal log will be printed for early detection and awareness.

Relates spf13/viper#911
Fixes cilium#18328

Signed-off-by: Tam Mach <tam.mach@isovalent.com>
glibsm pushed a commit that referenced this issue Jan 31, 2022
As mentioned in below upstream issue, there is a discrepancy in viper
while reading string map string data type i.e. kv pair format was not
supported, only `{"k":"v"}` format is allowed. This commit is to wrap
GetStringMapString implementation to handle such case.

Also, during the bootstrap, if there is any flag having invalid value,
fatal log will be printed for early detection and awareness.

Relates spf13/viper#911
Fixes #18328

Signed-off-by: Tam Mach <tam.mach@isovalent.com>
joamaki pushed a commit to joamaki/cilium that referenced this issue Feb 7, 2022
[ upstream commit 768659f ]

As mentioned in below upstream issue, there is a discrepancy in viper
while reading string map string data type i.e. kv pair format was not
supported, only `{"k":"v"}` format is allowed. This commit is to wrap
GetStringMapString implementation to handle such case.

Also, during the bootstrap, if there is any flag having invalid value,
fatal log will be printed for early detection and awareness.

Relates spf13/viper#911
Fixes cilium#18328

Signed-off-by: Tam Mach <tam.mach@isovalent.com>
Signed-off-by: Jussi Maki <jussi@isovalent.com>
joamaki pushed a commit to joamaki/cilium that referenced this issue Feb 7, 2022
[ upstream commit 768659f ]

As mentioned in below upstream issue, there is a discrepancy in viper
while reading string map string data type i.e. kv pair format was not
supported, only `{"k":"v"}` format is allowed. This commit is to wrap
GetStringMapString implementation to handle such case.

Also, during the bootstrap, if there is any flag having invalid value,
fatal log will be printed for early detection and awareness.

Relates spf13/viper#911
Fixes cilium#18328

Signed-off-by: Tam Mach <tam.mach@isovalent.com>
Signed-off-by: Jussi Maki <jussi@isovalent.com>
joamaki pushed a commit that referenced this issue Feb 8, 2022
[ upstream commit 768659f ]

As mentioned in below upstream issue, there is a discrepancy in viper
while reading string map string data type i.e. kv pair format was not
supported, only `{"k":"v"}` format is allowed. This commit is to wrap
GetStringMapString implementation to handle such case.

Also, during the bootstrap, if there is any flag having invalid value,
fatal log will be printed for early detection and awareness.

Relates spf13/viper#911
Fixes #18328

Signed-off-by: Tam Mach <tam.mach@isovalent.com>
Signed-off-by: Jussi Maki <jussi@isovalent.com>
joamaki pushed a commit that referenced this issue Feb 8, 2022
[ upstream commit 768659f ]

As mentioned in below upstream issue, there is a discrepancy in viper
while reading string map string data type i.e. kv pair format was not
supported, only `{"k":"v"}` format is allowed. This commit is to wrap
GetStringMapString implementation to handle such case.

Also, during the bootstrap, if there is any flag having invalid value,
fatal log will be printed for early detection and awareness.

Relates spf13/viper#911
Fixes #18328

Signed-off-by: Tam Mach <tam.mach@isovalent.com>
Signed-off-by: Jussi Maki <jussi@isovalent.com>
gandro added a commit to gandro/cilium that referenced this issue Mar 17, 2022
Because string map options are configured `flags.Var`, they are assigned
twice: Once in `flags.Var`, and then again in `option.Config.Populate()`
with `GetStringMapString`. The latter is needed because it works around
a viper bug where ConfigMap options were not properly parsed
(cilium#18328). This commit ensures we're always using the result
of the fallback parser, which fixes a bug where a ConfigMap value of
`{}` was parsed as `map["{}":""]`.

Fixes: 768659f ("cmd: Fix issue reading string map type via config map")

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
qmonnet pushed a commit that referenced this issue Mar 28, 2022
Because string map options are configured `flags.Var`, they are assigned
twice: Once in `flags.Var`, and then again in `option.Config.Populate()`
with `GetStringMapString`. The latter is needed because it works around
a viper bug where ConfigMap options were not properly parsed
(#18328). This commit ensures we're always using the result
of the fallback parser, which fixes a bug where a ConfigMap value of
`{}` was parsed as `map["{}":""]`.

Fixes: 768659f ("cmd: Fix issue reading string map type via config map")

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
qmonnet pushed a commit that referenced this issue Mar 29, 2022
[ upstream commit 96e7fa6 ]

Because string map options are configured `flags.Var`, they are assigned
twice: Once in `flags.Var`, and then again in `option.Config.Populate()`
with `GetStringMapString`. The latter is needed because it works around
a viper bug where ConfigMap options were not properly parsed
(#18328). This commit ensures we're always using the result
of the fallback parser, which fixes a bug where a ConfigMap value of
`{}` was parsed as `map["{}":""]`.

Fixes: 768659f ("cmd: Fix issue reading string map type via config map")

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
Signed-off-by: Quentin Monnet <quentin@isovalent.com>
qmonnet pushed a commit that referenced this issue Mar 30, 2022
[ upstream commit 96e7fa6 ]

Because string map options are configured `flags.Var`, they are assigned
twice: Once in `flags.Var`, and then again in `option.Config.Populate()`
with `GetStringMapString`. The latter is needed because it works around
a viper bug where ConfigMap options were not properly parsed
(#18328). This commit ensures we're always using the result
of the fallback parser, which fixes a bug where a ConfigMap value of
`{}` was parsed as `map["{}":""]`.

Fixes: 768659f ("cmd: Fix issue reading string map type via config map")

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
Signed-off-by: Quentin Monnet <quentin@isovalent.com>
qmonnet pushed a commit that referenced this issue Mar 30, 2022
[ upstream commit 96e7fa6 ]

Because string map options are configured `flags.Var`, they are assigned
twice: Once in `flags.Var`, and then again in `option.Config.Populate()`
with `GetStringMapString`. The latter is needed because it works around
a viper bug where ConfigMap options were not properly parsed
(#18328). This commit ensures we're always using the result
of the fallback parser, which fixes a bug where a ConfigMap value of
`{}` was parsed as `map["{}":""]`.

Fixes: 768659f ("cmd: Fix issue reading string map type via config map")

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
Signed-off-by: Quentin Monnet <quentin@isovalent.com>
qmonnet pushed a commit that referenced this issue Apr 4, 2022
[ upstream commit 96e7fa6 ]

Because string map options are configured `flags.Var`, they are assigned
twice: Once in `flags.Var`, and then again in `option.Config.Populate()`
with `GetStringMapString`. The latter is needed because it works around
a viper bug where ConfigMap options were not properly parsed
(#18328). This commit ensures we're always using the result
of the fallback parser, which fixes a bug where a ConfigMap value of
`{}` was parsed as `map["{}":""]`.

Fixes: 768659f ("cmd: Fix issue reading string map type via config map")

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
Signed-off-by: Quentin Monnet <quentin@isovalent.com>
pchaigno pushed a commit that referenced this issue Apr 4, 2022
[ upstream commit 96e7fa6 ]

Because string map options are configured `flags.Var`, they are assigned
twice: Once in `flags.Var`, and then again in `option.Config.Populate()`
with `GetStringMapString`. The latter is needed because it works around
a viper bug where ConfigMap options were not properly parsed
(#18328). This commit ensures we're always using the result
of the fallback parser, which fixes a bug where a ConfigMap value of
`{}` was parsed as `map["{}":""]`.

Fixes: 768659f ("cmd: Fix issue reading string map type via config map")

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
Signed-off-by: Quentin Monnet <quentin@isovalent.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cli Impacts the command line interface of any command in the repository. kind/bug This is a bug in the Cilium logic.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants