Skip to content

Commit

Permalink
Unset requester when releasing namespace (#127)
Browse files Browse the repository at this point in the history
* Remove reset command, unset the requester when releasing

* Formatting

* Fix missing 'force' arg
  • Loading branch information
bsquizz authored Oct 7, 2021
1 parent 01d70c6 commit e87919d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 38 deletions.
60 changes: 28 additions & 32 deletions bonfire/bonfire.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
get_namespaces,
reserve_namespace,
release_namespace,
reset_namespace,
add_base_resources,
reconcile,
)
Expand Down Expand Up @@ -539,7 +538,7 @@ def _validate_reservation_duration(ctx, param, value):
"-r",
type=str,
default=None,
help="Name of the user requesting a reservation"
help="Name of the user requesting a reservation",
),
click.option(
"--namespace",
Expand Down Expand Up @@ -582,20 +581,20 @@ def inner(func):
"-o",
default="cli",
help="which output format to return the data in",
type=click.Choice(['cli', 'json'], case_sensitive=False)
type=click.Choice(["cli", "json"], case_sensitive=False),
)
def _list_namespaces(available, mine, output):
"""Get list of ephemeral namespaces"""
namespaces = get_namespaces(available=available, mine=mine)
if not available and not mine and not namespaces:
_error(NO_RESERVATION_SYS)
elif not namespaces:
if output == 'json':
if output == "json":
click.echo("{}")
else:
click.echo("no namespaces found")
else:
if output == 'json':
if output == "json":
data = {}
for ns in namespaces:
data[ns.name] = {
Expand Down Expand Up @@ -630,11 +629,19 @@ def _cmd_namespace_reserve(duration, retries, namespace):

@namespace.command("release")
@click.argument("namespace", required=True, type=str)
def _cmd_namespace_release(namespace):
@click.option(
"-f",
"--force",
is_flag=True,
default=False,
help="Do not check if you own this namespace",
)
def _cmd_namespace_release(namespace, force):
"""Remove reservation from an ephemeral namespace"""
if not get_namespaces():
_error(NO_RESERVATION_SYS)
_warn_if_unsafe(namespace)
if not force:
_warn_if_unsafe(namespace)
release_namespace(namespace)


Expand Down Expand Up @@ -669,13 +676,6 @@ def _cmd_namespace_reconcile():
reconcile()


@namespace.command("reset", hidden=True)
@click.argument("namespace", required=True, type=str)
def _cmd_namespace_reset(namespace):
"""Set namespace to not released/not ready (for admin use only)"""
reset_namespace(namespace)


def _get_apps_config(source, target_env, ref_env, local_config_path):
config = conf.load_config(local_config_path)

Expand Down Expand Up @@ -1126,8 +1126,8 @@ def _cmd_apps_what_depends_on(

@reservation.command("create")
@click.option(
'--bot',
'-b',
"--bot",
"-b",
is_flag=True,
help="Use this flag to skip the duplicate reservation check (for automation)",
)
Expand All @@ -1142,9 +1142,7 @@ def _err_handler(err):
res = get_reservation(name)
# Name should be unique on reservation creation.
if res:
raise FatalError(
f"Reservation with name {name} already exists"
)
raise FatalError(f"Reservation with name {name} already exists")

res_config = process_reservation(name, requester, duration)

Expand Down Expand Up @@ -1189,11 +1187,11 @@ def _err_handler(err):

@reservation.command("extend")
@click.option(
'--duration',
'-d',
"--duration",
"-d",
type=str,
default='1h',
help='Amount of time to extend the reservation',
default="1h",
help="Amount of time to extend the reservation",
callback=_validate_reservation_duration,
)
@options(_reservation_lookup_options)
Expand Down Expand Up @@ -1229,9 +1227,7 @@ def _err_handler(err):
log.exception("hit unexpected error!")
_err_handler(err)
else:
log.info(
"reservation '%s' extended by '%s'", res["metadata"]["name"], duration
)
log.info("reservation '%s' extended by '%s'", res["metadata"]["name"], duration)


@reservation.command("delete")
Expand Down Expand Up @@ -1267,17 +1263,17 @@ def _err_handler(err):

@reservation.command("list")
@click.option(
'--mine',
'-m',
"--mine",
"-m",
is_flag=True,
help='Return reservations belonging to the result of oc whoami',
help="Return reservations belonging to the result of oc whoami",
)
@click.option(
'--requester',
'-r',
"--requester",
"-r",
type=str,
default=None,
help='Return reservations belonging to the provided requester',
help="Return reservations belonging to the provided requester",
)
def _list_reservations(mine, requester):
def _err_handler(err):
Expand Down
12 changes: 6 additions & 6 deletions bonfire/namespaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,12 @@ def reserve_namespace(duration, retries, specific_namespace=None, attempt=0):


def release_namespace(namespace):
oc("label", "--overwrite", "namespace", namespace, f"{NS_RESERVED}=false")


def reset_namespace(namespace):
release_namespace(namespace)
oc("label", "--overwrite", "namespace", namespace, f"{NS_READY}=false")
ns = Namespace(name=namespace)
ns.reserved = False
ns.requester = None
ns.requester_name = None
ns.ready = False
ns.update()


def _delete_resources(namespace):
Expand Down

0 comments on commit e87919d

Please sign in to comment.