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] Failed to find exact match for v1.DeploymentConfig by [kind, name, singularName, shortNames] #55221

Closed
amadeus-chuot opened this issue Apr 12, 2019 · 12 comments
Labels
affects_2.7 This issue/PR affects Ansible v2.7 bug This issue/PR relates to a bug. clustering Clustering category k8s module This issue/PR relates to a module. python3 support:community This issue/PR relates to code supported by the Ansible community. traceback This issue/PR includes a traceback.

Comments

@amadeus-chuot
Copy link

SUMMARY

I'm not able to use k8s to create a DeploymentConfig on Openshift 3.6.

Error messages are:

  • ResourceNotFoundError('No matches found for {}'.format(kwargs))
  • Failed to find exact match for v1.DeploymentConfig by [kind, name, singularName, shortNames]

Please help to fix or advise if it is not supported.

The same setup works when creating Pods or Secrets.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

k8s

ANSIBLE VERSION
ansible 2.7.10
  config file = None
  configured module search path = ['/Users/chuot/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/chuot/Dev/Ansible/ansible-virtualenv/lib/python3.6/site-packages/ansible
  executable location = /Users/chuot/Dev/Ansible/ansible-virtualenv/bin/ansible
  python version = 3.6.8 (default, Apr 11 2019, 22:58:09) [GCC 4.2.1 Compatible Clang 7.0.1 (tags/RELEASE_701/final)]
CONFIGURATION
(empty)
OS / ENVIRONMENT

MacOS 10.13.6

$ uname -a
Darwin NCELRND0546 17.7.0 Darwin Kernel Version 17.7.0: Thu Dec 20 21:47:19 PST 2018; root:xnu-4570.71.22~1/RELEASE_X86_64 x86_64 i386 MacBookPro14,1 Darwin

Gentoo Prefix

Virtualenv for ansible

STEPS TO REPRODUCE

Here is a small test config:

playbook.yml

---
- name: Test case for creating a DeploymentConfig with Ansible
  hosts: all
  gather_facts: no
  vars:
    k8s_url: https://172.30.19.49:8443/
    k8s_ns: myproject
    k8s_apikey: xxx
  tasks:
    - name: test DeploymentConfig
      delegate_to: 127.0.0.1
      run_once: true
      k8s:
        state: present
        resource_definition: "{{ lookup('template', 'test.yml') }}"
        host: "{{ k8s_url }}"
        namespace: "{{ k8s_ns }}"
        api_key: "{{ k8s_apikey }}"
        verify_ssl: false
...

test.yml:

kind: DeploymentConfig
apiVersion: v1
metadata:
  name: totoDc
spec:
  template:
    metadata:
      labels:
        name: totoTemplate
    spec:
      terminationGracePeriodSeconds: 120
      containers:
      - name: totoContainer
        image: my/image:thetag
        imagePullPolicy: IfNotPresent
  replicas: 1

and a minimalist inventory which is actually not used (since running on control node):
inventory:

[all]
toto
EXPECTED RESULTS

The DeploymentConfig should be created

ACTUAL RESULTS
$ ansible-playbook -i inventory -vvvv playbook.yml
ansible-playbook 2.7.10
  config file = None
  configured module search path = ['/Users/chuot/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/chuot/Dev/Ansible/ansible-virtualenv/lib/python3.6/site-packages/ansible
  executable location = /Users/chuot/Dev/Ansible/ansible-virtualenv/bin/ansible-playbook
  python version = 3.6.8 (default, Apr 11 2019, 22:58:09) [GCC 4.2.1 Compatible Clang 7.0.1 (tags/RELEASE_701/final)]
No config file found; using defaults
setting up inventory plugins
/Users/chuot/Dev/Ansible/oracle_observers/molecule/default/inventory did not meet host_list requirements, check plugin documentation if this is unexpected
/Users/chuot/Dev/Ansible/oracle_observers/molecule/default/inventory did not meet script requirements, check plugin documentation if this is unexpected
Parsed /Users/chuot/Dev/Ansible/oracle_observers/molecule/default/inventory inventory source with ini plugin
Loading callback plugin default of type stdout, v2.0 from /Users/chuot/Dev/Ansible/ansible-virtualenv/lib/python3.6/site-packages/ansible/plugins/callback/default.py

PLAYBOOK: playbook.yml **************************************************************************************************************************************************************
1 plays in playbook.yml

PLAY [Test case for creating a DeploymentConfig with Ansible] ***********************************************************************************************************************
META: ran handlers

TASK [test DeploymentConfig] ********************************************************************************************************************************************************
task path: /Users/chuot/Dev/Ansible/oracle_observers/molecule/default/playbook.yml:10
File lookup using /Users/chuot/Dev/Ansible/oracle_observers/templates/test.yml as file
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: chuot
<127.0.0.1> EXEC /bin/sh -c 'echo ~chuot && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /Users/chuot/.ansible/tmp/ansible-tmp-1555088971.376927-162544634893078 `" && echo ansible-tmp-1555088971.376927-162544634893078="` echo /Users/chuot/.ansible/tmp/ansible-tmp-1555088971.376927-162544634893078 `" ) && sleep 0'
Using module file /Users/chuot/Dev/Ansible/ansible-virtualenv/lib/python3.6/site-packages/ansible/modules/clustering/k8s/k8s.py
<127.0.0.1> PUT /Users/chuot/.ansible/tmp/ansible-local-33226s8wbs9mh/tmph00zv9rk TO /Users/chuot/.ansible/tmp/ansible-tmp-1555088971.376927-162544634893078/AnsiballZ_k8s.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /Users/chuot/.ansible/tmp/ansible-tmp-1555088971.376927-162544634893078/ /Users/chuot/.ansible/tmp/ansible-tmp-1555088971.376927-162544634893078/AnsiballZ_k8s.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/Users/chuot/Dev/Ansible/ansible-virtualenv/bin/python /Users/chuot/.ansible/tmp/ansible-tmp-1555088971.376927-162544634893078/AnsiballZ_k8s.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /Users/chuot/.ansible/tmp/ansible-tmp-1555088971.376927-162544634893078/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
  File "/var/folders/lq/mtrm60rd3xb75c4dv54rppk00000gp/T/ansible_k8s_payload_bchndbu9/ansible_k8s_payload.zip/ansible/module_utils/k8s/common.py", line 194, in find_resource
    return self.client.resources.get(api_version=api_version, short_names=[kind])
  File "/Users/chuot/Dev/Ansible/ansible-virtualenv/lib/python3.6/site-packages/openshift/dynamic/client.py", line 637, in get
    raise ResourceNotFoundError('No matches found for {}'.format(kwargs))

fatal: [toto -> 127.0.0.1]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "api_key": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "cert_file": null,
            "context": null,
            "force": false,
            "host": "https://172.30.19.49:8443/",
            "key_file": null,
            "kubeconfig": null,
            "merge_type": null,
            "password": null,
            "ssl_ca_cert": null,
            "state": "present",
            "username": null,
            "verify_ssl": false
        }
    },
    "msg": "Failed to find exact match for v1.DeploymentConfig by [kind, name, singularName, shortNames]"
}

