Skip to content

Commit c709bf8

Browse files
author
lijianguo
committed
feat(controller): push data to influx
1 parent 658fac1 commit c709bf8

16 files changed

Lines changed: 481 additions & 179 deletions

File tree

charts/controller/templates/_helpers.tmpl

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
{{/*
2+
Set apiVersion based on .Capabilities.APIVersions
3+
*/}}
4+
{{- define "rbacAPIVersion" -}}
5+
{{- if .Capabilities.APIVersions.Has "rbac.authorization.k8s.io/v1beta1" -}}
6+
rbac.authorization.k8s.io/v1beta1
7+
{{- else if .Capabilities.APIVersions.Has "rbac.authorization.k8s.io/v1alpha1" -}}
8+
rbac.authorization.k8s.io/v1alpha1
9+
{{- else -}}
10+
rbac.authorization.k8s.io/v1
11+
{{- end -}}
12+
{{- end -}}
13+
14+
15+
{{/* Generate controller deployment envs */}}
16+
{{- define "controller.envs" -}}
17+
{{ $redisNodeCount := .Values.redis.replicas | int }}
18+
env:
19+
- name: REGISTRATION_MODE
20+
value: {{ .Values.registration_mode }}
21+
# NOTE(bacongobbler): use drycc/registry_proxy to work around Docker --insecure-registry requirements
22+
- name: "DRYCC_REGISTRY_PROXY_HOST"
23+
value: "127.0.0.1"
24+
# Environmental variable value for $INGRESS_CLASS
25+
- name: "DRYCC_INGRESS_CLASS"
26+
value: "{{ .Values.global.ingress_class }}"
27+
- name: "DRYCC_PLATFORM_DOMAIN"
28+
value: "{{ .Values.global.platform_domain }}"
29+
- name: "K8S_API_VERIFY_TLS"
30+
value: "{{ .Values.k8s_api_verify_tls }}"
31+
- name: "DRYCC_REGISTRY_PROXY_PORT"
32+
value: "{{ .Values.global.registry_proxy_port }}"
33+
- name: "APP_STORAGE"
34+
value: "{{ .Values.global.storage}}"
35+
- name: "DRYCC_REGISTRY_LOCATION"
36+
value: "{{ .Values.global.registry_location }}"
37+
- name: "DRYCC_REGISTRY_SECRET_PREFIX"
38+
value: "{{ .Values.global.registry_secret_prefix }}"
39+
- name: "IMAGE_PULL_POLICY"
40+
value: "{{ .Values.app_image_pull_policy }}"
41+
- name: "KUBERNETES_CLUSTER_DOMAIN"
42+
value: "{{ .Values.global.cluster_domain }}"
43+
{{- if (.Values.app_storage_class) }}
44+
- name: "DRYCC_APP_STORAGE_CLASS"
45+
value: "{{ .Values.app_storage_class }}"
46+
{{- end }}
47+
- name: "TZ"
48+
value: {{ .Values.time_zone | default "UTC" | quote }}
49+
{{- if (.Values.deploy_hook_urls) }}
50+
- name: DRYCC_DEPLOY_HOOK_URLS
51+
value: "{{ .Values.deploy_hook_urls }}"
52+
- name: DRYCC_DEPLOY_HOOK_SECRET_KEY
53+
valueFrom:
54+
secretKeyRef:
55+
name: deploy-hook-key
56+
key: secret-key
57+
{{- end }}
58+
- name: DRYCC_SECRET_KEY
59+
valueFrom:
60+
secretKeyRef:
61+
name: django-secret-key
62+
key: secret-key
63+
- name: DRYCC_BUILDER_KEY
64+
valueFrom:
65+
secretKeyRef:
66+
name: builder-key-auth
67+
key: builder-key
68+
{{- if eq .Values.global.database_location "off-cluster" }}
69+
- name: DRYCC_DATABASE_NAME
70+
valueFrom:
71+
secretKeyRef:
72+
name: database-creds
73+
key: name
74+
- name: DRYCC_DATABASE_SERVICE_HOST
75+
valueFrom:
76+
secretKeyRef:
77+
name: database-creds
78+
key: host
79+
- name: DRYCC_DATABASE_SERVICE_PORT
80+
valueFrom:
81+
secretKeyRef:
82+
name: database-creds
83+
key: port
84+
{{- end }}
85+
- name: DRYCC_DATABASE_USER
86+
valueFrom:
87+
secretKeyRef:
88+
name: database-creds
89+
key: user
90+
- name: DRYCC_DATABASE_PASSWORD
91+
valueFrom:
92+
secretKeyRef:
93+
name: database-creds
94+
key: password
95+
- name: WORKFLOW_NAMESPACE
96+
valueFrom:
97+
fieldRef:
98+
fieldPath: metadata.namespace
99+
{{ if eq .Values.global.redis_location "on-cluster"}}
100+
- name: DRYCC_REDIS_ADDRS
101+
value: "{{range $i := until $redisNodeCount}}drycc-redis-{{$i}}.drycc-redis.{{$.Release.Namespace}}.svc.{{$.Values.global.cluster_domain}}:{{$.Values.redis.port}}{{if lt (add 1 $i) $redisNodeCount}},{{end}}{{end}}"
102+
{{- else if eq .Values.global.redis_location "off-cluster" }}
103+
- name: DRYCC_REDIS_ADDRS
104+
valueFrom:
105+
secretKeyRef:
106+
name: redis-creds
107+
key: addrs
108+
{{- end }}
109+
- name: DRYCC_REDIS_PASSWORD
110+
valueFrom:
111+
secretKeyRef:
112+
name: redis-creds
113+
key: password
114+
{{- if eq .Values.global.influxdb_location "off-cluster" }}
115+
- name: "INFLUXDB_URL"
116+
valueFrom:
117+
secretKeyRef:
118+
name: influxdb-creds
119+
key: url
120+
{{- else }}
121+
- name: "INFLUXDB_URL"
122+
value: http://$(DRYCC_INFLUXDB_SERVICE_HOST):$(DRYCC_INFLUXDB_SERVICE_PORT_TRANSPORT)
123+
{{- end }}
124+
- name: "INFLUXDB_BUCKET"
125+
valueFrom:
126+
secretKeyRef:
127+
name: influxdb-creds
128+
key: bucket
129+
- name: "INFLUXDB_ORG"
130+
valueFrom:
131+
secretKeyRef:
132+
name: influxdb-creds
133+
key: org
134+
- name: "INFLUXDB_TOKEN"
135+
valueFrom:
136+
secretKeyRef:
137+
name: influxdb-creds
138+
key: token
139+
{{- range $key, $value := .Values.environment }}
140+
- name: {{ $key }}
141+
value: {{ $value | quote }}
142+
{{- end }}
143+
{{- end }}
144+
145+
{{/* Generate controller deployment limits */}}
146+
{{- define "controller.limits" -}}
147+
{{- if or (.Values.limits_cpu) (.Values.limits_memory) }}
148+
resources:
149+
limits:
150+
{{- if (.Values.limits_cpu) }}
151+
cpu: {{.Values.limits_cpu}}
152+
{{- end }}
153+
{{- if (.Values.limits_memory) }}
154+
memory: {{.Values.limits_memory}}
155+
{{- end }}
156+
{{- end }}
157+
{{- end }}
158+
159+
160+
{{/* Generate controller deployment volumeMounts */}}
161+
{{- define "controller.volumeMounts" -}}
162+
volumeMounts:
163+
- mountPath: /etc/slugrunner
164+
name: slugrunner-config
165+
readOnly: true
166+
{{- end }}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: drycc-controller-celery
5+
labels:
6+
heritage: drycc
7+
annotations:
8+
component.drycc.cc/version: {{ .Values.image_tag }}
9+
spec:
10+
replicas: {{ .Values.celery_replicas }}
11+
strategy:
12+
rollingUpdate:
13+
maxSurge: 1
14+
maxUnavailable: 0
15+
type: RollingUpdate
16+
selector:
17+
matchLabels:
18+
app: drycc-controller-celery
19+
template:
20+
metadata:
21+
labels:
22+
app: drycc-controller-celery
23+
spec:
24+
serviceAccount: drycc-controller-celery
25+
containers:
26+
- name: drycc-controller-celery-high
27+
image: {{.Values.image_registry}}{{.Values.org}}/controller:{{.Values.image_tag}}
28+
command:
29+
- /bin/bash
30+
- -c
31+
args:
32+
- celery -A api worker -Q priority.high --autoscale=32,1 --loglevel=WARNING
33+
imagePullPolicy: {{.Values.image_pull_policy}}
34+
{{- include "controller.limits" . | indent 10 }}
35+
{{- include "controller.envs" . | indent 10 }}
36+
volumeMounts:
37+
- mountPath: /etc/slugrunner
38+
name: slugrunner-config
39+
readOnly: true
40+
- name: drycc-controller-celery-middle
41+
image: {{.Values.image_registry}}{{.Values.org}}/controller:{{.Values.image_tag}}
42+
command:
43+
- /bin/bash
44+
- -c
45+
args:
46+
- celery -A api worker -Q priority.middle --autoscale=16,1 --loglevel=WARNING
47+
{{- include "controller.limits" . | indent 10 }}
48+
{{- include "controller.envs" . | indent 10 }}
49+
volumeMounts:
50+
- mountPath: /etc/slugrunner
51+
name: slugrunner-config
52+
readOnly: true
53+
imagePullPolicy: {{.Values.image_pull_policy}}
54+
- name: drycc-controller-celery-low
55+
image: {{.Values.image_registry}}{{.Values.org}}/controller:{{.Values.image_tag}}
56+
command:
57+
- /bin/bash
58+
- -c
59+
args:
60+
- celery -A api worker -Q priority.low --autoscale=8,1 --loglevel=WARNING
61+
{{- include "controller.limits" . | indent 10 }}
62+
{{- include "controller.envs" . | indent 10 }}
63+
volumeMounts:
64+
- mountPath: /etc/slugrunner
65+
name: slugrunner-config
66+
readOnly: true
67+
imagePullPolicy: {{.Values.image_pull_policy}}
68+
volumes:
69+
- name: slugrunner-config
70+
configMap:
71+
name: slugrunner-config
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
apiVersion: batch/v1beta1
2+
kind: CronJob
3+
metadata:
4+
name: drycc-controller-cronjob-daily
5+
labels:
6+
heritage: drycc
7+
annotations:
8+
component.drycc.cc/version: {{ .Values.image_tag }}
9+
spec:
10+
failedJobsHistoryLimit: 1
11+
schedule: "0 0 * * *"
12+
successfulJobsHistoryLimit: 3
13+
jobTemplate:
14+
spec:
15+
template:
16+
spec:
17+
restartPolicy: OnFailure
18+
containers:
19+
- image: {{.Values.image_registry}}{{.Values.org}}/controller:{{.Values.image_tag}}
20+
imagePullPolicy: {{.Values.image_pull_policy}}
21+
name: drycc-controller-push-data-to-influxdb
22+
command:
23+
- /bin/bash
24+
- -c
25+
args:
26+
- python /app/manage.py push_data_to_influxdb
27+
{{- include "controller.envs" . | indent 12 }}
28+
volumeMounts:
29+
- mountPath: /etc/slugrunner
30+
name: slugrunner-config
31+
readOnly: true
32+
- image: {{.Values.image_registry}}{{.Values.org}}/controller:{{.Values.image_tag}}
33+
imagePullPolicy: {{.Values.pull_policy}}
34+
name: drycc-controller-load-db-state-to-k8s
35+
command:
36+
- /bin/bash
37+
- -c
38+
args:
39+
- python -u /app/manage.py load_db_state_to_k8s
40+
{{- include "controller.envs" . | indent 12 }}
41+
volumeMounts:
42+
- mountPath: /etc/slugrunner
43+
name: slugrunner-config
44+
readOnly: true
45+
volumes:
46+
- name: slugrunner-config
47+
configMap:
48+
name: slugrunner-config

0 commit comments

Comments
 (0)