Fix CNI_COMMAND=VERSION case

In case of VERSION command k8s v1.16 and higher sends
only {"cniVersion": "0.4.0"} to the stdio, but kuryr-cni
expected cni-conf with kuryr_conf field.

Also k8s expects json in the stdio, but logs was also there.
So need to strictly redirect it into stderr in this case.

It's a work around, because maintanable way here is to use
golang's version based on containernetworking library.

Change-Id: I9095ced11f78eb1ae2890883fa6da4df74213480
Signed-off-by: Alexey Perevalov <a.perevalov@samsung.com>
This commit is contained in:
Alexey Perevalov 2019-10-11 14:00:57 +03:00
parent a5dafba3e6
commit 76fa78cfde
2 changed files with 4 additions and 1 deletions

View File

@ -40,7 +40,8 @@ def run():
else:
d = jsonutils.load(sys.stdin)
cni_conf = utils.CNIConfig(d)
args = ['--config-file', cni_conf.kuryr_conf]
args = (['--config-file', cni_conf.kuryr_conf] if 'kuryr_conf' in d
else [])
try:
if cni_conf.debug:

View File

@ -329,6 +329,8 @@ logging.register_options(CONF)
def init(args, **kwargs):
version_k8s = version.version_info.version_string()
CONF(args=args, project='kuryr-k8s', version=version_k8s, **kwargs)
if os.environ.get('CNI_COMMAND') == 'VERSION':
CONF.set_default('use_stderr', True)
def setup_logging():