Skip to content

Commit

Permalink
Merge pull request teamhephy#30 from jianxiaoguo/main
Browse files Browse the repository at this point in the history
feat(controller): push data to influx
  • Loading branch information
duanhongyi authored Dec 25, 2020
2 parents 658fac1 + c709bf8 commit db1245a
Show file tree
Hide file tree
Showing 16 changed files with 481 additions and 179 deletions.
12 changes: 0 additions & 12 deletions charts/controller/templates/_helpers.tmpl

This file was deleted.

166 changes: 166 additions & 0 deletions charts/controller/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
{{/*
Set apiVersion based on .Capabilities.APIVersions
*/}}
{{- define "rbacAPIVersion" -}}
{{- if .Capabilities.APIVersions.Has "rbac.authorization.k8s.io/v1beta1" -}}
rbac.authorization.k8s.io/v1beta1
{{- else if .Capabilities.APIVersions.Has "rbac.authorization.k8s.io/v1alpha1" -}}
rbac.authorization.k8s.io/v1alpha1
{{- else -}}
rbac.authorization.k8s.io/v1
{{- end -}}
{{- end -}}


{{/* Generate controller deployment envs */}}
{{- define "controller.envs" -}}
{{ $redisNodeCount := .Values.redis.replicas | int }}
env:
- name: REGISTRATION_MODE
value: {{ .Values.registration_mode }}
# NOTE(bacongobbler): use drycc/registry_proxy to work around Docker --insecure-registry requirements
- name: "DRYCC_REGISTRY_PROXY_HOST"
value: "127.0.0.1"
# Environmental variable value for $INGRESS_CLASS
- name: "DRYCC_INGRESS_CLASS"
value: "{{ .Values.global.ingress_class }}"
- name: "DRYCC_PLATFORM_DOMAIN"
value: "{{ .Values.global.platform_domain }}"
- name: "K8S_API_VERIFY_TLS"
value: "{{ .Values.k8s_api_verify_tls }}"
- name: "DRYCC_REGISTRY_PROXY_PORT"
value: "{{ .Values.global.registry_proxy_port }}"
- name: "APP_STORAGE"
value: "{{ .Values.global.storage}}"
- name: "DRYCC_REGISTRY_LOCATION"
value: "{{ .Values.global.registry_location }}"
- name: "DRYCC_REGISTRY_SECRET_PREFIX"
value: "{{ .Values.global.registry_secret_prefix }}"
- name: "IMAGE_PULL_POLICY"
value: "{{ .Values.app_image_pull_policy }}"
- name: "KUBERNETES_CLUSTER_DOMAIN"
value: "{{ .Values.global.cluster_domain }}"
{{- if (.Values.app_storage_class) }}
- name: "DRYCC_APP_STORAGE_CLASS"
value: "{{ .Values.app_storage_class }}"
{{- end }}
- name: "TZ"
value: {{ .Values.time_zone | default "UTC" | quote }}
{{- if (.Values.deploy_hook_urls) }}
- name: DRYCC_DEPLOY_HOOK_URLS
value: "{{ .Values.deploy_hook_urls }}"
- name: DRYCC_DEPLOY_HOOK_SECRET_KEY
valueFrom:
secretKeyRef:
name: deploy-hook-key
key: secret-key
{{- end }}
- name: DRYCC_SECRET_KEY
valueFrom:
secretKeyRef:
name: django-secret-key
key: secret-key
- name: DRYCC_BUILDER_KEY
valueFrom:
secretKeyRef:
name: builder-key-auth
key: builder-key
{{- if eq .Values.global.database_location "off-cluster" }}
- name: DRYCC_DATABASE_NAME
valueFrom:
secretKeyRef:
name: database-creds
key: name
- name: DRYCC_DATABASE_SERVICE_HOST
valueFrom:
secretKeyRef:
name: database-creds
key: host
- name: DRYCC_DATABASE_SERVICE_PORT
valueFrom:
secretKeyRef:
name: database-creds
key: port
{{- end }}
- name: DRYCC_DATABASE_USER
valueFrom:
secretKeyRef:
name: database-creds
key: user
- name: DRYCC_DATABASE_PASSWORD
valueFrom:
secretKeyRef:
name: database-creds
key: password
- name: WORKFLOW_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
{{ if eq .Values.global.redis_location "on-cluster"}}
- name: DRYCC_REDIS_ADDRS
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}}"
{{- else if eq .Values.global.redis_location "off-cluster" }}
- name: DRYCC_REDIS_ADDRS
valueFrom:
secretKeyRef:
name: redis-creds
key: addrs
{{- end }}
- name: DRYCC_REDIS_PASSWORD
valueFrom:
secretKeyRef:
name: redis-creds
key: password
{{- if eq .Values.global.influxdb_location "off-cluster" }}
- name: "INFLUXDB_URL"
valueFrom:
secretKeyRef:
name: influxdb-creds
key: url
{{- else }}
- name: "INFLUXDB_URL"
value: http://$(DRYCC_INFLUXDB_SERVICE_HOST):$(DRYCC_INFLUXDB_SERVICE_PORT_TRANSPORT)
{{- end }}
- name: "INFLUXDB_BUCKET"
valueFrom:
secretKeyRef:
name: influxdb-creds
key: bucket
- name: "INFLUXDB_ORG"
valueFrom:
secretKeyRef:
name: influxdb-creds
key: org
- name: "INFLUXDB_TOKEN"
valueFrom:
secretKeyRef:
name: influxdb-creds
key: token
{{- range $key, $value := .Values.environment }}
- name: {{ $key }}
value: {{ $value | quote }}
{{- end }}
{{- end }}

