Skip to content

Commit 3224f84

Browse files
committed
feat(controller): add init job
1 parent 8d4a21b commit 3224f84

12 files changed

Lines changed: 112 additions & 2241 deletions

File tree

.woodpecker/chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ steps:
88
commands:
99
- export VERSION=$(sed 's#v##' <<< $CI_COMMIT_TAG)
1010
- export IMAGE_TAG=$([ ! -z $CI_COMMIT_TAG ] && echo \"$VERSION\" || echo \"canary\")
11-
- export APP_VERSION=$([ ! -z $CI_COMMIT_TAG ] && echo $VERSION || echo 1.0.0)
11+
- export APP_VERSION=$([ -z $CI_COMMIT_TAG ] && echo $CI_COMMIT_SHA || echo $VERSION)
1212
- export CHART_VERSION=$([ -z $CI_COMMIT_TAG ] && echo 1.0.0 || echo $VERSION)
1313
- sed -i "s/imageTag:\ \"canary\"/imageTag:\ $IMAGE_TAG/g" charts/$${CI_REPO_NAME}/values.yaml
1414
- helm package -u charts/$${CI_REPO_NAME} --version $CHART_VERSION --app-version $APP_VERSION

charts/controller/Chart.lock

Lines changed: 0 additions & 6 deletions
This file was deleted.

charts/controller/a.yaml

Lines changed: 0 additions & 2210 deletions
This file was deleted.
-10.4 KB
Binary file not shown.

charts/controller/templates/_helpers.tpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{{/* Generate controller deployment envs */}}
22
{{- define "controller.envs" }}
33
env:
4+
- name: VERSION
5+
value: {{ .Chart.appVersion }}
46
- name: REGISTRATION_MODE
57
value: {{ .Values.registrationMode }}
68
# Environmental variable value for $GATEWAY_CLASS

charts/controller/templates/controller-api-deployment.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ spec:
3838
- -a
3939
- $(DRYCC_REDIS_ADDRS)
4040
{{- include "controller.envs" . | indent 8 }}
41+
- name: drycc-controller-waitting
42+
image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/controller:{{.Values.imageTag}}
43+
imagePullPolicy: {{.Values.imagePullPolicy}}
44+
args:
45+
- /usr/bin/env
46+
- bash
47+
- -ec
48+
- |
49+
python -u /workspace/manage.py cluster_lock waitting
50+
{{- include "controller.envs" . | indent 8 }}
4151
containers:
4252
- name: drycc-controller
4353
image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/controller:{{.Values.imageTag}}
@@ -74,3 +84,11 @@ spec:
7484
name: http
7585
{{- include "controller.limits" . | indent 8 }}
7686
{{- include "controller.envs" . | indent 8 }}
87+
volumeMounts:
88+
- name: controller-config
89+
readOnly: false
90+
mountPath: /etc/controller
91+
volumes:
92+
- name: controller-config
93+
configMap:
94+
name: controller-config
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
name: drycc-controller-job-init
5+
spec:
6+
template:
7+
spec:
8+
initContainers:
9+
- name: drycc-controller-job-init
10+
image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/python-dev:latest
11+
imagePullPolicy: {{.Values.imagePullPolicy}}
12+
args:
13+
- netcat
14+
- -v
15+
- -u
16+
- $(DRYCC_DATABASE_URL),$(DRYCC_DATABASE_REPLICA_URL),$(DRYCC_RABBITMQ_URL)
17+
- -a
18+
- $(DRYCC_REDIS_ADDRS),$(DRYCC_CONTROLLER_API_SERVICE_HOST):$(DRYCC_CONTROLLER_API_SERVICE_PORT)
19+
{{- include "controller.envs" . | indent 8 }}
20+
containers:
21+
- name: drycc-controller-job-init
22+
image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/controller:{{.Values.imageTag}}
23+
imagePullPolicy: {{.Values.imagePullPolicy}}
24+
{{- if .Values.diagnosticMode.enabled }}
25+
command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 8 }}
26+
args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 8 }}
27+
{{- else }}
28+
args:
29+
- /usr/bin/env
30+
- bash
31+
- -ec
32+
- |
33+
python -u /workspace/manage.py cluster_lock lock
34+
python -u /workspace/manage.py migrate --noinput
35+
python -u /workspace/manage.py loaddata /etc/controller/limit-specs.json
36+
python -u /workspace/manage.py loaddata /etc/controller/limit-plans.json
37+
python -u /workspace/manage.py cluster_lock unlock
38+
{{- end }}
39+
{{- include "controller.envs" . | indent 8 }}
40+
restartPolicy: Never
41+
backoffLimit: 0
42+
ttlSecondsAfterFinished: 3600
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import time
2+
from django.core.management.base import BaseCommand
3+
from django.core.cache import cache
4+
from django.conf import settings
5+
6+
lock_key = "drycc:controller:version"
7+
waitting_init_msg = "version inconsistency %s!=%s, waiting for initialization to complete..."
8+
9+
10+
class Command(BaseCommand):
11+
"""Management command for push data to manager"""
12+
13+
def add_arguments(self, parser):
14+
parser.add_argument(
15+
"args",
16+
metavar="action",
17+
nargs="+",
18+
choices=["lock", "unlock", "waitting"],
19+
help="an action that needs to be executed.",
20+
)
21+
22+
def lock(self):
23+
cache.set(lock_key, settings.VERSION)
24+
print("lock completed!")
25+
26+
def unlock(self):
27+
cache.delete(lock_key)
28+
print("unlock completed!")
29+
30+
def waitting(self):
31+
while True:
32+
version = cache.get("drycc:controller:version")
33+
if version != settings.VERSION:
34+
print(waitting_init_msg % (version, settings.VERSION))
35+
else:
36+
break
37+
time.sleep(10)
38+
print("waiting completed!")
39+
40+
def handle(self, *args, **options):
41+
action = args[0]
42+
getattr(self, action)()

rootfs/api/management/commands/cluster_migrate.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

rootfs/api/management/commands/load_limits.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)