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] Surface resource discovery errors properly #55388

Closed
fabianvf opened this issue Apr 16, 2019 · 8 comments
Closed

[k8s] Surface resource discovery errors properly #55388

fabianvf opened this issue Apr 16, 2019 · 8 comments
Labels
affects_2.9 This issue/PR affects Ansible v2.9 bot_closed bug This issue/PR relates to a bug. clustering Clustering category collection:community.kubernetes collection Related to Ansible Collections work commands Commands category files Files category k8s module This issue/PR relates to a module. needs_collection_redirect https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md support:community This issue/PR relates to code supported by the Ansible community.

Comments

@fabianvf
Copy link
Contributor

fabianvf commented Apr 16, 2019

SUMMARY

Follow up on #55221

When we aren't able to find a specific resource, we fail cryptically. We should report the results of our search in our failure message so that users don't need to dig around in the python code manually.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

k8s

ANSIBLE VERSION
ansible 2.7.7
  config file = /home/fabian/.ansible.cfg
  configured module search path = [u'/home/fabian/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/fabian/.local/lib/python2.7/site-packages/ansible
  executable location = /home/fabian/.local/bin/ansible
  python version = 2.7.15 (default, May 15 2018, 15:37:31) [GCC 7.3.1 20180303 (Red Hat 7.3.1-5)]
STEPS TO REPRODUCE
  - k8s:
      definition:
        kind: Deployment
        apiVersion: v1beta1
        metadata:
          name: test
          namespace: default
        spec:
          selector:
            matchLabels:
              app: test
          template:
            metadata:
              labels:
                app: test
            spec:
              containers:
                - image: busybox
                  name: busybox
                  command:
                    - sleep
                    - "600"
EXPECTED RESULTS

Fails, with a message that explains that a v1beta1.Deployment resource was found in both extensions and apps api groups

ACTUAL RESULTS
TASK [k8s] ***************************************************************************************
fatal: [127.0.0.1]: FAILED! => changed=false 
  msg: Failed to find exact match for v1beta1.Deployment by [kind, name, singularName, shortNames]
@ansibot
Copy link
Contributor

ansibot commented Apr 16, 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 16, 2019

@fabianvf: Greetings! Thanks for taking the time to open this issue. In order for the community to handle your issue effectively, we need a bit more information.

Here are the items we could not find in your description:

  • ansible version

Please set the description of this issue with this template:
https://raw.githubusercontent.com/ansible/ansible/devel/.github/ISSUE_TEMPLATE.md

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented Apr 16, 2019

@ansibot ansibot added affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. clustering Clustering category commands Commands category files Files category k8s module This issue/PR relates to a module. needs_info This issue requires further information. Please answer any outstanding questions. needs_template This issue/PR has an incomplete description. Please fill in the proposed template correctly. needs_triage Needs a first human triage before being processed. support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Apr 16, 2019
@ansibot
Copy link
Contributor

ansibot commented Apr 16, 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 ansibot removed needs_info This issue requires further information. Please answer any outstanding questions. needs_template This issue/PR has an incomplete description. Please fill in the proposed template correctly. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Apr 16, 2019
@willthames
Copy link
Contributor

I'm not sure this issue properly captures the whole problem with DeploymentConfig, but that only really affects Openshift 3.6 and earlier.

@lucastheisen
Copy link

I think i just ran into this with Template after updating to 0.8.8 of openshift/openshift-restclient-python. It worked fine with 0.8.6, but now i get:

TASK [cluster-etl : Deploy job atsapetlcli template] ***********************************************************************************************************************************************************************************************************************************************************************************************
task path: /mnt/c/Users/ltheisen/git/asiasetl-asias-etl-ansible/roles/cluster-etl/tasks/deploy-job.yml:11
Friday 07 June 2019  18:20:26 -0400 (0:00:00.106)       0:00:22.843 ***********
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/clustering/k8s/k8s.py
Pipelining is enabled.
<okd-load.mitre.org> ESTABLISH LOCAL CONNECTION FOR USER: ltheisen
<okd-load.mitre.org> EXEC /bin/sh -c '/usr/bin/python && sleep 0'
The full traceback is:
WARNING: The below traceback may *not* be related to the actual failure.
  File "/tmp/ansible_k8s_payload_vRHA_O/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 "/home/ltheisen/.local/lib/python2.7/site-packages/openshift/dynamic/client.py", line 641, in get
    raise ResourceNotFoundError('No matches found for {}'.format(kwargs))

fatal: [okd-load.mitre.org]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "api_key": null,
            "api_version": "v1",
            "append_hash": false,
            "ca_cert": null,
            "client_cert": null,
            "client_key": null,
            "context": "asias-etl/okd-load-mitre-org:8443/ltheisen",
            "definition": {
                "apiVersion": "template.openshift.io/v1",
                "kind": "Template",
                "labels": {
                    "app": "asias-etl-atsap"
                },
                "metadata": {
                    "name": "asias-etl-atsap"
                },
                "objects": [
                    {
                        "apiVersion": "batch/v1",
                        "kind": "Job",
                        "metadata": {
                            "name": "${JOB_NAME}"
                        },
                        "spec": {
                            "completions": 1,
                            "parallelism": 1,
                            "template": {
                                "metadata": {
                                    "annotations": {
                                        "alpha.image.policy.openshift.io/resolve-names": "*"
                                    },
                                    "name": "${JOB_NAME}"
                                },
                                "spec": {
                                    "containers": [
                                        {
                                            "args": "${{JOB_ARGS}}",
                                            "env": [
                                                {
                                                    "name": "CONFIG_MODE",
                                                    "value": "confd"
                                                }
                                            ],
                                            "image": "asias-etl-atsap",
                                            "name": "${JOB_NAME}",
                                            "resources": {
                                                "requests": {
                                                    "cpu": "100m",
                                                    "memory": "10M"
                                                }
                                            },
                                            "volumeMounts": [
                                                {
                                                    "mountPath": "/etc/confd/.container/secrets",
                                                    "name": "app-confd-secrets-asias-etl-atsap-secret-volume",
                                                    "readOnly": true
                                                }
                                            ]
                                        }
                                    ],
                                    "restartPolicy": "OnFailure",
                                    "volumes": [
                                        {
                                            "name": "app-confd-secrets-asias-etl-atsap-secret-volume",
                                            "secret": {
                                                "defaultMode": 420,
                                                "secretName": "app-confd-secrets-asias-etl-atsap"
                                            }
                                        }
                                    ]
                                }
                            }
                        }
                    }
                ],
                "parameters": [
                    {
                        "description": "Job name",
                        "from": "atsapetlcli-[a-z0-9]{5}",
                        "generate": "expression",
                        "name": "JOB_NAME"
                    },
                    {
                        "description": "Command line parameters for atsapetlcli",
                        "name": "JOB_ARGS",
                        "required": true,
                        "value": "[\"--help\"]"
                    }
                ]
            },
            "force": false,
            "host": null,
            "kind": null,
            "kubeconfig": null,
            "merge_type": null,
            "name": null,
            "namespace": "asias-etl",
            "password": null,
            "resource_definition": {
                "apiVersion": "template.openshift.io/v1",
                "kind": "Template",
                "labels": {
                    "app": "asias-etl-atsap"
                },
                "metadata": {
                    "name": "asias-etl-atsap"
                },
                "objects": [
                    {
                        "apiVersion": "batch/v1",
                        "kind": "Job",
                        "metadata": {
                            "name": "${JOB_NAME}"
                        },
                        "spec": {
                            "completions": 1,
                            "parallelism": 1,
                            "template": {
                                "metadata": {
                                    "annotations": {
                                        "alpha.image.policy.openshift.io/resolve-names": "*"
                                    },
                                    "name": "${JOB_NAME}"
                                },
                                "spec": {
                                    "containers": [
                                        {
                                            "args": "${{JOB_ARGS}}",
                                            "env": [
                                                {
                                                    "name": "CONFIG_MODE",
                                                    "value": "confd"
                                                }
                                            ],
                                            "image": "asias-etl-atsap",
                                            "name": "${JOB_NAME}",
                                            "resources": {
                                                "requests": {
                                                    "cpu": "100m",
                                                    "memory": "10M"
                                                }
                                            },
                                            "volumeMounts": [
                                                {
                                                    "mountPath": "/etc/confd/.container/secrets",
                                                    "name": "app-confd-secrets-asias-etl-atsap-secret-volume",
                                                    "readOnly": true
                                                }
                                            ]
                                        }
                                    ],
                                    "restartPolicy": "OnFailure",
                                    "volumes": [
                                        {
                                            "name": "app-confd-secrets-asias-etl-atsap-secret-volume",
                                            "secret": {
                                                "defaultMode": 420,
                                                "secretName": "app-confd-secrets-asias-etl-atsap"
                                            }
                                        }
                                    ]
                                }
                            }
                        }
                    }
                ],
                "parameters": [
                    {
                        "description": "Job name",
                        "from": "atsapetlcli-[a-z0-9]{5}",
                        "generate": "expression",
                        "name": "JOB_NAME"
                    },
                    {
                        "description": "Command line parameters for atsapetlcli",
                        "name": "JOB_ARGS",
                        "required": true,
                        "value": "[\"--help\"]"
                    }
                ]
            },
            "src": null,
            "state": "present",
            "username": null,
            "validate": null,
            "validate_certs": false,
            "verify_ssl": false,
            "wait": false,
            "wait_condition": null,
            "wait_timeout": 120
        }
    },
    "msg": "Failed to find exact match for template.openshift.io/v1.Template by [kind, name, singularName, shortNames]"
}

