Skip to content

Commit 4b755cb

Browse files
committed
Fix extraFlags implementation
1 parent d443db6 commit 4b755cb

File tree

8 files changed

+100
-79
lines changed

8 files changed

+100
-79
lines changed

README.md.gotmpl

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -171,24 +171,50 @@ initJob:
171171

172172
### MySQL Command-Line Arguments
173173

174-
You can pass additional command-line arguments directly to the `mysqld` process:
174+
You can pass additional command-line arguments to MySQL in two ways:
175+
176+
#### Method 1: Using `primary.extraFlags` (Appends to Configuration)
177+
178+
The `extraFlags` property automatically converts command-line flags to MySQL configuration format and **appends** them to the existing configuration (default or custom):
179+
180+
```yaml
181+
primary:
182+
extraFlags: "--max-connections=500 --max-allowed-packet=64M --log-bin-trust-function-creators=1 --thread-stack=256K"
183+
```
184+
185+
**Benefits:**
186+
- Flags are automatically converted to `my.cnf` format
187+
- **Appends** to the default configuration (or your custom `primary.configuration`)
188+
189+
#### Method 2: Direct Configuration (Complete Override)
190+
191+
You can provide a complete MySQL configuration that **replaces** the default:
175192

176193
```yaml
177194
primary:
178-
extraFlags:
179-
- "--max-connections=500"
180-
- "--max-allowed-packet=64M"
181-
- "--log-bin-trust-function-creators=1"
182-
- "--thread-stack=256K"
195+
configuration: |-
196+
[mysqld]
197+
authentication_policy='* ,,'
198+
skip-name-resolve
199+
port=3306
200+
datadir=/var/lib/mysql
201+
max-connections=500
202+
max-allowed-packet=64M
203+
log-bin-trust-function-creators=1
204+
thread-stack=256K
183205
```
184206

185207
**Use cases:**
186-
- Override configuration values at runtime
187-
- Set values that can't be configured in `my.cnf`
188-
- Apply temporary settings without changing the config file
189-
- Test different MySQL settings
208+
- Complete control over the MySQL configuration
209+
- When you need to override the entire default configuration
210+
- Custom configurations that differ significantly from defaults
211+
212+
**Note:**
213+
- `primary.extraFlags` **appends** flags to the existing configuration (default or custom)
214+
- `primary.configuration` **completely replaces** the default configuration
215+
- You can use both together: `primary.configuration` provides the base config, and `primary.extraFlags` adds additional flags on top
190216

191-
**Note:** Command-line arguments take precedence over `my.cnf` configuration. See `examples/extra-args-values.yaml` for a complete example.
217+
See `examples/extra-args-values.yaml` for a complete example.
192218

193219
### Automated Backups
194220

examples/extra-args-values.yaml

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1-
# Example: MySQL with additional command-line arguments
1+
# Example: MySQL with extra flags, custom configuration, and environment variables
22
# Usage: helm install mysql ./ -f examples/extra-args-values.yaml
33

44
auth:
55
rootPassword: "changeme"
66

77
primary:
88
# Additional command-line arguments passed to mysqld
9-
# These override or supplement settings in my.cnf
10-
extraFlags:
11-
- "--max-connections=500"
12-
- "--max-allowed-packet=64M"
13-
- "--log-bin-trust-function-creators=1"
14-
- "--thread-stack=256K"
15-
- "--group-concat-max-len=1000000"
9+
# These are automatically converted to my.cnf format and appended to the configuration
10+
extraFlags: "--max-connections=500 --max-allowed-packet=64M --log-bin-trust-function-creators=1 --thread-stack=256K --group-concat-max-len=1000000"
1611

