Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 49 additions & 8 deletions bonfire/bonfire.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
render_ns_table,
render_pool_list,
render_version,
resource_wait_display,
status_spinner,
)

Expand All @@ -38,6 +39,7 @@
)
from bonfire.openshift import (
check_for_existing_reservation,
create_resource_watcher,
find_clowd_env_for_ns,
get_namespace_pools,
get_reservation,
Expand Down Expand Up @@ -239,11 +241,13 @@ def _get_requester():
return requester


def _wait_on_namespace_resources(namespace, timeout, db_only=False, defer_status_errors=False):
def _wait_on_namespace_resources(
namespace, timeout, db_only=False, defer_status_errors=False, watcher=None
):
if db_only:
wait_for_db_resources(namespace, timeout, defer_status_errors)
else:
wait_for_all_resources(namespace, timeout, defer_status_errors)
wait_for_all_resources(namespace, timeout, defer_status_errors, watcher=watcher)


def _validate_reservation_duration(ctx, param, value):
Expand Down Expand Up @@ -969,8 +973,23 @@ def _cmd_namespace_wait_on_resources(namespace, timeout, db_only, defer_status_e
if not namespace:
namespace = current_namespace_or_error()
try:
with status_spinner(f"Waiting for resources in '{namespace}'...", timeout=timeout):
_wait_on_namespace_resources(namespace, timeout, db_only, defer_status_errors)
if db_only:
with status_spinner(f"Waiting for DB resources in '{namespace}'...", timeout=timeout):
_wait_on_namespace_resources(namespace, timeout, db_only, defer_status_errors)
else:
with status_spinner("Starting resource tree view..."):
watcher = create_resource_watcher(namespace)
watcher.start()
try:
resource_wait_display(
watcher,
timeout=timeout,
wait_fn=lambda: _wait_on_namespace_resources(
namespace, timeout, False, defer_status_errors, watcher=watcher
),
)
finally:
watcher.stop()
echo_success(f"Resources in '{namespace}' are ready")
except TimedOutError as err:
log.error("hit timeout error: %s", err)
Expand Down Expand Up @@ -1634,8 +1653,19 @@ def _cmd_config_deploy(
else:
with status_spinner(f"Applying configs to namespace '{ns}'..."):
apply_config(ns, apps_config)
with status_spinner("Waiting for resources to be ready...", timeout=timeout):
_wait_on_namespace_resources(ns, timeout, False, defer_status_errors)
with status_spinner("Starting resource tree view..."):
watcher = create_resource_watcher(ns)
watcher.start()
try:
resource_wait_display(
watcher,
timeout=timeout,
wait_fn=lambda: _wait_on_namespace_resources(
ns, timeout, False, defer_status_errors, watcher=watcher
),
)
finally:
watcher.stop()
except (KeyboardInterrupt, Exception) as err:
_deploy_err_handler(err, no_release_on_fail, reserved_new_ns, reserve, ns)
else:
Expand Down Expand Up @@ -1759,8 +1789,19 @@ def _cmd_deploy_clowdenv(
with status_spinner("Waiting for Clowder to provision target namespace..."):
namespace = wait_for_clowd_env_target_ns(clowd_env)

with status_spinner("Waiting for resources to be ready...", timeout=timeout):
_wait_on_namespace_resources(namespace, timeout, False, defer_status_errors)
with status_spinner("Starting resource tree view..."):
watcher = create_resource_watcher(namespace)
watcher.start()
try:
resource_wait_display(
watcher,
timeout=timeout,
wait_fn=lambda: _wait_on_namespace_resources(
namespace, timeout, False, defer_status_errors, watcher=watcher
),
)
finally:
watcher.stop()

clowd_env_name = find_clowd_env_for_ns(namespace)["metadata"]["name"]

Expand Down
23 changes: 20 additions & 3 deletions bonfire/openshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,19 +187,36 @@ def _all_resources_ready(namespace, timeout, watcher, defer_status_errors=False)
)


def wait_for_all_resources(namespace, timeout=600, defer_status_errors=False):
def create_resource_watcher(namespace):
"""Create a ResourceWatcher with initial resource snapshot.

Caller is responsible for calling watcher.start() and watcher.stop().
"""
watcher = ResourceWatcher(namespace)
watcher.update_resources()

if not watcher.resources:
raise TimedOutError("no resources to wait for observed in namespace")

watcher.start()
return watcher


def wait_for_all_resources(namespace, timeout=600, defer_status_errors=False, watcher=None):
external_watcher = watcher is not None
if not external_watcher:
watcher = ResourceWatcher(namespace)
watcher.update_resources()

if not watcher.resources:
raise TimedOutError("no resources to wait for observed in namespace")

watcher.start()

try:
_all_resources_ready(namespace, timeout, watcher, defer_status_errors)
finally:
watcher.stop()
if not external_watcher:
watcher.stop()


def wait_for_db_resources(namespace, timeout=600, defer_status_errors=False):
Expand Down
Loading
Loading