krane
krane copied to clipboard
kubernetes-run doesn't not work as described in documentation
Bug report
I have deployed a PodTemplate to my namespace and I'm trying to run it from command-line using the Usage documentation. It works fine when I use an executable from my project's bin
directory but fails when I try to use rake with arguments.
Either this is a bug in CLI or I'm trying to use it incorrectly. If latter then documentation update is enough.
kubernetes-run my-kube-namespace my-kube-context "--tasks" --template=task-runner-template --max-watch-seconds=86400 --entrypoint=bin/rake
Expected behavior:
[INFO][2019-08-20 10:53:18 +0300]
[INFO][2019-08-20 10:53:18 +0300] -------------------------------------Phase 1: Initializing task-------------------------------------
[INFO][2019-08-20 10:53:18 +0300] Validating configuration
[INFO][2019-08-20 10:53:18 +0300] Using namespace 'my-kube-namespace' in context 'my-kube-context'
[INFO][2019-08-20 10:53:19 +0300] Using template 'task-runner-template'
[INFO][2019-08-20 10:53:19 +0300]
[INFO][2019-08-20 10:53:19 +0300] ----------------------------------------Phase 2: Running pod----------------------------------------
[INFO][2019-08-20 10:53:19 +0300] Creating pod 'task-runner-6adf88dc7e4b7047'
[INFO][2019-08-20 10:53:19 +0300] Pod creation succeeded
[INFO][2019-08-20 10:53:19 +0300]
[INFO][2019-08-20 10:53:19 +0300] --------------------------------------Phase 3: Streaming logs---------------------------------------
[INFO][2019-08-20 10:53:19 +0300] Streaming logs from Pod/task-runner-6adf88dc7e4b7047 container 'task-runner':
[INFO][2019-08-20 10:53:40 +0300] [2019-08-20 07:53:35 +0000] No valid API key has been set, notifications will not be sent
[INFO][2019-08-20 10:53:40 +0300] rake about # List versions of all Rails frameworks and the environment
...
[INFO][2019-08-20 10:53:40 +0300] Running via Spring preloader in process 22
[INFO][2019-08-20 10:53:41 +0300] Successfully ran in 22.5s: Pod/task-runner-6adf88dc7e4b7047
[INFO][2019-08-20 10:53:41 +0300]
[INFO][2019-08-20 10:53:41 +0300] ------------------------------------------Result: SUCCESS-------------------------------------------
[INFO][2019-08-20 10:53:41 +0300] Successfully ran 1 resource
[INFO][2019-08-20 10:53:41 +0300]
[INFO][2019-08-20 10:53:41 +0300] Successful resources
[INFO][2019-08-20 10:53:41 +0300] Pod/task-runner-6adf88dc7e4b7047 Succeeded
Actual behavior: [What actually happened]
Namespace and context are omited from ARGV
and args
is not handled as expected.
kubernetes-run: invalid option: --tasks
[INFO][2019-08-20 10:54:47 +0300]
[INFO][2019-08-20 10:54:47 +0300] -------------------------------------Phase 1: Initializing task-------------------------------------
[INFO][2019-08-20 10:54:47 +0300] Validating configuration
[INFO][2019-08-20 10:54:47 +0300]
[INFO][2019-08-20 10:54:47 +0300] ------------------------------------------Result: FAILURE-------------------------------------------
[FATAL][2019-08-20 10:54:47 +0300] Configuration invalid
[FATAL][2019-08-20 10:54:47 +0300]
[FATAL][2019-08-20 10:54:47 +0300] - Could not connect to kubernetes cluster - context invalid
Version(s) affected:
v0.26.7
Steps to Reproduce
- Create Rails project
- Create PodTemplate to your namespace
- Try to run a rake task with any arguments
I got it working by moving arguments after options and using an argument that doesn't have dashes.
This works as expected:
kubernetes-run my-kube-namespace my-kube-context --template=task-runner-template --max-watch-seconds=86400 --entrypoint=bin/rake db:migrate:status
I'd suggest two things based on this:
1. Move
From:
kubernetes-run <kube namespace> <kube context> <arguments> --entrypoint=<entrypoint> --template=<template name>
To
kubernetes-run <kube namespace> <kube context>--entrypoint=<entrypoint> --template=<template name> <arguments>
Arguments are not optional so a real life use case would help. Ie. Pass arguments as ""
if you don't need them for entrypoint.
2. Figure out how to pass arguments as options.
Ie. rake --tasks
doesn't work however I try to pass it from cli.
Thanks for the bug report @aom ! I'm not able to reproduce the first issue (putting arguments, even more than one, right after the namespace and context is working fine for me--see below), but the second one is definitely a problem. Unfortunately, I was not able to find a workaround. It seems to be a problem with optparse itself. Fortunately, our team is working on revamping this project's CLI right now, and as part of that, we have some changes planned for kubernetes-run
in particular that will fix this. Specifically, the new version of them command will use a flag for arguments, and that flag will not be required. For more information on these plans, see our tracking issue and design document.
Output from failure to reproduce positional problem
༶ kubernetes-run knverey-test docker-desktop "hello:there" ":world" --template=hello-cloud-template-runner --entrypoint="echo"
[INFO][2019-08-22 12:35:33 -0400]
[INFO][2019-08-22 12:35:33 -0400] -------------------------------------Phase 1: Initializing task-------------------------------------
[INFO][2019-08-22 12:35:33 -0400] Validating configuration
[INFO][2019-08-22 12:35:33 -0400] Using namespace 'knverey-test' in context 'docker-desktop'
[INFO][2019-08-22 12:35:33 -0400] Using template 'hello-cloud-template-runner'
[INFO][2019-08-22 12:35:33 -0400]
[INFO][2019-08-22 12:35:33 -0400] ----------------------------------------Phase 2: Running pod----------------------------------------
[INFO][2019-08-22 12:35:33 -0400] Creating pod 'task-runner-c74e30f0bb525002'
[INFO][2019-08-22 12:35:33 -0400] Pod creation succeeded
[INFO][2019-08-22 12:35:33 -0400]
[INFO][2019-08-22 12:35:33 -0400] --------------------------------------Phase 3: Streaming logs---------------------------------------
[INFO][2019-08-22 12:35:35 -0400] hello:there :world
[INFO][2019-08-22 12:35:35 -0400] Successfully ran in 2.3s: Pod/task-runner-c74e30f0bb525002
[INFO][2019-08-22 12:35:35 -0400]
[INFO][2019-08-22 12:35:35 -0400] ------------------------------------------Result: SUCCESS-------------------------------------------
[INFO][2019-08-22 12:35:35 -0400] Successfully ran 1 resource
[INFO][2019-08-22 12:35:35 -0400]
[INFO][2019-08-22 12:35:35 -0400] Successful resources
[INFO][2019-08-22 12:35:35 -0400] Pod/task-runner-c74e30f0bb525002 Succeeded