diff --git a/controller/server_controller.py b/controller/server_controller.py index 8a87d726..e4645105 100644 --- a/controller/server_controller.py +++ b/controller/server_controller.py @@ -173,12 +173,20 @@ def create_fn(labels, logger, name, namespace, spec, uid, body, **_): @kopf.on.delete(config.api_group, config.api_version, config.custom_resource_name) -def delete_fn(labels, body, namespace, name, **_): +def delete_fn(labels, logger, body, namespace, name, **_): """ The jupyter server has been deleted. """ api = get_api(config.api_version, config.custom_resource_name, config.api_group) new_status = ServerStatusEnum.Stopping + # delete persistent volumes because their not in a namespace and ignored by k8s GC + pv_api = get_api("v1", "PersistentVolume", "") + pvs = pv_api.get(label_selector=f"amalthea.dev/parent-name={name}") + logger.info(f"Found pvs: {pvs}") + if pvs and pvs.items: + for pv in pvs: + if not pv: + pv_api.delete(pv.metadata.name) api.patch( namespace=namespace, diff --git a/helm-chart/amalthea/templates/rbac/rbac-namespaced.yaml b/helm-chart/amalthea/templates/rbac/rbac-namespaced.yaml index 8a2fb4da..49b708b1 100644 --- a/helm-chart/amalthea/templates/rbac/rbac-namespaced.yaml +++ b/helm-chart/amalthea/templates/rbac/rbac-namespaced.yaml @@ -46,7 +46,7 @@ subjects: roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole - name: {{ .Values.scope.clusterRoleName }} + name: {{ $fullTemplateScope.Values.scope.clusterRoleName }} {{- end }} {{- end }} {{- end }} diff --git a/helm-chart/amalthea/values.schema.json b/helm-chart/amalthea/values.schema.json index bf871e3f..2033d485 100644 --- a/helm-chart/amalthea/values.schema.json +++ b/helm-chart/amalthea/values.schema.json @@ -32,11 +32,15 @@ } ], "uniqueItems": true + }, + "clusterRoleName":{ + "type": "string" } }, "required": [ "clusterWide", - "namespaces" + "namespaces", + "clusterRoleName" ], "additionalProperties": false }, @@ -44,10 +48,14 @@ "properties": { "clusterWide": { "const": false + }, + "clusterRoleName":{ + "type": "string" } }, "required": [ - "clusterWide" + "clusterWide", + "clusterRoleName" ], "additionalProperties": false } diff --git a/helm-chart/amalthea/values.yaml b/helm-chart/amalthea/values.yaml index 0a6af05f..517884c7 100644 --- a/helm-chart/amalthea/values.yaml +++ b/helm-chart/amalthea/values.yaml @@ -33,7 +33,7 @@ scope: # 2. Do not define namespaces at all, in which case amalthea # will only operate in the namespace where the helm chart is deployed. # namespaces: ["default"] - clusterRoleName: amalthea + clusterRoleName: amalthea # name of the cluster role for PV creation # only needs to be set if not deployed clusterwide # the role needs permission to create,get,list,watch PVs