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

--cni-plugin-dir flag acts strangely #3862

Closed
haircommander opened this issue Jun 10, 2020 · 6 comments · Fixed by #3870
Closed

--cni-plugin-dir flag acts strangely #3862

haircommander opened this issue Jun 10, 2020 · 6 comments · Fixed by #3870
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines.

Comments

@haircommander
Copy link
Member

haircommander commented Jun 10, 2020

Description
in researching a fix for #3823, I found bug where we always overwrite the first plugin_dir to the values in a config file when using --cni-plugin-dir, instead of taking the cli as precedence

This is all with plugin_dirs defined in both /etc/crio/crio.conf and /etc/crio/crio.conf.d/00-default.conf:

grep -r plugin_dirs -A 3 /etc/crio/crio.conf*
/etc/crio/crio.conf:plugin_dirs = [
/etc/crio/crio.conf-	"/opt/cni/bin/",
/etc/crio/crio.conf-]
/etc/crio/crio.conf-
--
/etc/crio/crio.conf.d/00-default.conf:plugin_dirs = [
/etc/crio/crio.conf.d/00-default.conf-	"/opt/cni/bin/",
/etc/crio/crio.conf.d/00-default.conf-]

Describe the results you received:

$ ./bin/crio --cni-plugin-dir /tmp/a --cni-plugin-dir /tmp/b config | grep plugin_dirs -A 3
plugin_dirs = [
	"/opt/cni/bin/",
	"/tmp/b",
]
$ ./bin/crio --cni-plugin-dir /tmp/a  config | grep plugin_dirs -A 3
plugin_dirs = [
	"/opt/cni/bin/",
]

Describe the results you expected:

$ ./bin/crio --cni-plugin-dir /tmp/a --cni-plugin-dir /tmp/b config | grep plugin_dirs -A 3
plugin_dirs = [
	"/tmp/a",
	"/tmp/b",
]
$ ./bin/crio --cni-plugin-dir /tmp/a  config | grep plugin_dirs -A 3
plugin_dirs = [
	"/tmp/a",
]

Note: we get the correct output if we do:

./bin/crio -c "" -d "" --cni-plugin-dir /tmp/a config | grep plugin_dirs -A 3
INFO Using default capabilities: CAP_CHOWN, CAP_DAC_OVERRIDE, CAP_FSETID, CAP_FOWNER, CAP_SETGID, CAP_SETUID, CAP_SETPCAP, CAP_NET_BIND_SERVICE, CAP_KILL 
plugin_dirs = [
	"/tmp/a",
]


Output of crio --version:

./bin/crio -v
crio version 
Version:       1.19.0-dev
GitCommit:     588911bc60db9825a0aa85cd19f0acf56ac0d84c
GitTreeState:  dirty
BuildDate:     2020-06-09T20:37:27Z
GoVersion:     go1.14.2
Compiler:      gc
Platform:      linux/amd64
Linkmode:      dynamic

though I think I observed it as far back as 1.16

@haircommander haircommander added the good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. label Jun 10, 2020
@haircommander
Copy link
Member Author

I also suspect other slice config values behave similarly, probably should test them all in integration/unit tests...

@saschagrunert
Copy link
Member

@rhafer maybe wanna take this one? :)

@rhafer
Copy link
Contributor

rhafer commented Jun 10, 2020

@saschagrunert Yeah. I'll take a look.

@rhafer
Copy link
Contributor

rhafer commented Jun 11, 2020

It looks as if mergeConfig() is not really idempotent. Upon a subsequent calls it might overwrite some args in the cli context. And in the case of crio config it is actually called twice via GetConfigFromContext(). (here: https://github.com/cri-o/cri-o/blob/master/cmd/crio/main.go#L147 and here: https://github.com/cri-o/cri-o/blob/master/cmd/crio/config.go#L52). The same is true for crio wipe I think.

I don't think it is really needed to call it twice. The subcommands could just get the parsed config via app.Metadata I guess, that would also avoid parsing all config files twice.

Additionally I guess we should return a copy of the slice in StringSliceTrySplit() (https://github.com/cri-o/cri-o/blob/master/internal/criocli/criocli.go#L774) to avoid it being overwritten.

... working on a fix.

@saschagrunert
Copy link
Member

Sounds all good to me, thank you @rhafer 🙏

rhafer added a commit to rhafer/cri-o that referenced this issue Jun 12, 2020
Otherwise the underlying flags in the ctx might be overriden, which
can cause issue when the config is reloaded (or GetConfigFromContext()
is called more than once).

Closes cri-o#3862

Signed-off-by: Ralf Haferkamp <rhafer@suse.com>
rhafer added a commit to rhafer/cri-o that referenced this issue Jun 12, 2020
Up to now the `config` and `wipe` subcommands called
GetConfigFromContext() which is also already called during app startup.
Apart from being inefficient this also caused issues with StringSlice
values being handled wrong.

Closes cri-o#3862

Signed-off-by: Ralf Haferkamp <rhafer@suse.com>
rhafer added a commit to rhafer/cri-o that referenced this issue Jun 15, 2020
Otherwise the underlying flags in the ctx might be overriden, which
can cause issue when the config is reloaded (or GetConfigFromContext()
is called more than once).

Closes cri-o#3862

Signed-off-by: Ralf Haferkamp <rhafer@suse.com>
rhafer added a commit to rhafer/cri-o that referenced this issue Jun 15, 2020
This splits out the config file loading and commandline argument
processing from GetConfigFromContext() so that subcommand like `crio
config' and `crio wipe` are able to fetch the configuration from the
context without reloading the config files. Apart from being inefficient
this also caused issues with StringSlice values being handled wrong.

Closes cri-o#3862

Signed-off-by: Ralf Haferkamp <rhafer@suse.com>
rhafer added a commit to rhafer/cri-o that referenced this issue Jun 16, 2020
Otherwise the underlying flags in the ctx might be overriden, which
can cause issue when the config is reloaded (or GetConfigFromContext()
is called more than once).

Closes cri-o#3862

Signed-off-by: Ralf Haferkamp <rhafer@suse.com>
(cherry picked from commit 35a8caf)
rhafer added a commit to rhafer/cri-o that referenced this issue Jun 16, 2020
This splits out the config file loading and commandline argument
processing from GetConfigFromContext() so that subcommand like `crio
config' and `crio wipe` are able to fetch the configuration from the
context without reloading the config files. Apart from being inefficient
this also caused issues with StringSlice values being handled wrong.

Closes cri-o#3862

Signed-off-by: Ralf Haferkamp <rhafer@suse.com>
(cherry picked from commit 6b9dfc6)
@rhafer
Copy link
Contributor

rhafer commented Jun 16, 2020

#3880 backports this to 1.18. Does this issue qualify for backports to even older releases?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants