Skip to content

Commit

Permalink
ignore errors when cleaning up resources
Browse files Browse the repository at this point in the history
When doing an uninstall it's not really an error if we try to remove
something that has already been removed. Add a few checks to cover this
scenario.

There's an upstream patch proposed which handles this a bit differently
which we may want to pick up instead, it basically just ignores all
errors on uninstall rather than being selective.
intel#239

Signed-off-by: Chris Friesen <[email protected]>
  • Loading branch information
cbf123 committed May 23, 2019
1 parent 300664d commit 54705af
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions intel/uninstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ def remove_node_label():
try:
discover.patch_k8s_node(patch_body)
except K8sApiException as err:
if "nonexistant" not in json.loads(err.body)["message"]:
if ("nonexistant" not in json.loads(err.body)["message"] and
err.status != 422):
logging.error(
"Aborting uninstall: Exception when removing node "
"label \"{}\": {}".format(patch_path, err))
Expand Down Expand Up @@ -344,7 +345,8 @@ def remove_node_cmk_er():
discover.patch_k8s_node_status(patch_body_capacity)
discover.patch_k8s_node_status(patch_body_allocatable)
except K8sApiException as err:
if "nonexistant" not in json.loads(err.body)["message"]:
if ("nonexistant" not in json.loads(err.body)["message"] and
err.status != 422):
logging.error(
"Aborting uninstall: Exception when removing ER: "
"{}".format(err))
Expand All @@ -365,7 +367,12 @@ def remove_webhook_resources(prefix, namespace):
k8s.delete_service(None, "{}-service".format(prefix), namespace)
k8s.delete_deployment(None, "cmk-webhook-deployment", namespace)
except K8sApiException as err:
logging.error("Aborting uninstall: Exception when removing "
"webhook: {}".format(err))
sys.exit(1)
if err.status == 404:
msg = json.loads(err.body)["message"]
logging.warning("Webhook resource does not exist: "
"{}".format(msg))
else:
logging.error("Aborting uninstall: Exception when removing "
"webhook: {}".format(err))
sys.exit(1)
logging.info("Removed webhook resources")

0 comments on commit 54705af

Please sign in to comment.