Skip to content

Commit

Permalink
Don't get reservation status for terminating namespaces (#323)
Browse files Browse the repository at this point in the history
* Don't bother getting reservation status for terminating namespaces
  • Loading branch information
adamrdrew authored Sep 1, 2023
1 parent 3d9e2bc commit aa83089
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion bonfire/namespaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from bonfire.processor import process_reservation
from bonfire.utils import FatalError, hms_to_seconds


log = logging.getLogger(__name__)
TIME_FMT = "%Y-%m-%dT%H:%M:%SZ"

Expand Down Expand Up @@ -67,6 +68,9 @@ def _duration_fmt(seconds):


class Namespace:
PHASE_ACTIVE = "Active"
PHASE_TERMINATING = "Terminating"

@property
def annotations(self):
return self._data.get("metadata", "").get("annotations", {})
Expand Down Expand Up @@ -149,7 +153,7 @@ def refresh(self, namespace_data=None, reservation_data=None, clowdapps_data=Non
if "labels" not in self._data["metadata"]:
self._data["metadata"]["labels"] = {}

if self.reserved:
if self.reserved and not self.is_terminating:
res = self.reservation # note: using 'reservation' property defined below
if res:
self.requester = res["spec"]["requester"]
Expand Down Expand Up @@ -210,6 +214,18 @@ def clowdapps(self):

return f"{ready}/{managed}"

@property
def phase(self):
return self._data.get("status", {}).get("phase", "")

@property
def is_terminating(self):
return self.phase == self.PHASE_TERMINATING

@property
def is_active(self):
return self.phase == self.PHASE_ACTIVE


def get_namespaces(available=False, mine=False):
"""
Expand Down Expand Up @@ -247,6 +263,8 @@ def get_namespaces(available=False, mine=False):
ephemeral_namespaces = []
for ns_kwargs in all_ns_kwargs:
ns = Namespace(**ns_kwargs)
if ns.is_terminating:
continue
if not ns.is_reservable:
continue
get_all = not mine and not available
Expand Down

0 comments on commit aa83089

Please sign in to comment.