openshift/openshift-restclient-python

ResourceNotUniqueError returned when really it's ResourceNotFound

Closed this issue · 7 comments

Short test case for openshift

docker run -d -p 8443:8443 --name openshift-origin  openshift/origin:v3.9 start master --listen https://0.0.0.0:8443
docker exec openshift-origin cat /var/lib/origin/openshift.local.config/master/admin.kubeconfig | sed 's/172\.17\.0\.2/127.0.0.1/'g  > ~/.kube/oo.config
from kubernetes import config
from openshift.dynamic import DynamicClient
import os
import yaml

k8s_client = config.new_client_from_config(config_file=os.path.expanduser("~/.kube/oo.config"))
dyn_client = DynamicClient(k8s_client)

service = dyn_client.resources.get(api_version='v1', short_names=["doesnotexist"])
data = yaml.safe_load(open("test.yaml"))
resp = dyn_client.apply(service, body=data, namespace="test")
Traceback (most recent call last):
  File "namespace.py", line 9, in <module>
    service = dyn_client.resources.get(api_version='v1', short_names=["doesnotexist"])
  File "/Users/will/venv/openshift-0.9.0/lib/python3.7/site-packages/openshift/dynamic/client.py", line 753, in get
    results = self.search(**kwargs)
  File "/Users/will/venv/openshift-0.9.0/lib/python3.7/site-packages/openshift/dynamic/client.py", line 794, in search
    results = self.__search(self.__build_search(**kwargs), self.__resources, [])
  File "/Users/will/venv/openshift-0.9.0/lib/python3.7/site-packages/openshift/dynamic/client.py", line 836, in __search
    matches.extend(self.__search([key] + parts[1:], resources, reqParams))
  File "/Users/will/venv/openshift-0.9.0/lib/python3.7/site-packages/openshift/dynamic/client.py", line 822, in __search
    return self.__search(parts[1:], resourcePart, reqParams + [part] )
  File "/Users/will/venv/openshift-0.9.0/lib/python3.7/site-packages/openshift/dynamic/client.py", line 836, in __search
    matches.extend(self.__search([key] + parts[1:], resources, reqParams))
  File "/Users/will/venv/openshift-0.9.0/lib/python3.7/site-packages/openshift/dynamic/client.py", line 822, in __search
    return self.__search(parts[1:], resourcePart, reqParams + [part] )
  File "/Users/will/venv/openshift-0.9.0/lib/python3.7/site-packages/openshift/dynamic/client.py", line 818, in __search
    return self.__search(parts[1:], resourcePart.resources, reqParams)
  File "/Users/will/venv/openshift-0.9.0/lib/python3.7/site-packages/openshift/dynamic/client.py", line 836, in __search
    matches.extend(self.__search([key] + parts[1:], resources, reqParams))
  File "/Users/will/venv/openshift-0.9.0/lib/python3.7/site-packages/openshift/dynamic/client.py", line 827, in __search
    if getattr(_resource, term) == value:
  File "/Users/will/venv/openshift-0.9.0/lib/python3.7/site-packages/openshift/dynamic/client.py", line 524, in __getattr__
    if self.base_resource():
  File "/Users/will/venv/openshift-0.9.0/lib/python3.7/site-packages/openshift/dynamic/client.py", line 421, in base_resource
    self.__base_resource = self.client.resources.get(group=self.group, api_version=self.api_version, kind=self.base_kind)
  File "/Users/will/venv/openshift-0.9.0/lib/python3.7/site-packages/openshift/dynamic/client.py", line 767, in get
    raise ResourceNotUniqueError('Multiple matches found for {}: {}'.format(kwargs, results))
openshift.dynamic.exceptions.ResourceNotUniqueError: Multiple matches found for {'group': '', 'api_version': 'v1', 'kind': 'Template'}: [<Resource(v1/processedtemplates)>, <Resource(v1/templates)>]

Compared to native kubernetes (here, docker-for-desktop)

Traceback (most recent call last):
  File "namespace.py", line 10, in <module>
    service = dyn_client.resources.get(api_version='v1', short_names=["doesnotexist"])
  File "/Users/will/venv/openshift-0.9.0/lib/python3.7/site-packages/openshift/dynamic/client.py", line 765, in get
    raise ResourceNotFoundError('No matches found for {}'.format(kwargs))
openshift.dynamic.exceptions.ResourceNotFoundError: No matches found for {'api_version': 'v1', 'short_names': ['doesnotexist]}

Similar to what is described here, in #270 and here ansible/ansible#55221, using sts in the k8s module in Ansible worked with kubernetes 7.0.1 and openshift 0.7.2 modules, but fails in kubernetes 8.0.1 and openshift 0.8.8 modules along with kubernetes 9.x and openshift 0.9.0 modules.

Changing sts to StatefulSet allows the k8s module to function under kubernetes 9.x and openshift 0.9.0 modules.

wow that is bizarre, why are we returning templates in that search?

Issues go stale after 90d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.
Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle stale

Stale issues rot after 30d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.
Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle rotten
/remove-lifecycle stale

Rotten issues close after 30d of inactivity.

Reopen the issue by commenting /reopen.
Mark the issue as fresh by commenting /remove-lifecycle rotten.
Exclude this issue from closing again by commenting /lifecycle frozen.

/close

@openshift-bot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity.

Reopen the issue by commenting /reopen.
Mark the issue as fresh by commenting /remove-lifecycle rotten.
Exclude this issue from closing again by commenting /lifecycle frozen.

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.