12+
# Custom MySQL configuration (completely replaces default configuration)
13+
# extraFlags will be appended to this configuration
1714
configuration: |-
1815
[mysqld]
1916
authentication_policy='* ,,'
@@ -24,7 +21,39 @@ primary:
2421
character-set-server=utf8mb4
2522
collation-server=utf8mb4_unicode_ci
2623
24+
# Extra environment variables to add to the MySQL container
25+
# Supports both simple values and valueFrom (for secrets/configmaps)
26+
extraEnvVars:
27+
# Simple value example
28+
- name: MY_CUSTOM_VAR
29+
value: "my-custom-value"
30+
31+
# Another simple value
32+
- name: DEBUG_MODE
33+
value: "true"
34+
35+
# Value from Secret
36+
- name: MY_SECRET_VAR
37+
valueFrom:
38+
secretKeyRef:
39+
name: my-secret
40+
key: my-secret-key
41+
42+
# Value from ConfigMap
43+
- name: MY_CONFIG_VAR
44+
valueFrom:
45+
configMapKeyRef:
46+
name: my-configmap
47+
key: my-config-key
48+
49+
# Value from Secret with optional key
50+
- name: DATABASE_URL
51+
valueFrom:
52+
secretKeyRef:
53+
name: app-secrets
54+
key: database-url
55+
optional: false
56+
2757
persistence:
2858
enabled: true
2959
size: 20Gi
30-

examples/extra-env-vars-values.yaml

Lines changed: 0 additions & 53 deletions
This file was deleted.

templates/_helpers.tpl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,17 @@ Return the configmap name for MySQL configuration
122122
{{- end }}
123123
{{- end }}
124124

125+
{{/*
126+
Convert extraFlags string to my.cnf format
127+
Input: "--max-connections=500 --log-bin-trust-function-creators=1"
128+
Output: "max-connections=500\nlog-bin-trust-function-creators=1"
129+
*/}}
130+
{{- define "mysql.extraFlagsToConfig" -}}
131+
{{- if .Values.primary.extraFlags }}
132+
{{- $flags := trim .Values.primary.extraFlags }}
133+
{{- $flags = regexReplaceAll " +--" $flags "\n" }}
134+
{{- $flags = regexReplaceAll "^--" $flags "" }}
135+
{{- $flags }}
136+
{{- end }}
137+
{{- end }}
138+

templates/configmap.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ data:
1515
datadir={{ .Values.primary.dataDir }}
1616
{{- end }}
1717
{{ $config | nindent 4 }}
18+
{{- if .Values.primary.extraFlags }}
19+
# Additional flags from primary.extraFlags
20+
{{- include "mysql.extraFlagsToConfig" . | nindent 4 }}
21+
{{- end }}
1822
{{- if .Values.tls.enabled }}
1923
# TLS/SSL Configuration
2024
ssl-ca=/etc/mysql/ssl/ca.crt

templates/init-job.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ spec:
5757
5858
echo "Initializing databases and users..."
5959
60+
# Enable log_bin_trust_function_creators to allow triggers/functions without SUPER privilege
61+
echo "Setting log_bin_trust_function_creators=1..."
62+
mysql -h {{ include "mysql.fullname" . }} -u root -p${MYSQL_ROOT_PASSWORD} -e "SET GLOBAL log_bin_trust_function_creators=1;" || echo "Warning: Could not set log_bin_trust_function_creators (may already be set or binary logging disabled)"
63+
6064
{{- range $index, $db := .Values.initJob.databases }}
6165
echo "Creating database '{{ $db.name }}' and user '{{ $db.username }}'..."
6266
mysql -h {{ include "mysql.fullname" $ }} -u root -p${MYSQL_ROOT_PASSWORD} -e "CREATE DATABASE IF NOT EXISTS \`{{ $db.name }}\` DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci;"

templates/statefulset.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ spec:
7575
name: {{ include "mysql.secretName" . }}
7676
key: mysql-password
7777
{{- end }}
78-
{{- if .Values.primary.extraFlags }}
79-
- name: MYSQL_EXTRA_FLAGS
80-
value: "{{ .Values.primary.extraFlags }}"
81-
{{- end }}
8278
{{- if .Values.primary.extraEnvVars }}
8379
{{- range .Values.primary.extraEnvVars }}
8480
- name: {{ .name }}

values.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ primary:
8181
existingConfigmap: ""
8282

8383
## @param primary.extraFlags Additional command-line arguments to pass to mysqld
84-
## Example: ["--max-connections=500", "--log-bin-trust-function-creators=1"]
85-
extraFlags: []
84+
## Space-separated string of flags
85+
## Example: "--max-connections=500 --log-bin-trust-function-creators=1"
86+
extraFlags: ""
8687

8788
## @param primary.extraEnvVars Array with extra environment variables to add to MySQL container
8889
## Example:

0 commit comments

Comments
 (0)