From bda536ebd906ea4176db915fe7b697907ac2be38 Mon Sep 17 00:00:00 2001
From: lijianguo <lijianguo@zhumengyuan.com>
Date: Fri, 11 Dec 2020 14:54:19 +0800
Subject: [PATCH] feat(chart): add celery deployment and cronjob

---
 charts/controller/templates/_helpers.tmpl     |  12 --
 charts/controller/templates/_helpers.tpl      | 164 ++++++++++++++++++
 .../templates/controller-celery.yaml          |  72 ++++++++
 .../templates/controller-cronjob-daily.yaml   |  48 +++++
 .../templates/controller-deployment.yaml      | 137 +--------------
 charts/controller/values.yaml                 |   3 +-
 rootfs/api/influxdata.py                      |  70 ++++++++
 .../commands/push_data_to_influxdb.py         |  17 ++
 rootfs/api/models/config.py                   |  14 ++
 rootfs/api/models/resource.py                 |   6 +
 rootfs/api/models/volume.py                   |   6 +
 rootfs/bin/boot                               |   9 -
 12 files changed, 401 insertions(+), 157 deletions(-)
 delete mode 100644 charts/controller/templates/_helpers.tmpl
 create mode 100644 charts/controller/templates/_helpers.tpl
 create mode 100644 charts/controller/templates/controller-celery.yaml
 create mode 100644 charts/controller/templates/controller-cronjob-daily.yaml
 create mode 100644 rootfs/api/influxdata.py
 create mode 100644 rootfs/api/management/commands/push_data_to_influxdb.py

