Skip to content

Commit

Permalink
Adding timeout check for reservation. On timeout release reservation (#…
Browse files Browse the repository at this point in the history
…174)

* Adding timeout check for reservation. On timeout release reservation

Co-authored-by: Brandon Squizzato <[email protected]>
  • Loading branch information
Jason-RH and bsquizz authored Jan 25, 2022
1 parent c12ba66 commit b29cd42
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
6 changes: 3 additions & 3 deletions bonfire/bonfire.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
get_namespaces,
extend_namespace,
reserve_namespace,
release_namespace,
release_reservation,
)
from bonfire.secrets import import_secrets_from_dir

Expand Down Expand Up @@ -637,7 +637,7 @@ def _cmd_namespace_release(namespace, force, local):
if not force:
_warn_before_delete()

release_namespace(namespace, local)
release_reservation(namespace=namespace, local=local)


@namespace.command("extend")
Expand Down Expand Up @@ -923,7 +923,7 @@ def _err_handler(err):
# if we auto-reserved this ns, auto-release it on failure unless
# --no-release-on-fail was requested
log.info("releasing namespace '%s'", ns)
release_namespace(ns)
release_reservation(namespace=ns)
finally:
msg = "deploy failed"
if str(err):
Expand Down
20 changes: 14 additions & 6 deletions bonfire/namespaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
)
from bonfire.processor import process_reservation
from bonfire.utils import FatalError, hms_to_seconds
from wait_for import TimedOutError


log = logging.getLogger(__name__)
Expand Down Expand Up @@ -257,21 +258,25 @@ def reserve_namespace(name, requester, duration, timeout, local=True):

apply_config(None, list_resource=res_config)

ns_name = wait_on_reservation(res_name, timeout)
try:
ns_name = wait_on_reservation(res_name, timeout)
except TimedOutError:
log.info("timeout waiting for namespace. Cancelling reservation.")
release_reservation(name=res_name)
raise

log.info(
"namespace '%s' is reserved by '%s' for '%s'",
ns_name,
requester,
duration,
)
if not ns_name:
raise FatalError("Reservation of namespace failed.")

return Namespace(name=ns_name)


def release_namespace(namespace, local=True):
res = get_reservation(namespace=namespace)
def release_reservation(name=None, namespace=None, local=True):
res = get_reservation(name=name, namespace=namespace)
if res:
res_config = process_reservation(
res["metadata"]["name"],
Expand All @@ -281,7 +286,10 @@ def release_namespace(namespace, local=True):
)

apply_config(None, list_resource=res_config)
log.info("releasing namespace '%s'", namespace)
msg = f"releasing reservation '{name}'"
if namespace:
msg += f" namespace '{namespace}'"
log.info(msg)
else:
raise FatalError("Reservation lookup failed")

Expand Down

0 comments on commit b29cd42

Please sign in to comment.