Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

k8s_exec should error if the process exit code isn't 0 #122

Closed
Yantrio opened this issue Jun 5, 2020 · 1 comment · Fixed by #158
Closed

k8s_exec should error if the process exit code isn't 0 #122

Yantrio opened this issue Jun 5, 2020 · 1 comment · Fixed by #158
Assignees
Labels
has_pr This issue has a related PR that may close it. type/enhancement New feature or request

Comments

@Yantrio
Copy link

Yantrio commented Jun 5, 2020

SUMMARY

At the moment if you run k8s_exec and the command returns a non 0 status code the task still returns a successful change. I think it should return an error.

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

k8s_exec

ADDITIONAL INFORMATION

This could solve issues for playbooks where commands could possibly fail, and carry on unknowningly.

- name: Cause an exit code by using command 'false'
  community.kubernetes.k8s_exec:
    namespace: default
    pod: "mypodname"
    command: "false"

- name: This should never fire due to the error above
  .....

My python isn't too amazing, and I'm not familiar with the python kubernetes client, but it looks like we could utillize something similar to this https://github.com/kubernetes-client/python-base/pull/160/files in the part that parses the stream in k8s_exec here:

while resp.is_open():
resp.update(timeout=1)
if resp.peek_stdout():
stdout.append(resp.read_stdout())
if resp.peek_stderr():
stderr.append(resp.read_stderr())
module.exit_json(
changed=True, stdout="".join(stdout), stderr="".join(stderr))

Due to this being released already also, this may have to be behind a property as to not break existing functionality in playbooks out there already.

I may try at implementing this and I'll put in a PR if I'm successful.

Akasurde added a commit to Akasurde/community.kubernetes that referenced this issue Jul 10, 2020
k8s_exec now returns command return code in output.

Fixes: ansible-collections#122

Signed-off-by: Abhijeet Kasurde <[email protected]>
Akasurde added a commit to Akasurde/community.kubernetes that referenced this issue Jul 10, 2020
k8s_exec now returns command return code in output.

Fixes: ansible-collections#122

Signed-off-by: Abhijeet Kasurde <[email protected]>
@Akasurde
Copy link
Member

@Yantrio I added rc in k8s_exec which returns the status code of the command, but this is changing the behavior of the module. Since we are rc affects ansible task status. Let me know if you want a toggle switch to enable this feature or not.

Thanks,

@Akasurde Akasurde self-assigned this Jul 10, 2020
@Akasurde Akasurde added type/enhancement New feature or request has_pr This issue has a related PR that may close it. and removed type/enhancement New feature or request labels Jul 10, 2020
Akasurde added a commit to Akasurde/community.kubernetes that referenced this issue Jul 11, 2020
k8s_exec now returns command return code in output.

Fixes: ansible-collections#122

Signed-off-by: Abhijeet Kasurde <[email protected]>
Akasurde added a commit that referenced this issue Jul 23, 2020
k8s_exec now returns command return code in output.

Fixes: #122

Signed-off-by: Abhijeet Kasurde <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
has_pr This issue has a related PR that may close it. type/enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants