Skip to content

Commit

Permalink
fix k8s request (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
fred-labs committed Sep 10, 2024
1 parent 4c94f2f commit 929197f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def update(self) -> py_trees.common.Status: # pylint: disable=too-many-return-s
self.current_state = KubernetesBaseActionState.REQUEST_SENT
return py_trees.common.Status.RUNNING
elif self.current_state == KubernetesBaseActionState.REQUEST_SENT:
success = True
if self.current_request.ready():
if not self.current_request.successful():
try:
Expand All @@ -64,11 +63,10 @@ def update(self) -> py_trees.common.Status: # pylint: disable=too-many-return-s
if "message" in body:
message = f", message: '{body['message']}'"
self.feedback_message = f"Failure! Reason: {e.reason} {message}" # pylint: disable= attribute-defined-outside-init
success = False
if success:
return py_trees.common.Status.FAILURE
return py_trees.common.Status.SUCCESS
else:
return py_trees.common.Status.FAILURE
return py_trees.common.Status.RUNNING
return py_trees.common.Status.FAILURE

def kubernetes_call(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,25 +130,27 @@ def update(self) -> py_trees.common.Status: # pylint: disable=too-many-return-s
else:
return py_trees.common.Status.RUNNING
elif self.current_state == KubernetesDeleteActionState.WAIT_FOR_DELETION:
if self.current_request.successful():
current_elements = []
for i in self.current_request.get().items:
current_elements.append(i.metadata.name)
if self.target not in current_elements:
self.feedback_message = f"successfully deleted '{self.target}' from namespace '{self.namespace}'." # pylint: disable= attribute-defined-outside-init
return py_trees.common.Status.SUCCESS
if self.current_request.ready():
if self.current_request.successful():
current_elements = []
for i in self.current_request.get().items:
current_elements.append(i.metadata.name)
if self.target not in current_elements:
self.feedback_message = f"successfully deleted '{self.target}' from namespace '{self.namespace}'." # pylint: disable= attribute-defined-outside-init
return py_trees.common.Status.SUCCESS
else:
self.feedback_message = f"Waiting for deletion of '{self.target}' in namespace '{self.namespace}'." # pylint: disable= attribute-defined-outside-init
if self.element_type == KubernetesElementType.POD:
self.current_request = self.client.list_namespaced_pod(
namespace=self.namespace, async_req=True)
elif self.element_type == KubernetesElementType.NETWORK_POLICY:
self.current_request = self.network_client.list_namespaced_network_policy(
namespace=self.namespace, async_req=True)
return py_trees.common.Status.RUNNING
else:
self.feedback_message = f"Waiting for deletion of '{self.target}' in namespace '{self.namespace}'." # pylint: disable= attribute-defined-outside-init
if self.element_type == KubernetesElementType.POD:
self.current_request = self.client.list_namespaced_pod(
namespace=self.namespace, async_req=True)
elif self.element_type == KubernetesElementType.NETWORK_POLICY:
self.current_request = self.network_client.list_namespaced_network_policy(
namespace=self.namespace, async_req=True)
return py_trees.common.Status.RUNNING
self.feedback_message = f"Error while deleting '{self.target}' in namespace '{self.namespace}'." # pylint: disable= attribute-defined-outside-init
else:
self.feedback_message = f"Error while deleting '{self.target}' in namespace '{self.namespace}'." # pylint: disable= attribute-defined-outside-init
return py_trees.common.Status.FAILURE
return py_trees.common.Status.RUNNING

else:
self.feedback_message = f"Error while requesting list of current elements of type {self.element_type_str} (after deletion request)." # pylint: disable= attribute-defined-outside-init
Expand Down

0 comments on commit 929197f

Please sign in to comment.