Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[utils] ProxySql side-car cleanup in prep for placement #3829

Merged
merged 1 commit into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion openstack/utils/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: v1
description: A Helm chart for Kubernetes
name: utils
version: 0.4.2
version: 0.4.3
86 changes: 0 additions & 86 deletions openstack/utils/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
7 changes: 6 additions & 1 deletion openstack/utils/templates/_hosts.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
98 changes: 0 additions & 98 deletions openstack/utils/templates/_proxy_sql_configmap.yaml.tpl

This file was deleted.

21 changes: 15 additions & 6 deletions openstack/utils/templates/_proxysql.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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 }}
Expand All @@ -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 }}
Expand Down
5 changes: 4 additions & 1 deletion openstack/utils/templates/_proxysql_configmap.yaml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down