Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/drycc/controller into main
Browse files Browse the repository at this point in the history
  • Loading branch information
duanhongyi committed Dec 10, 2020
2 parents 86e8816 + f80e067 commit a8227ee
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 14 deletions.
25 changes: 25 additions & 0 deletions charts/controller/templates/controller-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,31 @@ spec:
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 }}
Expand Down
36 changes: 22 additions & 14 deletions rootfs/api/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,20 +443,6 @@
}
}

DRYCC_REDIS_ADDRS = os.environ.get('DRYCC_REDIS_ADDRS', '127.0.0.1:6379').split(",")
DRYCC_REDIS_PASSWORD = os.environ.get('DRYCC_REDIS_PASSWORD', '')

CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": ['redis://:{}@{}'.format(DRYCC_REDIS_PASSWORD, DRYCC_REDIS_ADDR) \
for DRYCC_REDIS_ADDR in DRYCC_REDIS_ADDRS], # noqa
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.ShardClient",
}
}
}

APP_URL_REGEX = '[a-z0-9-]+'

# LDAP settings taken from environment variables.
Expand Down Expand Up @@ -514,6 +500,22 @@
AUTH_LDAP_FIND_GROUP_PERMS = True
AUTH_LDAP_CACHE_GROUPS = False

# Redis Configuration
DRYCC_REDIS_ADDRS = os.environ.get('DRYCC_REDIS_ADDRS', '127.0.0.1:6379').split(",")
DRYCC_REDIS_PASSWORD = os.environ.get('DRYCC_REDIS_PASSWORD', '')

# Cache Configuration
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": ['redis://:{}@{}'.format(DRYCC_REDIS_PASSWORD, DRYCC_REDIS_ADDR) \
for DRYCC_REDIS_ADDR in DRYCC_REDIS_ADDRS], # noqa
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.ShardClient",
}
}
}

# Celery Configuration Options
CELERY_TIMEZONE = "Asia/Shanghai"
CELERY_ENABLE_UTC = True
Expand All @@ -525,3 +527,9 @@
CELERY_RESULT_BACKEND = 'redis://:{}@{}'.format(DRYCC_REDIS_PASSWORD, DRYCC_REDIS_ADDRS[0]) # noqa
CELERY_CACHE_BACKEND = 'django-cache'
CELERY_DEFAULT_QUEUE = 'priority.middle'

# Influxdb Configuration Options
INFLUXDB_URL = os.environ.get('DRYCC_INFLUXDB_URL', 'http://localhost:8086')
INFLUXDB_DATABASE = os.environ.get('DRYCC_INFLUXDB_DATABASE', 'drycc')
INFLUXDB_USER = os.environ.get('DRYCC_INFLUXDB_USER', 'root')
INFLUXDB_PASSWORD = os.environ.get('DRYCC_INFLUXDB_PASSWORD', 'root')
23 changes: 23 additions & 0 deletions rootfs/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@
import hashlib
import logging
import random
import threading
from copy import deepcopy
from urllib.parse import urlparse
from django.conf import settings
from influxdb import InfluxDBClient


local = threading.local()
logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -160,6 +166,23 @@ def apply_tasks(tasks):
executor.shutdown(wait=True)


def get_influxdb_client():
if not hasattr(local, "influxdb_client"):
addr = urlparse(settings.INFLUXDB_URL).netloc
if ":" in addr:
host, port = addr.rsplit(":")
else:
host, port = addr, 8086
local.influxdb_client = InfluxDBClient(
host,
port,
settings.INFLUXDB_USER,
settings.INFLUXDB_PASSWORD,
settings.INFLUXDB_DATABASE
)
return local.influxdb_client


if __name__ == "__main__":
import doctest
doctest.testmod()
1 change: 1 addition & 0 deletions rootfs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ requests==2.24.0
requests-toolbelt==0.9.1
celery==5.0.2
django_redis==4.12.1
influxdb==5.3.1

0 comments on commit a8227ee

Please sign in to comment.