From 8049b5075d2ab4285a515f284875738b77f5a1c2 Mon Sep 17 00:00:00 2001 From: Alexander Cherepanov Date: Mon, 29 May 2023 23:35:43 +0600 Subject: [PATCH] Helm chart: added configuration of uwsgi using environment variables (#2045) # What this PR does Adds `uwsgi` configuration to helm chart. Sets environment variables with name capitalized and prefixed with `UWSGI_`, and dashes are substituted with underscores like described [here](https://uwsgi-docs.readthedocs.io/en/latest/Configuration.html#environment-variables) Sets `UWSGI_LISTEN=1024` by default, but can be overwritten or completely removed by `uwsgi: null` Or is it better to not specify default value (it's not backward compatible)? Also, small indentation fixes for postgresql configuration. ## Which issue(s) this PR fixes closes https://github.com/grafana/oncall/issues/562 Also, [this PR](https://github.com/grafana/oncall/pull/856) has been closed because of this PR ## Checklist - [x] Unit, integration, and e2e (if applicable) tests updated - [ ] Documentation added (or `pr:no public docs` PR label added if not required) - [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not required) Co-authored-by: Joey Orlando --- CHANGELOG.md | 2 ++ helm/oncall/templates/_env.tpl | 12 +++++-- helm/oncall/templates/_helpers.tpl | 14 ++++---- helm/oncall/tests/uwsgi_env_test.yaml | 49 +++++++++++++++++++++++++++ helm/oncall/values.yaml | 6 ++++ 5 files changed, 74 insertions(+), 9 deletions(-) create mode 100644 helm/oncall/tests/uwsgi_env_test.yaml diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e1811a5..b6554cdb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add models and framework to use different services (Phone, SMS, Verify) in Twilio depending on the destination country code by @mderynck ([#1976](https://github.com/grafana/oncall/pull/1976)) - Prometheus exporter backend for alert groups related metrics +- Helm chart: configuration of `uwsgi` using environment variables by @alexintech ([#2045](https://github.com/grafana/oncall/pull/2045)) - Much expanded/improved docs for mobile app ([2026](https://github.com/grafana/oncall/pull/2026>)) - Enable by-day selection when defining monthly and hourly rotations ([2037](https://github.com/grafana/oncall/pull/2037)) @@ -19,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix error when updating closed modal window in Slack by @vadimkerr ([#2019](https://github.com/grafana/oncall/pull/2019)) - Fix final schedule export failing to update when ical imported events set start/end as date ([#2025](https://github.com/grafana/oncall/pull/2025)) +- Helm chart: fix bugs in helm chart with external postgresql configuration by @alexintech ([#2036](https://github.com/grafana/oncall/pull/2036)) - Properly address `Organization.DoesNotExist` exceptions thrown which result in HTTP 500 for the Slack `interactive_api_endpoint` endpoint by @joeyorlando ([#2040](https://github.com/grafana/oncall/pull/2040)) diff --git a/helm/oncall/templates/_env.tpl b/helm/oncall/templates/_env.tpl index 05bff9a0..f269f37d 100644 --- a/helm/oncall/templates/_env.tpl +++ b/helm/oncall/templates/_env.tpl @@ -19,8 +19,7 @@ value: "admin" - name: OSS value: "True" -- name: UWSGI_LISTEN - value: "1024" +{{- template "snippet.oncall.uwsgi" . }} - name: BROKER_TYPE value: {{ .Values.broker.type | default "rabbitmq" }} - name: GRAFANA_API_URL @@ -51,6 +50,15 @@ MIRAGE_SECRET_KEY {{- end -}} {{- end -}} +{{- define "snippet.oncall.uwsgi" -}} +{{- if .Values.uwsgi -}} + {{- range $key, $value := .Values.uwsgi }} +- name: UWSGI_{{ $key | upper | replace "-" "_" }} + value: {{ $value | quote }} + {{- end -}} +{{- end -}} +{{- end -}} + {{- define "snippet.oncall.slack.env" -}} {{- if .Values.oncall.slack.enabled -}} - name: FEATURE_SLACK_INTEGRATION_ENABLED diff --git a/helm/oncall/templates/_helpers.tpl b/helm/oncall/templates/_helpers.tpl index 110bc525..1566deb1 100644 --- a/helm/oncall/templates/_helpers.tpl +++ b/helm/oncall/templates/_helpers.tpl @@ -91,7 +91,7 @@ Create the name of the service account to use imagePullPolicy: {{ .Values.image.pullPolicy }} command: ['sh', '-c', "until (python manage.py migrate --check); do echo Waiting for database migrations; sleep 2; done"] securityContext: - {{ toYaml .Values.init.securityContext| nindent 4}} + {{ toYaml .Values.init.securityContext | nindent 4 }} env: {{- include "snippet.oncall.env" . | nindent 4 }} {{- include "snippet.mysql.env" . | nindent 4 }} @@ -116,13 +116,13 @@ Create the name of the service account to use imagePullPolicy: {{ .Values.image.pullPolicy }} command: ['sh', '-c', "until (python manage.py migrate --check); do echo Waiting for database migrations; sleep 2; done"] securityContext: - {{ toYaml .Values.init.securityContext| nindent 4}} + {{ toYaml .Values.init.securityContext | nindent 4 }} env: - {{- include "snippet.oncall.env" . | nindent 12 }} - {{- include "snippet.postgresql.env" . | nindent 12 }} - {{- include "snippet.rabbitmq.env" . | nindent 12 }} - {{- include "snippet.redis.env" . | nindent 12 }} + {{- include "snippet.oncall.env" . | nindent 4 }} + {{- include "snippet.postgresql.env" . | nindent 4 }} + {{- include "snippet.rabbitmq.env" . | nindent 4 }} + {{- include "snippet.redis.env" . | nindent 4 }} {{- if .Values.env }} - {{- toYaml .Values.env | nindent 12 }} + {{- toYaml .Values.env | nindent 4 }} {{- end }} {{- end }} diff --git a/helm/oncall/tests/uwsgi_env_test.yaml b/helm/oncall/tests/uwsgi_env_test.yaml new file mode 100644 index 00000000..7986c361 --- /dev/null +++ b/helm/oncall/tests/uwsgi_env_test.yaml @@ -0,0 +1,49 @@ +suite: test uwsgi environment variables +templates: + - engine/deployment.yaml + - engine/job-migrate.yaml + - celery/deployment-celery.yaml +release: + name: oncall +tests: + - it: uwsgi.listen should overwrite UWSGI_LISTEN env + set: + uwsgi.listen: 128 + asserts: + - contains: + path: spec.template.spec.containers[0].env + content: + name: UWSGI_LISTEN + value: "128" + - it: uwsgi.envs should set multiple UWSGI_* envs + set: + uwsgi: + processes: 3 + max-requests: 1000 + asserts: + - contains: + path: spec.template.spec.containers[0].env + content: + name: UWSGI_LISTEN + value: "1024" + - contains: + path: spec.template.spec.containers[0].env + content: + name: UWSGI_PROCESSES + value: "3" + - contains: + path: spec.template.spec.containers[0].env + content: + name: UWSGI_MAX_REQUESTS + value: "1000" + - it: uwsgi.null should not set any UWSGI_* variable + set: + uwsgi: null + asserts: + - notContains: + path: spec.template.spec.containers[0].env + content: + name: UWSGI_LISTEN + + + diff --git a/helm/oncall/values.yaml b/helm/oncall/values.yaml index a3447cdd..fa97f014 100644 --- a/helm/oncall/values.yaml +++ b/helm/oncall/values.yaml @@ -166,6 +166,12 @@ migrate: # use a helm hook to manage the migration job useHook: false +# Sets environment variables with name capitalized and prefixed with UWSGI_, and dashes are substituted with underscores. +# see more: https://uwsgi-docs.readthedocs.io/en/latest/Configuration.html#environment-variables +# Set null to disable all UWSGI environment variables +uwsgi: + listen: 1024 + # Additional env variables to add to deployments env: {}