netgroup-polito / CrownLabs

Kubernetes-based Remote Laboratories
https://crownlabs.polito.it
Apache License 2.0
107 stars 42 forks source link

Add tenant personal workspace auto-closure after a defined number of seconds #821

Closed rs59 closed 1 year ago

rs59 commented 1 year ago

Description

"Project 1": Improving resources and namespaces management in CrownLabs

"For isolation purposes, CrownLabs creates a new Kubernetes namespace for each tenant (e.g., student). However, due to the high number of users, this operation may become problematic, also considering that namespaces are active in CrownLabs even if the user is not logged-in. This project aims at improving how namespaces and resources are handled in CrownLabs, possibly creating dynamically the namespace only when the user is actively using the system." https://cloud.frisso.net/projects

This pull request modifies operators/api/v1alpha2/tenant_types.go and operators/deploy/crds/crownlabs.polito.it_tenants.yaml, adding a LastLogin field to the tenant Spec, implementing in operators/pkg/tenant-controller/tenant_controller.go an auto-deletion of the tenant personal namespace based on the number of seconds elapsed since the tenant has last logged in. If there are Instance resources in the Tenant namespace, the Tenant namespace will not be deleted.

Relevant startup variables in operators/cmd/tenant-operator/main.go include requeueTimeMaximum or nc-tenant-operator-rq-time-max (Maximum nanoseconds before requeue of controller), requeueTimeMinimum or nc-tenant-operator-rq-time-min (Minimum nanoseconds before requeue of controller), and tenantWorkspaceKeepAlive or nc-tenant-operator-wspc-keep-alive (Nanoseconds after last login of tenant during which the tenant workspace should be kept alive: after this period, the controller will attempt to delete the tenant personal workspace).

How Has This Been Tested?

A new sample tenant configuration, operators/samples/tenantRS.yml, was created and applied to the kubernetes cluster (using kubectl apply -f tenantRS.yml) with tenant_controller.go settings nc-tenant-operator-rq-time-max=35000000000, nc-tenant-operator-rq-time-min=30000000000, and nc-tenant-operator-wspc-keep-alive=80000000000.

Known issues/bugs

kingmakerbot commented 1 year ago

Hi @rs59. Thanks for your PR.

I am @kingmakerbot. You can interact with me issuing a slash command in the first line of a comment. Currently, I understand the following commands:

Make sure this PR appears in the CrownLabs changelog, adding one of the following labels:

rs59 commented 1 year ago

@giorio94 Ready to move forward with the next steps!

rs59 commented 1 year ago

Squash all commits @rs59

rs59 commented 1 year ago

@giorio94 Tests have been edited to run and a new test was created for LastLogin. Except for merging all of the commits into one commit, are there any other outstanding issues?