I tried both v1 and template.openshift.io/v1 for both api_version and definition.apiVersion. My oc client reports that the existing (added using 0.8.6) has apiVersion template.openshift.io/v1:

ltheisen@MM233009-PC:~/git/asiasetl-asias-etl-ansible$ oc -n asias-etl get template asias-etl-atsap -o "jsonpath={.apiVersion}"
template.openshift.io/v1

but was originally inserted using apiVersion: v1.

@lucastheisen
Copy link

@fabianvf , i monkey-patched my module_utls/k8s/common.py to simply print out the exception at the end of the message:

195         except (ResourceNotFoundError, ResourceNotUniqueError) as e:
196             if fail:
197                 self.fail(msg='Failed to find exact match for {0}.{1} by [kind, name, singularName, shortNames]: {2}'.format(api_version, kind, e))

It works, though you may want to just provide different messages for each exception type. In any case, surfacing the true error would have eliminated hours of digging through source to figure out i am running into this issue where there are 2 distinct types for kind=Template.

@ansibot ansibot added collection Related to Ansible Collections work collection:community.kubernetes needs_collection_redirect https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md labels Apr 29, 2020
@ansibot
Copy link
Contributor

ansibot commented Aug 16, 2020

Thank you very much for your interest in Ansible. Ansible has migrated much of the content into separate repositories to allow for more rapid, independent development. We are closing this issue/PR because this content has been moved to one or more collection repositories.

For further information, please see:
https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md

@ansibot ansibot closed this as completed Aug 16, 2020
@ansible ansible locked and limited conversation to collaborators Sep 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.9 This issue/PR affects Ansible v2.9 bot_closed bug This issue/PR relates to a bug. clustering Clustering category collection:community.kubernetes collection Related to Ansible Collections work commands Commands category files Files category k8s module This issue/PR relates to a module. needs_collection_redirect https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md support:community This issue/PR relates to code supported by the Ansible community.
Projects
None yet
Development

No branches or pull requests

4 participants