Skip to content

Commit

Permalink
delete pvs on CR deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralf Grubenmann committed Nov 17, 2023
1 parent 985fd05 commit 5e75463
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
11 changes: 10 additions & 1 deletion controller/server_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,21 @@ 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.items:
if not pv:
continue
pv_api.delete(pv.metadata.name)

api.patch(
namespace=namespace,
Expand Down
2 changes: 1 addition & 1 deletion helm-chart/amalthea/templates/rbac/rbac-namespaced.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
12 changes: 10 additions & 2 deletions helm-chart/amalthea/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,30 @@
}
],
"uniqueItems": true
},
"clusterRoleName":{
"type": "string"
}
},
"required": [
"clusterWide",
"namespaces"
"namespaces",
"clusterRoleName"
],
"additionalProperties": false
},
{
"properties": {
"clusterWide": {
"const": false
},
"clusterRoleName":{
"type": "string"
}
},
"required": [
"clusterWide"
"clusterWide",
"clusterRoleName"
],
"additionalProperties": false
}
Expand Down
2 changes: 1 addition & 1 deletion helm-chart/amalthea/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5e75463

Please sign in to comment.