Skip to content

Commit ba1605f

Browse files
committed
ignore errors when cleaning up resources
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]>
1 parent 9b66540 commit ba1605f

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

intel/uninstall.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ def remove_node_label():
239239
try:
240240
discover.patch_k8s_node(patch_body)
241241
except K8sApiException as err:
242-
if "nonexistant" not in json.loads(err.body)["message"]:
242+
if ("nonexistant" not in json.loads(err.body)["message"] and
243+
err.status != 422):
243244
logging.error(
244245
"Aborting uninstall: Exception when removing node "
245246
"label \"{}\": {}".format(patch_path, err))
@@ -344,7 +345,8 @@ def remove_node_cmk_er():
344345
discover.patch_k8s_node_status(patch_body_capacity)
345346
discover.patch_k8s_node_status(patch_body_allocatable)
346347
except K8sApiException as err:
347-
if "nonexistant" not in json.loads(err.body)["message"]:
348+
if ("nonexistant" not in json.loads(err.body)["message"] and
349+
err.status != 422):
348350
logging.error(
349351
"Aborting uninstall: Exception when removing ER: "
350352
"{}".format(err))
@@ -365,7 +367,12 @@ def remove_webhook_resources(prefix, namespace):
365367
k8s.delete_service(None, "{}-service".format(prefix), namespace)
366368
k8s.delete_deployment(None, "cmk-webhook-deployment", namespace)
367369
except K8sApiException as err:
368-
logging.error("Aborting uninstall: Exception when removing "
369-
"webhook: {}".format(err))
370-
sys.exit(1)
370+
if err.status == 404:
371+
msg = json.loads(err.body)["message"]
372+
logging.warning("Webhook resource does not exist: "
373+
"{}".format(msg))
374+
else:
375+
logging.error("Aborting uninstall: Exception when removing "
376+
"webhook: {}".format(err))
377+
sys.exit(1)
371378
logging.info("Removed webhook resources")

0 commit comments

Comments
 (0)