diff --git a/charts/controller/templates/_helpers.tmpl b/charts/controller/templates/_helpers.tmpl
deleted file mode 100644
index 422a5ae3f..000000000
--- a/charts/controller/templates/_helpers.tmpl
+++ /dev/null
@@ -1,12 +0,0 @@
-{{/*
-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 -}}
diff --git a/charts/controller/templates/_helpers.tpl b/charts/controller/templates/_helpers.tpl
new file mode 100644
index 000000000..d2490cf63
--- /dev/null
+++ b/charts/controller/templates/_helpers.tpl
@@ -0,0 +1,164 @@
+{{/*
+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 }}
+- 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 "off-cluster" .Values.global.database_location) }}
+- 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 (.Values.global.redis_location) and eq "on-cluster" .Values.global.redis_location }}
+- 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 (.Values.global.redis_location) and (eq "off-cluster" .Values.global.redis_location) }}
+- name: DRYCC_REDIS_ADDRS
+  valueFrom:
+    secretKeyRef:
+      name: redis-creds
+      key: addrs
+{{- end }}
+- name: DRYCC_REDIS_PASSWORD
+  valueFrom:
+    secretKeyRef:
+      name: redis-creds
+      key: password
+{{- if (.Values.global.influxdb_location) and eq (.Values.global.influxdb_location) "off-cluster" }}
+- name: "INFLUXDB_URL"
+  valueFrom:
+    secretKeyRef:
+      name: influxdb-creds
+      key: url
+- name: "INFLUXDB_DATABASE"
+  valueFrom:
+    secretKeyRef:
+      name: influxdb-creds
+      key: database
+- name: "INFLUXDB_USER"
+  valueFrom:
+    secretKeyRef:
+      name: influxdb-creds
+      key: user
+- name: "INFLUXDB_PASSWORD"
+  valueFrom:
+    secretKeyRef:
+      name: influxdb-creds
+      key: password
+{{- else }}
+- name: "INFLUXDB_URL"
+  value: http://$(DRYCC_INFLUXDB_SERVICE_HOST):$(DRYCC_INFLUXDB_SERVICE_PORT_TRANSPORT)
+{{- end }}
+{{- 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 }}
diff --git a/charts/controller/templates/controller-celery.yaml b/charts/controller/templates/controller-celery.yaml
new file mode 100644
index 000000000..e16e13299
--- /dev/null
+++ b/charts/controller/templates/controller-celery.yaml
@@ -0,0 +1,72 @@
+{{ $redisNodeCount := .Values.redis.replicas | int }}
+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
diff --git a/charts/controller/templates/controller-cronjob-daily.yaml b/charts/controller/templates/controller-cronjob-daily.yaml
new file mode 100644
index 000000000..ac203606a
--- /dev/null
+++ b/charts/controller/templates/controller-cronjob-daily.yaml
@@ -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
diff --git a/charts/controller/templates/controller-deployment.yaml b/charts/controller/templates/controller-deployment.yaml
index 20e70e42a..26ae5bbfa 100644
--- a/charts/controller/templates/controller-deployment.yaml
+++ b/charts/controller/templates/controller-deployment.yaml
@@ -43,141 +43,8 @@ spec:
           ports:
             - containerPort: 8000
               name: http
-{{- 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 }}
-          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
-          - name: "INFLUXDB_DATABASE"
-            valueFrom:
-              secretKeyRef:
-                name: influxdb-creds
-                key: database
-          - name: "INFLUXDB_USER"
-            valueFrom:
-              secretKeyRef:
-                name: influxdb-creds
-                key: user
-          - name: "INFLUXDB_PASSWORD"
-            valueFrom:
-              secretKeyRef:
-                name: influxdb-creds
-                key: password
-          {{- else }}
-          - name: "INFLUXDB_URL"
-            value: http://$(DRYCC_INFLUXDB_SERVICE_HOST):$(DRYCC_INFLUXDB_SERVICE_PORT_TRANSPORT)
-          {{- end }}
-          {{- range $key, $value := .Values.environment }}
-          - name: {{ $key }}
-            value: {{ $value | quote }}
-          {{- end }}
+          {{- include "controller.limits" . | indent 10 }}
+          {{- include "controller.envs" . | indent 10 }}
           volumeMounts:
             - mountPath: /etc/slugrunner
               name: slugrunner-config
diff --git a/charts/controller/values.yaml b/charts/controller/values.yaml
index 819ba9ae6..5b151513c 100644
--- a/charts/controller/values.yaml
+++ b/charts/controller/values.yaml
@@ -15,9 +15,10 @@ deploy_hook_urls: ""
 registration_mode: "admin_only"
 # Option to disable ssl verification to connect to k8s api server
 k8s_api_verify_tls: "true"
-
 # Set storageClassName, It is used for application mount.
 app_storage_class: ""
+# Set celery replicas
+celery_replicas: 1
 
 # Any custom controller environment variables
 # can be specified as key-value pairs under environment
diff --git a/rootfs/api/influxdata.py b/rootfs/api/influxdata.py
new file mode 100644
index 000000000..7e94f986d
--- /dev/null
+++ b/rootfs/api/influxdata.py
@@ -0,0 +1,70 @@
+from datetime import datetime
+
+from api.utils import get_influxdb_client
+
+
+class InfluxProxy(object):
+    def __init__(self):
+        self.c = get_influxdb_client()
+
+    def query(self, q):
+        rs = self.c.query(q)
+        return rs
+
+    def write_points(self, body):
+        self.c.write_points(body)
+
+    @staticmethod
+    def drycc_volume_manifest(namespace, volume_name, **kwargs):
+        data = [{
+            "measurement": "drycc_volume",
+            "tags": {
+                "volume_name": volume_name,
+                "namespace": namespace
+            },
+            "time": datetime.now(),
+            "fields": {
+                "size": kwargs.get('size')
+            }
+        }]
+        return data
+
+    @staticmethod
+    def drycc_limit_manifest(namespace, type, **kwargs):
+        data = [{
+            "measurement": "drycc_limit",
+            "tags": {
+                "type": type,
+                "namespace": namespace
+            },
+            "time": datetime.now(),
+            "fields": {
+                "cpu": kwargs.get('cpu'),
+                "memory": kwargs.get('memory')
+            }
+        }]
+        return data
+
+    @staticmethod
+    def drycc_resource_manifest(namespace, name, **kwargs):
+        data = [{
+            "measurement": "drycc_resource",
+            "tags": {
+                "name": name,  # resource name
+                "namespace": namespace
+            },
+            "time": datetime.now(),
+            "fields": {
+                "plan": kwargs.get('plan')
+            }
+        }]
+        return data
+
+
+influx_client = InfluxProxy()
+
+if __name__ == '__main__':
+    q = '''SELECT last("rx_bytes") FROM "kubernetes_pod_network"
+       WHERE ("namespace" = 'py3django3') AND time >= now() - 5m
+       GROUP BY time(5m), "pod_name" fill(null)'''
+    influx_client.query(q)
diff --git a/rootfs/api/management/commands/push_data_to_influxdb.py b/rootfs/api/management/commands/push_data_to_influxdb.py
new file mode 100644
index 000000000..1ba40639d
--- /dev/null
+++ b/rootfs/api/management/commands/push_data_to_influxdb.py
@@ -0,0 +1,17 @@
+from django.core.management.base import BaseCommand
+
+from api.models import App
+
+
+class Command(BaseCommand):
+    """Management command for push data to influxdb"""
+    def handle(self, *args, **options):
+        print("push data to influxdb")
+        apps = App.objects.all()
+        for app in apps:
+            for volume in app.volume_set():
+                volume.to_influx()
+            for resource in app.resource_set():
+                resource.to_influx()
+            for config in app.config_set().latest():
+                config.to_influx()
diff --git a/rootfs/api/models/config.py b/rootfs/api/models/config.py
index 4455e2cd5..daf592e75 100644
--- a/rootfs/api/models/config.py
+++ b/rootfs/api/models/config.py
@@ -4,6 +4,7 @@
 from jsonfield import JSONField
 import json
 
+from api.influxdata import influx_client
 from api.models.release import Release
 from api.models import UuidAuditedModel
 from api.exceptions import DryccException, UnprocessableEntity
@@ -195,3 +196,16 @@ def save(self, **kwargs):
             self.set_tags({'tags': {}})
 
         return super(Config, self).save(**kwargs)
+
+    def to_influx(self):
+        bodys = []
+        types = self.app.procfile_structure.keys()
+        limits = json.loads(settings.KUBERNETES_NAMESPACE_DEFAULT_LIMIT_RANGES_SPEC)
+        limits_default = limits.get('limits')[0].get('default')
+        for type in types:
+            body = influx_client.drycc_limit_manifest(
+                self.app, type,
+                cpu=self.cpu.get(type, limits_default.get('cpu')),
+                memory=self.memory.get(type, limits_default.get('memory')))
+            bodys.append(body)
+        influx_client.write_points(bodys)
diff --git a/rootfs/api/models/resource.py b/rootfs/api/models/resource.py
index 7c5de6c85..a1d375807 100644
--- a/rootfs/api/models/resource.py
+++ b/rootfs/api/models/resource.py
@@ -6,6 +6,7 @@
 from api.models import UuidAuditedModel, validate_label
 from scheduler import KubeException
 from . import resource_changed
+from ..influxdata import influx_client
 
 logger = logging.getLogger(__name__)
 
@@ -199,3 +200,8 @@ def detach_resource(self, *args, **kwargs):
 
         if (self.status != "Ready") or (not self.binding):
             self.delete()
+
+    def to_influx(self):
+        body = influx_client.drycc_resource_manifest(
+            self.app, self.name, plan=self.plan)
+        influx_client.write_points(body)
diff --git a/rootfs/api/models/volume.py b/rootfs/api/models/volume.py
index 6dddb1625..483ae2ed3 100644
--- a/rootfs/api/models/volume.py
+++ b/rootfs/api/models/volume.py
@@ -3,6 +3,7 @@
 from django.conf import settings
 from jsonfield import JSONField
 from api.exceptions import DryccException, ServiceUnavailable, AlreadyExists
+from api.influxdata import influx_client
 from api.models import UuidAuditedModel, validate_label
 from scheduler import KubeException
 
@@ -90,3 +91,8 @@ def log(self, message, level=logging.INFO):
         accordingly.
         """
         logger.log(level, "[{}]: {}".format(self.id, message))
+
+    def to_influx(self):
+        body = influx_client.drycc_volume_manifest(
+            self.app, self.name, size=self.size)
+        influx_client.write_points(body)
diff --git a/rootfs/bin/boot b/rootfs/bin/boot
index 6bb6abdab..a9c3a1e33 100755
--- a/rootfs/bin/boot
+++ b/rootfs/bin/boot
@@ -32,15 +32,6 @@ echo ""
 echo "Starting up Gunicorn"
 gunicorn -c /app/drycc/gunicorn/config.py api.wsgi &
 
-echo ""
-echo "Loading database information to Kubernetes in the background"
-echo "Log of the run can be found in /app/data/logs/load_db_state_to_k8s.log"
-# python -u avoids output buffering
-nohup python -u /app/manage.py load_db_state_to_k8s > /app/data/logs/load_db_state_to_k8s.log &
-# celery
-nohup su-exec nobody celery -A api worker -Q priority.low --autoscale=8,1 --loglevel=WARNING > /app/data/logs/celery.log 2>&1 &
-nohup su-exec nobody celery -A api worker -Q priority.middle --autoscale=16,1 --loglevel=WARNING > /app/data/logs/celery.log 2>&1 &
-nohup su-exec nobody celery -A api worker -Q priority.high --autoscale=32,1 --loglevel=WARNING > /app/data/logs/celery.log 2>&1 &
 # smart shutdown on SIGTERM (SIGINT is handled by gunicorn)
 function on_exit() {
 	GUNICORN_PID=$(cat /tmp/gunicorn.pid)
