From 2f518e4fd44ed2051b28d7bcd69059523f0bfabd Mon Sep 17 00:00:00 2001 From: Fabian Wiesel Date: Wed, 20 Jul 2022 14:15:46 +0200 Subject: [PATCH] [utils] ProxySql side-car cleanup in prep for placement - A couple of macros were duplicated, they got removed. - The check for valid modes (unix_socket, host_alias) was fixed - The version of proxysql gets a patch version update - Removed the check for Dependency.Enabled, as disabled ones do not appear among the dependencies - The proxysql setting can now point with proxysql.force_enable to a list of database settings which are disabled. This is needed for proxysql as long as it runs with the nova-api database --- openstack/utils/templates/_helpers.tpl | 86 ---------------- openstack/utils/templates/_hosts.tpl | 7 +- .../templates/_proxy_sql_configmap.yaml.tpl | 98 ------------------- openstack/utils/templates/_proxysql.tpl | 21 ++-- .../templates/_proxysql_configmap.yaml.tpl | 5 +- 5 files changed, 25 insertions(+), 192 deletions(-) delete mode 100644 openstack/utils/templates/_proxy_sql_configmap.yaml.tpl diff --git a/openstack/utils/templates/_helpers.tpl b/openstack/utils/templates/_helpers.tpl index 9b2d9ba795..9471d2b376 100644 --- a/openstack/utils/templates/_helpers.tpl +++ b/openstack/utils/templates/_helpers.tpl @@ -70,89 +70,3 @@ trace_sqlalchemy = {{ .Values.global.osprofiler.trace_sqlalchemy }} {{- end }} {{- end }} -{{- define "utils.proxysql.volume_mount" }} - {{- if .Values.proxysql }} - {{- if .Values.proxysql.mode }}{{/* Always mount it, it doesn't cost much and eases migrations */}} -- mountPath: /run/proxysql - name: runproxysql - {{- end }} - {{- end }} -{{- end }} - -{{- define "utils.proxysql.container" }} - {{- if .Values.proxysql }} - {{- if .Values.proxysql.mode }} -- name: proxysql - image: {{ required ".Values.global.dockerHubMirror is missing" .Values.global.dockerHubMirror}}/{{ default "proxysql/proxysql" .Values.proxysql.image }}:{{ .Values.proxysql.imageTag | default "2.4.1-debian" }} - imagePullPolicy: IfNotPresent - command: ["proxysql"] - args: ["--config", "/etc/proxysql/proxysql.cnf", "--exit-on-error", "--foreground", "--idle-threads", "--admin-socket", "/run/proxysql/admin.sock", "--no-version-check", "-D", "/run/proxysql"] - ports: - - name: metrics-psql - containerPort: {{ default 6070 .Values.proxysql.restapi_port }} - livenessProbe: - exec: - command: - - test - - -S - - /run/proxysql/mysql.sock - volumeMounts: - - mountPath: /etc/proxysql - name: etcproxysql - {{- include "utils.proxysql.volume_mount" . | indent 2 }} - {{- end }} - {{- end }} -{{- end }} - -{{- define "utils.proxysql.volumes" }} - {{- if .Values.proxysql }} - {{- if .Values.proxysql.mode }} -- name: runproxysql - emptyDir: {} -- name: etcproxysql - configMap: - name: {{ .Release.Name }}-proxysql-etc - {{- end }} - {{- end }} -{{- end }} - -# Place this to the pod spec to reroute the traffic via hostAliases -{{- define "utils.proxysql.pod_settings" }} - {{- if .Values.proxysql }} - {{- if .Values.proxysql.mode }} - {{- $envAll := . }} -hostAliases: -- ip: "127.0.0.1" - hostnames: - {{- range $d := .Chart.Dependencies }} - {{- if and $d.Enabled (hasPrefix "mariadb" $d.Name)}} - - {{ print (get $envAll.Values $d.Name).name "-mariadb" | quote }} - {{- end }} - {{- end }} - {{- end }} - {{- end }} -{{- end }} - - -# Place this to the pod spec of a job to allow the job to -# stop the sidecar pod via pkill -{{- define "utils.proxysql.job_pod_settings" }} - {{- if .Values.proxysql }} - {{- if .Values.proxysql.mode }} -{{- include "utils.proxysql.pod_settings" . }} -shareProcessNamespace: true -securityContext: - runAsUser: 65534 - {{- end }} - {{- end }} -{{- end }} - -# Place this in job scripts when your script stops normally, but not abnormally -# as this causes the side-car pod finish normally, but we need it for the re-runs -{{- define "utils.proxysql.proxysql_signal_stop_script" }} - {{- if .Values.proxysql }} - {{- if .Values.proxysql.mode }} -pkill proxysql || true - {{- end }} - {{- end }} -{{- end }} diff --git a/openstack/utils/templates/_hosts.tpl b/openstack/utils/templates/_hosts.tpl index cd1ec5f562..49deffa8b6 100644 --- a/openstack/utils/templates/_hosts.tpl +++ b/openstack/utils/templates/_hosts.tpl @@ -54,9 +54,14 @@ mysql+pymysql://{{ include "db_credentials" . }}@ {{- with $envAll := index . 0 }} {{- if not .Values.proxysql }} {{- include "db_host_mysql" $allArgs }} + {{- else if not .Values.proxysql.mode }} + {{- include "db_host_mysql" $allArgs }} {{- else if ne $envAll.Values.proxysql.mode "unix_socket" }} - {{- $_ := mustHas $envAll.Values.proxysql.mode (list "unix_socket" "host_alias") }} + {{- if mustHas $envAll.Values.proxysql.mode (list "unix_socket" "host_alias") }} {{- include "db_host_mysql" $allArgs }} + {{- else }} + {{ fail (printf "Unknown value for .Values.proxysql.mode: got \"%v\"" $envAll.Values.proxysql.mode) }} + {{- end }} {{- end -}} /{{ $schemaName }}? {{- if .Values.proxysql }} diff --git a/openstack/utils/templates/_proxy_sql_configmap.yaml.tpl b/openstack/utils/templates/_proxy_sql_configmap.yaml.tpl deleted file mode 100644 index 42e2ab8317..0000000000 --- a/openstack/utils/templates/_proxy_sql_configmap.yaml.tpl +++ /dev/null @@ -1,98 +0,0 @@ -{{- define "proxy_sql_configmap" }} - {{ $dbs := index . 1 }} - {{ $dbKeys := keys $dbs | sortAlpha }} - {{ $envAll := index . 0 }} - {{ with $envAll }} - {{- if .Values.proxysql -}} - {{- if .Values.proxysql.mode -}} -apiVersion: v1 -kind: ConfigMap -metadata: - name: {{ .Release.Name }}-proxysql-etc - labels: - system: openstack - type: configuration - component: database -data: - proxysql.cnf: | - admin_variables = - { - restapi_enabled = true - restapi_port = {{ default 6070 .Values.proxysql.restapi_port }} - prometheus_memory_metrics_interval = {{ default 61 .Values.proxysql.prometheus_memory_metrics_interval }} - } - - mysql_variables = - { - interfaces = "127.0.0.1:3306;/run/proxysql/mysql.sock" - monitor_username = "root" - monitor_password = "{{ .Values.mariadb.root_password | required ".Values.mariadb.root_password is required!" }}" - monitor_enabled = {{ if $dbs -}} false {{- else -}} true {{- end }} - connect_retries_on_failure = {{ default 1000 .Values.proxysql.connect_retries_on_failure }} - connect_retries_delay = {{ default 100 .Values.proxysql.connect_retries_delay }} {{- /* The default is 1ms, and that means we will run through the retries on failure in no time */}} - connect_timeout_server_max = {{ default 100000 .Values.proxysql.connect_timeout_server_max }} - } - - mysql_servers = - ( - { - {{- $max_pool_size := coalesce .Values.max_pool_size .Values.global.max_pool_size 50 }} - {{- $max_overflow := coalesce .Values.max_overflow .Values.global.max_overflow 5 }} - {{- $max_connections := .Values.proxysql.max_connnections | default (add $max_pool_size $max_overflow) }} - {{- $address := include "db_host_mysql" . }} - {{- $host_groups := dict $address 0 }} - address = "{{ $address }}.{{ include "svc_fqdn" $envAll }}" - hostgroup = 0 - max_connections = {{ $max_connections }} - }, - {{- range $key:= $dbKeys }} - {{- $entry := get $dbs $key }} - {{- $address := get $entry "host" }} - {{- if hasKey $host_groups $address }} - {{- /* Nothing to be done */}} - {{- else }} - {{- $index := len $host_groups }} - {{- $_ := set $host_groups $address $index }} - { - address = "{{ $address }}.{{ include "svc_fqdn" $envAll }}" - hostgroup = {{ $index }} - max_connections = {{ $max_connections }} - }, - {{- end }} - {{- end }} - ) - - mysql_users = - ( - { - username = "{{ coalesce .Values.dbUser .Values.global.dbUser "root" }}" - password = "{{ coalesce .Values.dbPassword .Values.global.dbPassword .Values.mariadb.root_password | required ".Values.mariadb.root_password is required!"}}" - default_hostgroup = 0 - default_schema = "{{ coalesce .Values.dbName .Values.db_name }}" - }, - {{- range $key:= $dbKeys }} - { - {{- $entry := get $dbs $key }} - {{- $address := get $entry "host" }} - username = "{{ get $entry "user" | required "user needs to be set for all extra dbs" }}" - password = "{{ get $entry "password" | required "password needs to be set for all extra dbs" }}" - default_hostgroup = {{ get $host_groups $address }} - default_schema = "{{ get $entry "schema" }}" - }, - {{- end }} - ) - - mysql_query_rules = - ( - { - rule_id = 0, - active = 1, - apply = 1, - cache_ttl = 3600000, - match_pattern = "^SELECT 1$", - }, - ) - {{- end }} - {{- end }} - {{- end }} -{{- end }} diff --git a/openstack/utils/templates/_proxysql.tpl b/openstack/utils/templates/_proxysql.tpl index e053463a7d..35b831b83c 100644 --- a/openstack/utils/templates/_proxysql.tpl +++ b/openstack/utils/templates/_proxysql.tpl @@ -12,7 +12,7 @@ {{- if .Values.proxysql }} {{- if .Values.proxysql.mode }} - name: proxysql - image: {{ required ".Values.global.dockerHubMirror is missing" .Values.global.dockerHubMirror}}/{{ default "proxysql/proxysql" .Values.proxysql.image }}:{{ .Values.proxysql.imageTag | default "2.4.1-debian" }} + image: {{ required ".Values.global.dockerHubMirror is missing" .Values.global.dockerHubMirror}}/{{ default "proxysql/proxysql" .Values.proxysql.image }}:{{ .Values.proxysql.imageTag | default "2.4.2-debian" }} imagePullPolicy: IfNotPresent command: ["proxysql"] args: ["--config", "/etc/proxysql/proxysql.cnf", "--exit-on-error", "--foreground", "--idle-threads", "--admin-socket", "/run/proxysql/admin.sock", "--no-version-check", "-D", "/run/proxysql"] @@ -50,13 +50,22 @@ {{- if .Values.proxysql }} {{- if .Values.proxysql.mode }} {{- $envAll := . }} + {{- $dbs := dict }} + {{- range $d := $envAll.Chart.Dependencies }} + {{- if hasPrefix "mariadb" $d.Name }} + {{- $_ := set $dbs $d.Name (get $envAll.Values $d.Name) }} + {{- end }} + {{- end }} + {{- range $d := $envAll.Values.proxysql.force_enable }} + {{- $_ := set $dbs $d (get $envAll.Values $d) }} + {{- end }} + {{- $dbKeys := keys $dbs | sortAlpha }} hostAliases: - ip: "127.0.0.1" hostnames: - {{- range $d := .Chart.Dependencies }} - {{- if and $d.Enabled (hasPrefix "mariadb" $d.Name)}} - - {{ print (get $envAll.Values $d.Name).name "-mariadb" | quote }} - {{- end }} + {{- range $index, $dbKey := $dbKeys }} + {{- $db := get $dbs $dbKey }} + - {{ print $db.name "-mariadb" | quote }} {{- end }} {{- end }} {{- end }} @@ -80,7 +89,7 @@ securityContext: # as this causes the side-car pod finish normally, but we need it for the re-runs {{- define "utils.proxysql.proxysql_signal_stop_script" }} {{- if .Values.proxysql }} - {{- if .Values.proxysql.mode }} + {{- if .Values.proxysql.mode -}} pkill proxysql || true {{- end }} {{- end }} diff --git a/openstack/utils/templates/_proxysql_configmap.yaml.tpl b/openstack/utils/templates/_proxysql_configmap.yaml.tpl index 0b797911be..5a68c734cb 100644 --- a/openstack/utils/templates/_proxysql_configmap.yaml.tpl +++ b/openstack/utils/templates/_proxysql_configmap.yaml.tpl @@ -8,10 +8,13 @@ {{- $dbs := dict }} {{- range $d := $envAll.Chart.Dependencies }} - {{- if and $d.Enabled (hasPrefix "mariadb" $d.Name)}} + {{- if hasPrefix "mariadb" $d.Name }} {{- $_ := set $dbs $d.Name (get $envAll.Values $d.Name) }} {{- end }} {{- end }} +{{- range $d := $envAll.Values.proxysql.force_enable }} + {{- $_ := set $dbs $d (get $envAll.Values $d) }} +{{- end }} {{- $dbKeys := keys $dbs | sortAlpha }} apiVersion: v1 kind: ConfigMap