Skip to content

Commit

Permalink
Merge pull request #526 from GrahamDumpleton/track-capacity-details
Browse files Browse the repository at this point in the history
Track capacity details in workshop environment status.
  • Loading branch information
GrahamDumpleton authored Aug 5, 2024
2 parents 3b04c70 + b9d2f43 commit b102489
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ spec:
type: string
namespace:
type: string
capacity:
type: integer
initial:
type: integer
reserved:
type: integer
secrets:
type: object
properties:
Expand Down
3 changes: 3 additions & 0 deletions project-docs/release-notes/version-3.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ New Features
recorded in the status of the `WorkshopSession` resource, as well as in the
`WorkshopAllocation` resource.

* The capacity details for a workshop environment are now recorded in the status
of the `WorkshopEnvironment` resource.

* When requesting a workshop session via the REST API, if the `session` param is
supplied along with `user` then an existing workshop session for the user will
only be returned if the name of that session also matches that supplied. When
Expand Down
50 changes: 50 additions & 0 deletions training-portal/src/project/apps/workshops/manager/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,10 @@ def update_workshop_environments(training_portal, workshops):

environment.save()

update_environment_status_details(
environment.name, environment.capacity, environment.reserved
)


@background_task
@resources_lock
Expand Down Expand Up @@ -523,6 +527,13 @@ def process_workshop_environment(portal, workshop, position):
"theme": {"name": settings.THEME_NAME},
"cookies": {"domain": settings.SESSION_COOKIE_DOMAIN},
},
"status": {
settings.OPERATOR_STATUS_KEY: {
"capacity": environment.capacity,
"initial": environment.initial,
"reserved": environment.reserved,
},
},
}

if settings.GOOGLE_TRACKING_ID is not None:
Expand Down Expand Up @@ -644,3 +655,42 @@ def replace_workshop_environment(environment):
# Now schedule creation of the replacement workshop session.

process_workshop_environment(environment.portal, workshop, position).schedule()


def update_environment_status_details(name, capacity, reserved):
"""Update the capacity for the workshop environment recorded in the status."""

try:
K8SWorkshopEnvironment = pykube.object_factory(
api,
f"training.{settings.OPERATOR_API_GROUP}/v1beta1",
"WorkshopEnvironment",
)

resource = K8SWorkshopEnvironment.objects(api).get(name=name)

# The status may not exist as yet if not processed by the operator.

status = resource.obj.setdefault("status", {}).setdefault(
settings.OPERATOR_STATUS_KEY, {}
)

status["capacity"] = capacity
status["reserved"] = reserved

resource.update()

logger.info(
"Updated status of workshop environment %s with capacity=%s and reserved=%s.",
name,
capacity,
reserved,
)

except pykube.exceptions.ObjectDoesNotExist:
pass

except pykube.exceptions.PyKubeError:
logger.exception(
"Failed to update status details of workshop environment %s.", name
)

0 comments on commit b102489

Please sign in to comment.