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

k8s: Fix .to_dict not needed #56147

Open
wants to merge 1 commit into
base: devel
from

Conversation

Projects
None yet
4 participants
@jfrabaute
Copy link

commented May 6, 2019

SUMMARY

Fixes small bug in k8s module

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

k8s

ADDITIONAL INFORMATION

Trying to deploy a simple ConfigMap with the "k8s" module and "force" set to true sohuld reproduce the error.

jfrabaute referenced this pull request May 6, 2019

Add wait functionality to k8s module (#47493)
Provide wait and wait_timeout parameters and wait for certain
resource kinds to become available.
@ansibot

This comment has been minimized.

@willthames

This comment has been minimized.

Copy link
Contributor

commented May 7, 2019

There should be a test case for this under test/integration/targets/k8s - could you add one please?

I'm not 100% convinced this is correct in all cases (e.g. when wait is not set, result['result'] will be k8s_obj, which I'd think needs .to_dict), but a new test case along with the existing test suite should confirm if more changes are required (it may well be that the test suite doesn't check force)

@ansibot ansibot removed the needs_triage label May 7, 2019

@jfrabaute

This comment has been minimized.

Copy link
Author

commented May 7, 2019

There should be a test case for this under test/integration/targets/k8s - could you add one please?

Yes, I'll work on this. One question.
The README in this folder says:

cd test/integration/targets/k8s
./runme.sh -vv

But there is no "runme.sh" in this particular folder.
https://github.com/ansible/ansible/tree/devel/test/integration/targets/k8s

I'm not 100% convinced this is correct in all cases (e.g. when wait is not set, result['result'] will be k8s_obj, which I'd think needs .to_dict),

This is what was happening for me. I don't have "wait" set and it was raising an exception. I checked and "k8s_obj" is a dict when not set.
It is also a dict when set.

but a new test case along with the existing test suite should confirm if more changes are required (it may well be that the test suite doesn't check force)

I'll try to add a test on the existing code to reproduce the problem I was having.

@willthames

This comment has been minimized.

Copy link
Contributor

commented May 7, 2019

Yeah, that's a little out of date (I wrote the original README and then runme.sh got removed by someone else).

I think

cd test/integration/targets
ansible -m include_role -a name=k8s localhost

might do the trick but not 100% sure - I'll take a look later if not.

@willthames

This comment has been minimized.

Copy link
Contributor

commented May 7, 2019

The tests really aren't working very well at the moment, I'm disappointed that the result of the refactor wasn't properly tested.

I'll have a PR up for that shortly which will be a better basis for the tests needed for this PR

@willthames

This comment has been minimized.

Copy link
Contributor

commented May 7, 2019

I had to create #56163 for ansible -m include_role being broken

In the mean time I've been using the following playbook:

- hosts: localhost
  connection: local
  gather_facts: no
  vars:
    ansible_python_interpreter: "{{ ansible_playbook_python }}"
    k8s_openshift: no

  roles:
    - test/integration/targets/k8s

@ansibot ansibot added the stale_ci label May 16, 2019

@geerlingguy

This comment has been minimized.

Copy link
Contributor

commented May 17, 2019

I believe we may be running into this in some circumstances even when we are not using force; we're ending up with an error like:

TASK [Update the secret in the namespace] **************************************
task path: /var/jenkins_home/workspace/job-name/src/k8s-update-secret/main.yml:51
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: jenkins
<127.0.0.1> EXEC /bin/sh -c 'echo ~jenkins && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /var/jenkins_home/.ansible/tmp/ansible-tmp-1558125808.4-215671049649585 `" && echo ansible-tmp-1558125808.4-215671049649585="` echo /var/jenkins_home/.ansible/tmp/ansible-tmp-1558125808.4-215671049649585 `" ) && sleep 0'
<127.0.0.1> Attempting python interpreter discovery
<127.0.0.1> EXEC /bin/sh -c 'echo PLATFORM; uname; echo FOUND; command -v '"'"'/usr/bin/python'"'"'; command -v '"'"'python3.7'"'"'; command -v '"'"'python3.6'"'"'; command -v '"'"'python3.5'"'"'; command -v '"'"'python2.7'"'"'; command -v '"'"'python2.6'"'"'; command -v '"'"'/usr/libexec/platform-python'"'"'; command -v '"'"'/usr/bin/python3'"'"'; command -v '"'"'python'"'"'; echo ENDFOUND && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python && sleep 0'
<127.0.0.1> Python interpreter discovery fallback (unsupported Linux distribution: debian)
Using module file /usr/local/lib/python2.7/dist-packages/ansible/modules/clustering/k8s/k8s.py
<127.0.0.1> PUT /var/jenkins_home/.ansible/tmp/ansible-local-10668DHEDp3/tmpWKS8g0 TO /var/jenkins_home/.ansible/tmp/ansible-tmp-1558125808.4-215671049649585/AnsiballZ_k8s.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /var/jenkins_home/.ansible/tmp/ansible-tmp-1558125808.4-215671049649585/ /var/jenkins_home/.ansible/tmp/ansible-tmp-1558125808.4-215671049649585/AnsiballZ_k8s.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python /var/jenkins_home/.ansible/tmp/ansible-tmp-1558125808.4-215671049649585/AnsiballZ_k8s.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /var/jenkins_home/.ansible/tmp/ansible-tmp-1558125808.4-215671049649585/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/var/jenkins_home/.ansible/tmp/ansible-tmp-1558125808.4-215671049649585/AnsiballZ_k8s.py", line 114, in <module>
    _ansiballz_main()
  File "/var/jenkins_home/.ansible/tmp/ansible-tmp-1558125808.4-215671049649585/AnsiballZ_k8s.py", line 106, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/var/jenkins_home/.ansible/tmp/ansible-tmp-1558125808.4-215671049649585/AnsiballZ_k8s.py", line 49, in invoke_module
    imp.load_module('__main__', mod, module, MOD_DESC)
  File "/tmp/ansible_k8s_payload_UTeKfv/__main__.py", line 258, in <module>
  File "/tmp/ansible_k8s_payload_UTeKfv/__main__.py", line 254, in main
  File "/tmp/ansible_k8s_payload_UTeKfv/ansible_k8s_payload.zip/ansible/module_utils/k8s/raw.py", line 174, in execute_module
  File "/tmp/ansible_k8s_payload_UTeKfv/ansible_k8s_payload.zip/ansible/module_utils/k8s/raw.py", line 321, in perform_action
AttributeError: 'dict' object has no attribute 'to_dict'
@willthames

This comment has been minimized.

Copy link
Contributor

commented May 18, 2019

@geerlingguy if you're hitting it without force, that's a different issue and should be raised as such.

That said, I might have fixed your issue with #56168

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.