NO MORE HOSTS LEFT ******************************************************************************************************************************************************************
	to retry, use: --limit @/Users/chuot/Dev/Ansible/oracle_observers/molecule/default/playbook.retry

PLAY RECAP **************************************************************************************************************************************************************************
toto                       : ok=0    changed=0    unreachable=0    failed=1
@ansibot
Copy link
Contributor

ansibot commented Apr 12, 2019

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented Apr 12, 2019

@ansibot ansibot added affects_2.7 This issue/PR affects Ansible v2.7 bug This issue/PR relates to a bug. clustering Clustering category k8s module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. python3 support:community This issue/PR relates to code supported by the Ansible community. traceback This issue/PR includes a traceback. labels Apr 12, 2019
@willthames
Copy link
Contributor

Can you add a task before that one with

- python_requirements_facts:
    dependencies:
      - openshift
      - kubernetes

I get a different response from openshift 3.6 (using openshift/origin:v3.6.1 container) so would be good to be able to reproduce your exact issue

@ansibot ansibot removed the needs_triage Needs a first human triage before being processed. label Apr 13, 2019
@willthames
Copy link
Contributor

Ah, reproduced it by upgrading my openshift to 0.8.7

@willthames
Copy link
Contributor

So, I've got to the bottom of this but I don't know what to do about it.

Basically in the /oapi/v1 response, both generatedeploymentconfig and deploymentconfig resources are of kind DeploymentConfig. When looking for what resource to use for kind DeploymentConfig, multiple resources are returned so a ResourceNotUniqueError error is returned (you can see this in the stack trace you provide).

generatedeploymentconfig is deprecated in openshift 3.7, 3.6 is an incredibly old openshift version, so I'm not sure what to do from here - @fabianvf might be able to help in the openshift/openshift-restclient-python repository

@willthames
Copy link
Contributor

willthames commented Apr 13, 2019

I can confirm this issue goes away running against openshift/origin:v3.7

It may still be worth addressing in case of future API changes, although I'd hope that the mappings are more consistent these days.

@amadeus-chuot
Copy link
Author

Thanks for confirming the issue and that it works with 3.7.
Just to be sure, you talk about ResourceNotUniqueError but my stack shows a ResourceNotFoundError?

I need to deploy in production on 3.6, before the upgrade to 3.7.
Can I tweak the namespace to hide this generatedeploymentconfig? Or do you think about any other workaround?

@amadeus-chuot
Copy link
Author

Also, since I'm finding nothing about this generatedeploymentconfig, I suppose nobody is using it and would it be possible to filter it out from the Ansible module?

@willthames
Copy link
Contributor

This problem should really be addressed upstream in the openshift library - we don't have enough control to filter this out.

If you're seeing ResourceNotFoundError then you may need a newer version of the openshift library.

@amadeus-chuot
Copy link
Author

Ok this is solved.

After digging into the openshift lib code, I found that search() was returning 3 objects:
[<Resource(v1/deploymentconfigs)>, <Resource(v1/generatedeploymentconfigs)>, <Resource(apps.openshift.io/v1/deploymentconfigs)>]

I managed to fix my issue by using apiVersion: apps.openshift.io/v1 instead of v1

Thanks for the help

@fabianvf
Copy link
Contributor

@amadeus-chuot thanks a ton for your additional investigation! I'll create a follow-up issue to surface these errors a little better, you shouldn't have to dig around manually to find that information.

@nhenderson
Copy link

nhenderson commented Jun 13, 2019

For anyone interested, here's a non-ideal work-around for my similar issue:

Failed to find exact match for v1.Template by [kind, name, singularName, shortNames]

It should work for the v1.DeploymentConfig issue as well:

- name: Create resources from OpenShift template
  shell: |
    oc create -n {{ openshift_project_name }} -f - <<-'EOF'
    {{ lookup('template', role_path + '/templates/main.yaml.j2') }}
    EOF

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.7 This issue/PR affects Ansible v2.7 bug This issue/PR relates to a bug. clustering Clustering category k8s module This issue/PR relates to a module. python3 support:community This issue/PR relates to code supported by the Ansible community. traceback This issue/PR includes a traceback.
Projects
None yet
Development

No branches or pull requests

5 participants