This repository contains a Kopf-based OpenShift operator for provisioning ColdFront allocations.
It is intended to move allocation provisioning out of coldfront-plugin-cloud and
into a Kubernetes controller. This lets ColdFront manage an Allocation custom resource
instead of directly managing namespaces, users, groups, role bindings, quotas, and limit ranges.
The operator watches Allocation resources and creates or repairs the corresponding OpenShift
resources. This reduces the OpenShift permissions required by ColdFront and keeps provisioned
resources aligned with the allocation specification.
allocation_operator.py: Kopf operator and OpenShift client abstraction.k8s/allocation-crd.yaml:AllocationCRD definition.tests/test_openshift_operator.py: functional tests that run against a live OpenShift cluster.
The cluster must have the OpenShift APIs used by the operator, including the OpenShift User and
Group resources. Install the CRD with:
oc apply -f k8s/allocation-crd.yamlConfirm that it is available:
oc get crd allocations.massopen.cloudCreate a Python environment and install the dependencies:
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtWith KUBECONFIG pointing to the target cluster, start the operator from the repository root:
kopf run --verbose allocation_operator.pyThe CRD is cluster-scoped and uses API version massopen.cloud/v1alpha1:
apiVersion: massopen.cloud/v1alpha1
kind: Allocation
metadata:
name: research-allocation
spec:
users:
- dylan
- bob
quota:
requests.cpu: 16
requests.memory: 32Gi
limits.cpu: "16"
limits.memory: 64Gi
persistentvolumeclaims: "10"
onDeletePolicy: Delete
expirationDate: "2027-12-02"usersis a required, non-empty list of OpenShift usernames. The operator creates one OpenShiftUserobject for each entry and adds the users to the allocationGroup.quotais a required map of resource quota keys to integer or string values. It is used as thespec.hardvalue of the allocation'sResourceQuota.onDeletePolicyis required and must beDelete,Archive, orIgnore:Deleteremoves the role binding, group, users, and namespace when the Allocation is deleted.Archiveremoves the role binding but retains the other managed resources.Ignoreleaves managed resources untouched.
expirationDateis an optional date inYYYY-MM-DDformat. It is stored on the resource, but expiration handling is not currently implemented.
For an allocation named research-allocation, the operator maintains:
- Namespace
research-allocation. - OpenShift Group
research-allocationcontaining the configured users. - One OpenShift User per configured username.
- Namespaced RoleBinding
research-allocation-editgranting theeditClusterRole to the group. - Namespaced ResourceQuota
research-allocation-projectusing the configured quota. - Namespaced LimitRange
research-allocation-limitswith the operator's default container limits.
The Allocation status reports one of these phases: Progressing, Failed, or Ready.
Apply an allocation with:
oc apply -f allocation.yaml
oc get allocation research-allocation -o yamlFunctional tests require a live OpenShift or MicroShift cluster, and a
KUBECONFIG that can create the resources managed by the operator.
pytest-xdist is used to run tests in paralell
Install the CRD and dependencies, then run:
oc apply -f k8s/allocation-crd.yaml
pip install -r requirements.txt
pytest -n auto testsEach test allocation receives a random suffix, so the functional tests can run in parallel without sharing allocation, namespace, quota, or user names.
For local MicroShift setup, the repository includes:
./ci/setup-microshift.shThat script starts the MicroShift container, prepares KUBECONFIG, waits for the cluster, and
installs the Allocation CRD. The script requires Docker, oc, and the permissions needed to run
the container setup commands.