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
This commit is contained in:
parent
7894021931
commit
5c855d9611
|
@ -58,6 +58,10 @@ class K8sUnprocessableEntity(K8sClientException):
|
||||||
"Unprocessable: %r" % message)
|
"Unprocessable: %r" % message)
|
||||||
|
|
||||||
|
|
||||||
|
class K8sFieldValueForbidden(K8sUnprocessableEntity):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class InvalidKuryrNetworkAnnotation(Exception):
|
class InvalidKuryrNetworkAnnotation(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -88,6 +88,12 @@ class K8sClient(object):
|
||||||
raise exc.K8sNamespaceTerminating(response.text)
|
raise exc.K8sNamespaceTerminating(response.text)
|
||||||
raise exc.K8sForbidden(response.text)
|
raise exc.K8sForbidden(response.text)
|
||||||
if response.status_code == requests.codes.unprocessable_entity:
|
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)
|
raise exc.K8sUnprocessableEntity(response.text)
|
||||||
if not response.ok:
|
if not response.ok:
|
||||||
raise exc.K8sClientException(response.text)
|
raise exc.K8sClientException(response.text)
|
||||||
|
@ -261,7 +267,7 @@ class K8sClient(object):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._raise_from_response(response)
|
self._raise_from_response(response)
|
||||||
except (exc.K8sForbidden, exc.K8sResourceNotFound):
|
except (exc.K8sFieldValueForbidden, exc.K8sResourceNotFound):
|
||||||
# Object is being deleting or gone. Return.
|
# Object is being deleting or gone. Return.
|
||||||
return False
|
return False
|
||||||
except exc.K8sConflict:
|
except exc.K8sConflict:
|
||||||
|
@ -306,8 +312,8 @@ class K8sClient(object):
|
||||||
self._raise_from_response(response)
|
self._raise_from_response(response)
|
||||||
except exc.K8sConflict:
|
except exc.K8sConflict:
|
||||||
obj = self.get(path)
|
obj = self.get(path)
|
||||||
except exc.K8sResourceNotFound:
|
except (exc.K8sFieldValueForbidden, exc.K8sResourceNotFound):
|
||||||
# Object is gone already, stop.
|
# Object is being deleted or gone already, stop.
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# If after 3 iterations there's still conflict, just raise.
|
# If after 3 iterations there's still conflict, just raise.
|
||||||
|
|
Loading…
Reference in New Issue