Browse Source

Added new K8sFieldValueForbidden exception.

During tests it turns out, that we didn't catch Forbidden exceptions,
since there was no forbidden http code sent from kubernetes API. In this
Patch we introduce new exception K8sFieldValueForbidden, which will be
raised on 422 Unprocessable Entity, k8s API returns.

Also, taken care of objects in state terminating in remove_finalizer
method.

Closes-Bug: 1895124
Change-Id: If4ac93190db3a56ee6b94ca122bfd2e95c29ffb9
changes/59/750959/4
Roman Dobosz 11 months ago
committed by Luis Tomas Bolivar
parent
commit
5c855d9611
  1. 4
      kuryr_kubernetes/exceptions.py
  2. 12
      kuryr_kubernetes/k8s_client.py

4
kuryr_kubernetes/exceptions.py

@ -58,6 +58,10 @@ class K8sUnprocessableEntity(K8sClientException):
"Unprocessable: %r" % message)
class K8sFieldValueForbidden(K8sUnprocessableEntity):
pass
class InvalidKuryrNetworkAnnotation(Exception):
pass

12
kuryr_kubernetes/k8s_client.py

@ -88,6 +88,12 @@ class K8sClient(object):
raise exc.K8sNamespaceTerminating(response.text)
raise exc.K8sForbidden(response.text)
if response.status_code == requests.codes.unprocessable_entity:
# NOTE(gryf): on k8s API code 422 is also Forbidden, but specified
# to FieldValueForbidden. Perhaps there are other usages for
# throwing unprocessable entity errors in different cases.
if ('FieldValueForbidden' in response.text and
'Forbidden' in response.json()['message']):
raise exc.K8sFieldValueForbidden(response.text)
raise exc.K8sUnprocessableEntity(response.text)
if not response.ok:
raise exc.K8sClientException(response.text)
@ -261,7 +267,7 @@ class K8sClient(object):
try:
self._raise_from_response(response)
except (exc.K8sForbidden, exc.K8sResourceNotFound):
except (exc.K8sFieldValueForbidden, exc.K8sResourceNotFound):
# Object is being deleting or gone. Return.
return False
except exc.K8sConflict:
@ -306,8 +312,8 @@ class K8sClient(object):
self._raise_from_response(response)
except exc.K8sConflict:
obj = self.get(path)
except exc.K8sResourceNotFound:
# Object is gone already, stop.
except (exc.K8sFieldValueForbidden, exc.K8sResourceNotFound):
# Object is being deleted or gone already, stop.
return False
# If after 3 iterations there's still conflict, just raise.

Loading…
Cancel
Save