Skip to content

Commit 06cecce

Browse files
chaenaldbr
andauthored
feat: implement diracx tasks support (#261)
* test: nicer logging in the CI * feat: implement diracx tasks support * test: add a pre-commit for checking the diagram --------- Co-authored-by: aldbr <aldbr@outlook.com>
1 parent 0d2e57f commit 06cecce

14 files changed

Lines changed: 558 additions & 40 deletions

.github/workflows/main.yml

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -54,38 +54,14 @@ jobs:
5454
runs-on: ubuntu-latest
5555
steps:
5656
- uses: actions/checkout@v6
57-
- uses: actions/setup-python@v6
57+
- uses: prefix-dev/setup-pixi@v0.9.5
5858
with:
59-
python-version: 3.x
59+
cache: false
60+
environments: pre-commit
6061
- uses: pre-commit/action@v3.0.1
6162
- uses: pre-commit-ci/lite-action@v1.1.0
6263
if: always()
6364

64-
update-diagram:
65-
needs: detect-docs-only
66-
if: needs.detect-docs-only.outputs.docs-only != 'true'
67-
runs-on: ubuntu-latest
68-
steps:
69-
- uses: actions/checkout@v6
70-
- uses: prefix-dev/setup-pixi@v0.9.5
71-
with:
72-
cache: false
73-
environments: diagram
74-
- name: Regenerate diagram
75-
run: pixi run generate-diagram
76-
- name: Check diagram is up to date
77-
run: |
78-
if ! git diff --exit-code docs/admin/explanations/architecture_diagram.md; then
79-
echo "::error::architecture_diagram.md is out of date. Run 'pixi run generate-diagram' and commit the result."
80-
exit 1
81-
fi
82-
- name: Upload diagram on failure
83-
uses: actions/upload-artifact@v7
84-
with:
85-
name: architecture-diagram
86-
path: docs/admin/explanations/architecture_diagram.md
87-
if: failure()
88-
8965
run-demo:
9066
needs: detect-docs-only
9167
if: needs.detect-docs-only.outputs.docs-only != 'true'
@@ -120,17 +96,8 @@ jobs:
12096
12197
echo "SUCCESS: Environment variable DIRACX_SERVICE_AUTH_REFRESH_TOKEN_EXPIRE_MINUTES is correctly set to 12345"
12298
- name: Debugging information
123-
run: |
124-
export KUBECONFIG=$PWD/.demo/kube.conf
125-
.demo/kubectl get pods
126-
for pod_name in $(.demo/kubectl get pods -o json | jq -r '.items[] | .metadata.name' | grep -vE '(dex|minio|mysql|rabbitmq|opensearch)'); do
127-
echo "${pod_name}"
128-
.demo/kubectl describe pod/"${pod_name}" || true
129-
for container_name in $(.demo/kubectl get pods $pod_name -o jsonpath='{.spec.initContainers[*].name} {.spec.containers[*].name}'); do
130-
echo $pod_name $container_name
131-
.demo/kubectl logs "${pod_name}" -c "${container_name}" || true
132-
done
133-
done
99+
if: always()
100+
run: curl https://raw.githubusercontent.com/DIRACGrid/diracx/refs/heads/main/.github/scripts/collect-k8s-debug-info.sh | bash -s -- "$PWD/.demo"
134101
- name: Check for success
135102
run: |
136103
if [ ! -f ".demo/.success" ]; then

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ repos:
2727
always_run: true
2828
pass_filenames: false
2929

30+
- id: generate-diagram
31+
name: Generate architecture diagram
32+
entry: bash -c 'pixi run -e diagram generate-diagram && git diff --exit-code docs/admin/explanations/architecture_diagram.md'
33+
language: system
34+
always_run: true
35+
pass_filenames: false
36+
3037
- repo: https://github.com/koalaman/shellcheck-precommit
3138
rev: v0.11.0
3239
hooks:

diracx/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type: application
1111
# This is the chart version. This version number should be incremented each time you make changes
1212
# to the chart and its templates, including the app version.
1313
# Versions are expected to follow Semantic Versioning (https://semver.org/)
14-
version: "1.0.26"
14+
version: "1.1.0-beta.1"
1515

1616
# This is the version number of the application being deployed. This version number should be
1717
# incremented each time you make changes to the application. Versions are not expected to

diracx/templates/_helpers.tpl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,36 @@ app.kubernetes.io/instance: {{ .Release.Name }}-web
5757
app.kubernetes.io/name: {{ include "diracx.name" . }}-cli
5858
app.kubernetes.io/instance: {{ .Release.Name }}-cli
5959
{{- end }}
60+
{{- define "diracxTaskRedis.selectorLabels" -}}
61+
app.kubernetes.io/name: {{ include "diracx.name" . }}-task-redis
62+
app.kubernetes.io/instance: {{ .Release.Name }}-task-redis
63+
{{- end }}
64+
65+
{{- define "diracx.taskRedisName" -}}
66+
{{- printf "%s-task-redis" (include "diracx.fullname" .) | trunc 63 | trimSuffix "-" -}}
67+
{{- end -}}
68+
69+
{{- define "diracx.taskWorkerName" -}}
70+
{{- $root := .root -}}
71+
{{- $size := .size -}}
72+
{{- printf "%s-task-worker-%s" (include "diracx.fullname" $root) $size | trunc 63 | trimSuffix "-" -}}
73+
{{- end -}}
74+
75+
{{- define "diracxTaskWorker.selectorLabels" -}}
76+
{{- $root := .root -}}
77+
{{- $size := .size -}}
78+
app.kubernetes.io/name: {{ include "diracx.name" $root }}-task-worker-{{ $size }}
79+
app.kubernetes.io/instance: {{ $root.Release.Name }}-task-worker-{{ $size }}
80+
{{- end }}
81+
82+
{{- define "diracx.taskSchedulerName" -}}
83+
{{- printf "%s-task-scheduler" (include "diracx.fullname" .) | trunc 63 | trimSuffix "-" -}}
84+
{{- end -}}
85+
86+
{{- define "diracxTaskScheduler.selectorLabels" -}}
87+
app.kubernetes.io/name: {{ include "diracx.name" . }}-task-scheduler
88+
app.kubernetes.io/instance: {{ .Release.Name }}-task-scheduler
89+
{{- end }}
6090

6191
{{/*
6292
Create the name of the service account to use

diracx/templates/diracx/_helpers_images.tpl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ Generates the services image path
6464
{{- end }}
6565

6666

67+
{{/*
68+
Generates the tasks image path
69+
*/}}
70+
{{- define "diracx.tasksImage" }}
71+
{{- include "diracx.image" (dict "registryType" .Values.global.images.tasks.registryType "repository" .Values.global.images.tasks.repository "root" . ) }}
72+
{{- end }}
73+
74+
6775
{{/*
6876
Generates the client image path
6977
*/}}
@@ -86,6 +94,13 @@ Generates the busybox image path
8694
{{- include "diracx.image" (dict "registryType" .Values.global.images.busybox.registryType "repository" .Values.global.images.busybox.repository "root" . "tag" .Values.global.images.busybox.tag ) }}
8795
{{- end }}
8896

97+
{{/*
98+
Generates the redis task image path
99+
*/}}
100+
{{- define "diracx.redisTasksImage" }}
101+
{{- include "diracx.image" (dict "registryType" .Values.global.images.redisTasks.registryType "repository" .Values.global.images.redisTasks.repository "root" . "tag" .Values.global.images.redisTasks.tag ) }}
102+
{{- end }}
103+
89104
{{/*
90105
Generates the web image path
91106
*/}}

diracx/templates/diracx/deployment.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ spec:
171171
- secretRef:
172172
name: diracx-os-connection-urls
173173
{{- end }}
174+
{{- if .Values.taskWorkers.enabled }}
175+
- secretRef:
176+
name: diracx-task-redis-url
177+
{{- end }}
174178
resources:
175179
{{- toYaml .Values.resources | nindent 12 }}
176180
{{- with .Values.nodeSelector }}

diracx/templates/diracx/init-secrets/_init-secrets.sh.tpl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,19 @@ generate_secret_if_needed diracx-sql-root-connection-urls \
132132

133133

134134

135+
{{- if .Values.taskWorkers.enabled }}
136+
# Generate the Redis URL secret for the task broker
137+
{{- if .Values.redisTasks.enabled }}
138+
generate_secret_if_needed diracx-task-redis-url \
139+
--from-literal=DIRACX_TASKS_REDIS_URL="redis://{{ include "diracx.taskRedisName" . }}:{{ .Values.redisTasks.port }}"
140+
{{- else if .Values.diracx.tasks.redis_url }}
141+
generate_secret_if_needed diracx-task-redis-url \
142+
--from-literal=DIRACX_TASKS_REDIS_URL="{{ .Values.diracx.tasks.redis_url }}"
143+
{{- else }}
144+
{{ fail "diracx.tasks.redis_url must be set when redisTasks.enabled is false and taskWorkers.enabled is true" }}
145+
{{- end }}
146+
{{- end }}
147+
135148
{{- if .Values.initOs.enabled }}
136149
# If we deploy opensearch ourselves
137150
{{- if .Values.opensearch.enabled }}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{{- if .Values.redisTasks.enabled }}
2+
apiVersion: v1
3+
kind: Service
4+
metadata:
5+
name: {{ include "diracx.taskRedisName" . }}
6+
labels:
7+
{{- include "diracx.labels" . | nindent 4 }}
8+
app.kubernetes.io/component: task-redis
9+
spec:
10+
clusterIP: None
11+
ports:
12+
- name: redis
13+
port: {{ .Values.redisTasks.port }}
14+
targetPort: redis
15+
protocol: TCP
16+
selector:
17+
{{- include "diracxTaskRedis.selectorLabels" . | nindent 4 }}
18+
{{- end }}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{{- if .Values.redisTasks.enabled }}
2+
apiVersion: apps/v1
3+
kind: StatefulSet
4+
metadata:
5+
name: {{ include "diracx.taskRedisName" . }}
6+
labels:
7+
{{- include "diracx.labels" . | nindent 4 }}
8+
app.kubernetes.io/component: task-redis
9+
spec:
10+
serviceName: {{ include "diracx.taskRedisName" . }}
11+
replicas: 1
12+
selector:
13+
matchLabels:
14+
{{- include "diracxTaskRedis.selectorLabels" . | nindent 6 }}
15+
template:
16+
metadata:
17+
annotations:
18+
{{- with .Values.podAnnotations }}
19+
{{- toYaml . | nindent 8 }}
20+
{{- end }}
21+
labels:
22+
{{- include "diracxTaskRedis.selectorLabels" . | nindent 8 }}
23+
app.kubernetes.io/component: task-redis
24+
spec:
25+
{{- with .Values.imagePullSecrets }}
26+
imagePullSecrets:
27+
{{- toYaml . | nindent 8 }}
28+
{{- end }}
29+
serviceAccountName: {{ include "diracx.serviceAccountName" . }}
30+
securityContext:
31+
{{- toYaml .Values.podSecurityContext | nindent 8 }}
32+
containers:
33+
- name: redis
34+
securityContext:
35+
{{- toYaml .Values.securityContext | nindent 12 }}
36+
image: "{{ include "diracx.redisTasksImage" . }}"
37+
imagePullPolicy: {{ .Values.global.imagePullPolicy }}
38+
ports:
39+
- name: redis
40+
containerPort: {{ .Values.redisTasks.port }}
41+
protocol: TCP
42+
livenessProbe:
43+
tcpSocket:
44+
port: redis
45+
timeoutSeconds: 5
46+
periodSeconds: 10
47+
successThreshold: 1
48+
failureThreshold: 3
49+
readinessProbe:
50+
tcpSocket:
51+
port: redis
52+
timeoutSeconds: 5
53+
periodSeconds: 10
54+
successThreshold: 1
55+
failureThreshold: 3
56+
volumeMounts:
57+
- name: redis-data
58+
mountPath: /data
59+
resources:
60+
{{- toYaml (.Values.redisTasks.resources | default dict) | nindent 12 }}
61+
volumes:
62+
- name: redis-data
63+
emptyDir: {}
64+
{{- with .Values.nodeSelector }}
65+
nodeSelector:
66+
{{- toYaml . | nindent 8 }}
67+
{{- end }}
68+
{{- with .Values.affinity }}
69+
affinity:
70+
{{- toYaml . | nindent 8 }}
71+
{{- end }}
72+
{{- with .Values.tolerations }}
73+
tolerations:
74+
{{- toYaml . | nindent 8 }}
75+
{{- end }}
76+
{{- end }}

0 commit comments

Comments
 (0)