Skip to content

Commit aabad98

Browse files
authored
Merge pull request #272 from QuanMPhm/ops_1615/pre_existing
Allow pre-existing OpenShift projects to be managed by Coldfront allocations
2 parents 7bc0fd4 + f9603cd commit aabad98

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

src/coldfront_plugin_cloud/openshift.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ def get_quota(self, project_id):
304304
cloud_quotas = self._openshift_get_resourcequotas(project_id)
305305
combined_quota = {}
306306
for cloud_quota in cloud_quotas:
307-
combined_quota.update(cloud_quota["spec"]["hard"])
307+
if quota_spec := cloud_quota["spec"].get("hard"):
308+
combined_quota.update(quota_spec)
308309

309310
return combined_quota
310311

@@ -606,7 +607,10 @@ def _wait_for_quota_to_settle(self, project_id, resource_quota):
606607
resourcequota objects.
607608
"""
608609

609-
if "resourcequotas" in resource_quota["spec"]["hard"]:
610+
if (
611+
resource_quota["spec"].get("hard")
612+
and "resourcequotas" in resource_quota["spec"]["hard"]
613+
):
610614
logger.info("waiting for resourcequota quota")
611615

612616
api = self.get_resource_api(API_CORE, "ResourceQuota")

src/coldfront_plugin_cloud/tests/functional/openshift/test_allocation.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,3 +566,39 @@ def test_limitrange_defaults_update(self):
566566
),
567567
[],
568568
)
569+
570+
def test_preexisting_project(self):
571+
"""Test allocation activation and validation when the project already exists on OpenShift."""
572+
user = self.new_user()
573+
project = self.new_project(pi=user)
574+
allocation = self.new_allocation(project, self.resource, 1)
575+
self.new_allocation_user(allocation, user)
576+
allocator = openshift.OpenShiftResourceAllocator(self.resource, allocation)
577+
578+
project_id = allocator.create_project(project.title).id
579+
580+
self.assertEqual(allocator.get_quota(project_id), {})
581+
self.assertEqual(allocator.get_users(project_id), set())
582+
583+
utils.set_attribute_on_allocation(
584+
allocation, attributes.ALLOCATION_PROJECT_ID, project_id
585+
)
586+
utils.set_attribute_on_allocation(
587+
allocation, attributes.ALLOCATION_PROJECT_NAME, project_id
588+
)
589+
tasks.activate_allocation(allocation.pk)
590+
call_command("validate_allocations", apply=True)
591+
592+
self.assertEqual(
593+
allocator.get_quota(project_id),
594+
{
595+
"limits.cpu": "1",
596+
"limits.memory": "4Gi",
597+
"limits.ephemeral-storage": "5Gi",
598+
"ocs-external-storagecluster-ceph-rbd.storageclass.storage.k8s.io/requests.storage": "20Gi",
599+
"ibm-spectrum-scale-fileset.storageclass.storage.k8s.io/requests.storage": "0",
600+
"requests.nvidia.com/gpu": "0",
601+
"persistentvolumeclaims": "2",
602+
},
603+
)
604+
assert set([user.username]) == allocator.get_users(project_id)

0 commit comments

Comments
 (0)