{{/* Generate controller deployment limits */}}
{{- define "controller.limits" -}}
{{- if or (.Values.limits_cpu) (.Values.limits_memory) }}
resources:
limits:
{{- if (.Values.limits_cpu) }}
cpu: {{.Values.limits_cpu}}
{{- end }}
{{- if (.Values.limits_memory) }}
memory: {{.Values.limits_memory}}
{{- end }}
{{- end }}
{{- end }}


{{/* Generate controller deployment volumeMounts */}}
{{- define "controller.volumeMounts" -}}
volumeMounts:
- mountPath: /etc/slugrunner
name: slugrunner-config
readOnly: true
{{- end }}
71 changes: 71 additions & 0 deletions charts/controller/templates/controller-celery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: drycc-controller-celery
labels:
heritage: drycc
annotations:
component.drycc.cc/version: {{ .Values.image_tag }}
spec:
replicas: {{ .Values.celery_replicas }}
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
type: RollingUpdate
selector:
matchLabels:
app: drycc-controller-celery
template:
metadata:
labels:
app: drycc-controller-celery
spec:
serviceAccount: drycc-controller-celery
containers:
- name: drycc-controller-celery-high
image: {{.Values.image_registry}}{{.Values.org}}/controller:{{.Values.image_tag}}
command:
- /bin/bash
- -c
args:
- celery -A api worker -Q priority.high --autoscale=32,1 --loglevel=WARNING
imagePullPolicy: {{.Values.image_pull_policy}}
{{- include "controller.limits" . | indent 10 }}
{{- include "controller.envs" . | indent 10 }}
volumeMounts:
- mountPath: /etc/slugrunner
name: slugrunner-config
readOnly: true
- name: drycc-controller-celery-middle
image: {{.Values.image_registry}}{{.Values.org}}/controller:{{.Values.image_tag}}
command:
- /bin/bash
- -c
args:
- celery -A api worker -Q priority.middle --autoscale=16,1 --loglevel=WARNING
{{- include "controller.limits" . | indent 10 }}
{{- include "controller.envs" . | indent 10 }}
volumeMounts:
- mountPath: /etc/slugrunner
name: slugrunner-config
readOnly: true
imagePullPolicy: {{.Values.image_pull_policy}}
- name: drycc-controller-celery-low
image: {{.Values.image_registry}}{{.Values.org}}/controller:{{.Values.image_tag}}
command:
- /bin/bash
- -c
args:
- celery -A api worker -Q priority.low --autoscale=8,1 --loglevel=WARNING
{{- include "controller.limits" . | indent 10 }}
{{- include "controller.envs" . | indent 10 }}
volumeMounts:
- mountPath: /etc/slugrunner
name: slugrunner-config
readOnly: true
imagePullPolicy: {{.Values.image_pull_policy}}
volumes:
- name: slugrunner-config
configMap:
name: slugrunner-config
48 changes: 48 additions & 0 deletions charts/controller/templates/controller-cronjob-daily.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: drycc-controller-cronjob-daily
labels:
heritage: drycc
annotations:
component.drycc.cc/version: {{ .Values.image_tag }}
spec:
failedJobsHistoryLimit: 1
schedule: "0 0 * * *"
successfulJobsHistoryLimit: 3
jobTemplate:
spec:
template:
spec:
restartPolicy: OnFailure
containers:
- image: {{.Values.image_registry}}{{.Values.org}}/controller:{{.Values.image_tag}}
imagePullPolicy: {{.Values.image_pull_policy}}
name: drycc-controller-push-data-to-influxdb
command:
- /bin/bash
- -c
args:
- python /app/manage.py push_data_to_influxdb
{{- include "controller.envs" . | indent 12 }}
volumeMounts:
- mountPath: /etc/slugrunner
name: slugrunner-config
readOnly: true
- image: {{.Values.image_registry}}{{.Values.org}}/controller:{{.Values.image_tag}}
imagePullPolicy: {{.Values.pull_policy}}
name: drycc-controller-load-db-state-to-k8s
command:
- /bin/bash
- -c
args:
- python -u /app/manage.py load_db_state_to_k8s
{{- include "controller.envs" . | indent 12 }}
volumeMounts:
- mountPath: /etc/slugrunner
name: slugrunner-config
readOnly: true
volumes:
- name: slugrunner-config
configMap:
name: slugrunner-config
Loading

0 comments on commit db1245a

Please sign in to comment.