diff --git a/openstack_operator/heat.py b/openstack_operator/heat.py index 84baa525..40e99f11 100644 --- a/openstack_operator/heat.py +++ b/openstack_operator/heat.py @@ -33,9 +33,11 @@ def create_or_resume(name, spec, **_): start the service up for the first time. """ + env = utils.get_uwsgi_env() for component in ("api", "api-cfn"): utils.create_or_update('heat/deployment.yml.j2', - name=name, spec=spec, component=component) + name=name, spec=spec, + component=component, env=env) utils.create_or_update('heat/service.yml.j2', name=name, component=component) diff --git a/openstack_operator/horizon.py b/openstack_operator/horizon.py index 1c944c4d..19c83d54 100644 --- a/openstack_operator/horizon.py +++ b/openstack_operator/horizon.py @@ -51,8 +51,10 @@ def create_or_resume(namespace, name, spec, **_): config = utils.create_or_update('horizon/configmap.yml.j2', name=name, spec=spec, auth_url=auth_url) config_hash = utils.generate_hash(config.obj['data']) + env = utils.get_uwsgi_env() utils.create_or_update('horizon/deployment.yml.j2', - config_hash=config_hash, name=name, spec=spec) + config_hash=config_hash, name=name, + spec=spec, env=env) utils.create_or_update('horizon/service.yml.j2', name=name, spec=spec) utils.create_or_update('horizon/memcached.yml.j2', @@ -74,8 +76,10 @@ def update(name, spec, **_): config = utils.create_or_update('horizon/configmap.yml.j2', name=name, spec=spec, auth_url=auth_url) config_hash = utils.generate_hash(config.obj['data']) + env = utils.get_uwsgi_env() utils.create_or_update('horizon/deployment.yml.j2', - config_hash=config_hash, name=name, spec=spec) + config_hash=config_hash, name=name, + spec=spec, env=env) if hasattr(spec, "ingress"): utils.create_or_update('horizon/ingress.yml.j2', name=name, spec=spec) diff --git a/openstack_operator/keystone.py b/openstack_operator/keystone.py index 11a24522..959b64a1 100644 --- a/openstack_operator/keystone.py +++ b/openstack_operator/keystone.py @@ -30,9 +30,9 @@ def create_or_resume(name, spec, **_): This function is called when a new resource is created but also when we start the service up for the first time. """ - + env = utils.get_uwsgi_env() utils.create_or_update('keystone/deployment.yml.j2', - name=name, spec=spec) + name=name, spec=spec, env=env) utils.create_or_update('keystone/service.yml.j2', name=name, spec=spec) utils.create_or_update('keystone/horizontalpodautoscaler.yml.j2', diff --git a/openstack_operator/templates/heat/deployment.yml.j2 b/openstack_operator/templates/heat/deployment.yml.j2 index 33242463..b9a7010c 100644 --- a/openstack_operator/templates/heat/deployment.yml.j2 +++ b/openstack_operator/templates/heat/deployment.yml.j2 @@ -39,6 +39,13 @@ spec: - name: heat-{{ component }} image: vexxhost/heat-{{ component }}:latest imagePullPolicy: Always + {% if env is defined %} + env: + {% for v in env %} + - name: "{{ v.name }}" + value: "{{ v.value }}" + {% endfor %} + {% endif %} {% if 'api' in component %} ports: - name: heat-{{ component }} diff --git a/openstack_operator/templates/horizon/deployment.yml.j2 b/openstack_operator/templates/horizon/deployment.yml.j2 index d7ce451b..06287e00 100644 --- a/openstack_operator/templates/horizon/deployment.yml.j2 +++ b/openstack_operator/templates/horizon/deployment.yml.j2 @@ -36,6 +36,10 @@ spec: image: vexxhost/horizon:latest imagePullPolicy: Always env: + {% for v in env %} + - name: "{{ v.name }}" + value: "{{ v.value }}" + {% endfor %} - name: SECRET_KEY valueFrom: secretKeyRef: diff --git a/openstack_operator/templates/keystone/deployment.yml.j2 b/openstack_operator/templates/keystone/deployment.yml.j2 index 728acf49..321d4edd 100644 --- a/openstack_operator/templates/keystone/deployment.yml.j2 +++ b/openstack_operator/templates/keystone/deployment.yml.j2 @@ -33,6 +33,11 @@ spec: - name: keystone image: vexxhost/keystone:latest imagePullPolicy: Always + env: + {% for v in env %} + - name: "{{ v.name }}" + value: "{{ v.value }}" + {% endfor %} ports: - name: keystone containerPort: 5000 diff --git a/openstack_operator/utils.py b/openstack_operator/utils.py index 3139346c..a9052457 100644 --- a/openstack_operator/utils.py +++ b/openstack_operator/utils.py @@ -35,6 +35,24 @@ from openstack_operator import objects DIR_PATH = os.path.dirname(os.path.realpath(__file__)) + +UWSGI_SETTINGS = { + 'UWSGI_ENABLE_THREADS': True, + 'UWSGI_PROCESSES': 2, + 'UWSGI_EXIT_ON_RELOAD': True, + 'UWSGI_DIE_ON_TERM': True, + 'UWSGI_LAZY_APPS': True, + 'UWSGI_ADD_HEADER': 'Connection: close', + 'UWSGI_BUFFER_SIZE': 65535, + 'UWSGI_THUNDER_LOCK': True, + 'UWSGI_DISABLE_LOGGING': True, + 'UWSGI_AUTO_CHUNCKED': True, + 'UWSGI_HTTP_RAW_BODY': True, + 'UWSGI_SOCKET_TIMEOUT': 10, + 'UWSGI_NEED_APP': True, + 'UWSGI_ROUTE_USER_AGENT': '^kube-probe.* donotlog:' +} + VERSION = version.VersionInfo('openstack_operator').version_string() @@ -194,8 +212,16 @@ def get_secret(namespace, name): def generate_hash(dictionary): - """Generate a has from a dictionary, return None if dictionary is empty""" + """Generate a hash from a dictionary, return None if dictionary is empty""" if not dictionary: return None return hash(frozenset(dictionary.items())) + + +def get_uwsgi_env(): + """Generate k8s env list from UWSGI_SETTINGS dict""" + res = [] + for key, value in UWSGI_SETTINGS.items(): + res.append({'name': key, 'value': value}) + return res