Skip to content

Commit

Permalink
feat(prefect-worker): update Base Job Template with user-provided JSON (
Browse files Browse the repository at this point in the history
#357)

* feat(prefect-worker): update Base Job Template with user-provided JSON

* empty

* words

* Update charts/prefect-worker/README.md
  • Loading branch information
parkedwards authored Jul 15, 2024
1 parent f0a41f6 commit 9b68112
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 8 deletions.
19 changes: 14 additions & 5 deletions charts/prefect-worker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,22 @@ prefect work-pool get-default-base-job-template --type kubernetes > base-job-tem
helm install prefect-worker prefect/prefect-worker -f values.yaml --set-file worker.config.baseJobTemplate=base-job-template.json
```

#### Updating the Base Job Template

If a base job template is set through Helm (via either `.Values.worker.config.baseJobTemplate.configuration` or `.Values.worker.config.baseJobTemplate.existingConfigMapName`), we'll run an optional `initContainer` that will sync the template configuration to the work pool named in `.Values.worker.config.workPool`.
Any time the base job template is updated, the subsequent `initContainer` run will run `prefect work-pool update <work-pool-name> --base-job-template <template-json>` and sync this template to the API.
Please note that updating JSON inside of a `baseJobTemplate.existingConfigMapName` will require a manual restart of the `prefect-worker` Deployment in order to kick off the `initContainer`. However, updating the `baseJobTemplate.configuration` value will automatically roll the Deployment.
## Maintainers
| Name | Email | Url |
| ---- | ------ | --- |
| jamiezieziula | <[email protected]> | |
| jimid27 | <[email protected]> | |
| parkedwards | <[email protected]> | |
| Name | Email | Url |
|---------------|-----------------------|-----|
| jamiezieziula | <[email protected]> | |
| jimid27 | <[email protected]> | |
| parkedwards | <[email protected]> | |
| mitchnielsen | <[email protected]> | |
## Requirements
Expand Down
74 changes: 71 additions & 3 deletions charts/prefect-worker/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ spec:
app.kubernetes.io/component: worker
template:
metadata:
{{- if .Values.worker.podAnnotations }}
annotations: {{- include "common.tplvalues.render" (dict "value" .Values.worker.podAnnotations "context" $) | nindent 8 }}
{{- end }}
annotations:
checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
{{- if .Values.worker.podAnnotations }}
{{- include "common.tplvalues.render" (dict "value" .Values.worker.podAnnotations "context" $) | nindent 8 }}
{{- end }}
labels: {{- include "common.labels.standard" . | nindent 8 }}
app.kubernetes.io/component: worker
prefect-version: {{ .Chart.AppVersion }}
Expand Down Expand Up @@ -51,6 +53,72 @@ spec:
{{- if .Values.worker.priorityClassName }}
priorityClassName: {{ .Values.worker.priorityClassName }}
{{- end }}
{{- if include "worker.baseJobTemplateName" . }}
initContainers:
- name: sync-base-job-template
image: "{{ .Values.worker.image.repository }}:{{ .Values.worker.image.prefectTag }}"
imagePullPolicy: {{ .Values.worker.image.pullPolicy }}
command:
- /bin/sh
- -c
args:
- |
work_pool_name={{ required "A Work Pool Name is required (worker.config.workPool)" .Values.worker.config.workPool | quote }}
# suppress work-pool inspect output, as we're just
# calling it to check the existence of the work-pool.
if ! prefect work-pool inspect $work_pool_name > /dev/null; then
echo ""
echo "Work pool $work_pool_name does not yet exist, meaning this is the initial run."
echo "The prefect-worker container will create the work pool on the initial run."
echo ""
echo "Exiting now!"
exit 0
fi
echo ""
echo "Work pool $work_pool_name exists; syncing the base job template now..."
echo ""
echo "Work pool $work_pool_name now updating with the following Base Job Template:"
echo ""
cat ./baseJobTemplate.json
echo ""
prefect work-pool update $work_pool_name --base-job-template ./baseJobTemplate.json
workingDir: /home/prefect
volumeMounts:
- mountPath: /home/prefect
name: scratch
subPathExpr: home
- mountPath: /tmp
name: scratch
subPathExpr: tmp
- mountPath: /home/prefect/baseJobTemplate.json
name: base-job-template-file
subPath: baseJobTemplate.json
env:
- name: HOME
value: /home/prefect
- name: PREFECT_API_URL
value: {{ template "worker.apiUrl" . }}
- name: PREFECT_KUBERNETES_CLUSTER_UID
value: {{ template "worker.clusterUUID" . }}
{{- if eq .Values.worker.apiConfig "cloud" }}
- name: PREFECT_API_KEY
valueFrom:
secretKeyRef:
name: {{ .Values.worker.cloudApiConfig.apiKeySecret.name }}
key: {{ .Values.worker.cloudApiConfig.apiKeySecret.key }}
{{- else if eq .Values.worker.apiConfig "selfHosted" }}
- name: PREFECT_API_KEY
valueFrom:
secretKeyRef:
name: {{ .Values.worker.selfHostedCloudApiConfig.apiKeySecret.name }}
key: {{ .Values.worker.selfHostedCloudApiConfig.apiKeySecret.key }}
{{- end }}
{{- end }}
containers:
- name: prefect-worker
image: "{{ .Values.worker.image.repository }}:{{ .Values.worker.image.prefectTag }}"
Expand Down

0 comments on commit 9b68112

Please sign in to comment.