Skip to content

Commit

Permalink
Merge pull request #140 from SubstraFoundation/add-operator
Browse files Browse the repository at this point in the history
Convert add user/nodes Jobs to Operator
  • Loading branch information
Kelvin-M authored Feb 4, 2020
2 parents 66cac11 + d93dc10 commit 3f56133
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 192 deletions.
77 changes: 77 additions & 0 deletions charts/substra-backend/templates/add-account-operator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ template "substra.fullname" . }}-add-account
labels:
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }}
app.kubernetes.io/name: {{ template "substra.name" . }}-add-account
app.kubernetes.io/part-of: {{ template "substra.name" . }}
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: {{ template "substra.name" . }}-add-account
app.kubernetes.io/instance: {{ .Release.Name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ template "substra.name" . }}-add-account
app.kubernetes.io/instance: {{ .Release.Name }}
spec:
containers:
- name: add-account
image: "{{ .Values.backend.image.repository }}:{{ .Values.backend.image.tag }}"
imagePullPolicy: "{{ .Values.backend.image.pullPolicy }}"
command: ["/bin/bash", "-c"]
args:
- |
while true; do
./manage.py migrate
## Users
while read user_password; do
./manage.py add_user $user_password
done < /accounts/users
## IncomingNode
while read user_password; do
./manage.py create_incoming_node $user_password
done < /accounts/incoming_nodes
## OutgoingNode
while read user_password; do
./manage.py create_outgoing_node $user_password
done < /accounts/outgoing_nodes
sleep 60
done
resources:
{{- toYaml .Values.resources | nindent 14 }}
env:
- name: DJANGO_SETTINGS_MODULE
value: backend.settings.{{ .Values.backend.settings }}
- name: BACKEND_DB_NAME
value: {{ .Values.postgresql.postgresqlDatabase }}
- name: BACKEND_DB_USER
value: {{ .Values.postgresql.postgresqlUsername }}
- name: BACKEND_DB_PWD
value: {{ .Values.postgresql.postgresqlPassword }}
- name: DATABASE_HOST
value: {{ .Release.Name }}-postgresql
- name: PYTHONUNBUFFERED
value: "1"
volumeMounts:
- mountPath: /accounts
name: accounts
readOnly: true
initContainers:
- name: wait-postgresql
image: jwilder/dockerize
command: ['dockerize', '-wait', 'tcp://{{ .Release.Name }}-postgresql:5432']
volumes:
- name: accounts
configMap:
name: {{ template "substra.fullname" . }}-add-account
17 changes: 17 additions & 0 deletions charts/substra-backend/templates/configmap-add-account.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "substra.fullname" . }}-add-account
data:
users: |
{{- range .Values.users }}
{{ .name }} {{ .secret }}
{{- end }}
incoming_nodes: |
{{- range .Values.incomingNodes }}
{{ .name }} {{ .secret }}
{{- end }}
outgoing_nodes: |
{{- range .Values.outgoingNodes }}
{{ .name }} {{ .secret }}
{{- end }}
62 changes: 0 additions & 62 deletions charts/substra-backend/templates/job-add-incoming-nodes.yaml

This file was deleted.

62 changes: 0 additions & 62 deletions charts/substra-backend/templates/job-add-outgoing-nodes.yaml

This file was deleted.

68 changes: 0 additions & 68 deletions charts/substra-backend/templates/job-add-users.yaml

This file was deleted.

0 comments on commit 3f56133

Please sign in to comment.