diff --git a/docs/api.md b/docs/api.md index 5f33ffe4..8ce4875e 100644 --- a/docs/api.md +++ b/docs/api.md @@ -6675,7 +6675,7 @@ created for this component.

ExtraEnv can optionally be used to override default environment variables set by the operator, or pass additional environment variables. -These values are applied to both the vttablet and mysqld containers.

+These values are applied to the vttablet, mysqld, and mysqld-exporter containers.

diff --git a/pkg/operator/vttablet/env_vars.go b/pkg/operator/vttablet/env_vars.go index 2dd089cd..3e3189c5 100644 --- a/pkg/operator/vttablet/env_vars.go +++ b/pkg/operator/vttablet/env_vars.go @@ -17,6 +17,7 @@ limitations under the License. package vttablet import ( + "fmt" "strings" "planetscale.dev/vitess-operator/pkg/operator/lazy" @@ -41,4 +42,13 @@ func init() { }, } }) + + mysqldExporterEnvVars.Add(func(s lazy.Spec) []corev1.EnvVar { + return []corev1.EnvVar{ + { + Name: "DATA_SOURCE_NAME", + Value: fmt.Sprintf("%s@unix(%s)/", mysqldExporterUser, mysqlSocketPath), + }, + } + }) } diff --git a/pkg/operator/vttablet/lazy_values.go b/pkg/operator/vttablet/lazy_values.go index 83916a5f..b0aa84e8 100644 --- a/pkg/operator/vttablet/lazy_values.go +++ b/pkg/operator/vttablet/lazy_values.go @@ -30,6 +30,8 @@ var ( tabletEnvVars lazy.EnvVars // vttabletEnvVars are extra env vars for only the vttablet container. vttabletEnvVars lazy.EnvVars + // mysqldExporterEnvVars are extra env vars for only the mysqld container. + mysqldExporterEnvVars lazy.EnvVars // extraMyCnf is a list of file paths to put into the EXTRA_MY_CNF env var. extraMyCnf lazy.Strings diff --git a/pkg/operator/vttablet/pod.go b/pkg/operator/vttablet/pod.go index a078b3af..392ea282 100644 --- a/pkg/operator/vttablet/pod.go +++ b/pkg/operator/vttablet/pod.go @@ -17,7 +17,6 @@ limitations under the License. package vttablet import ( - "fmt" "strconv" "strings" @@ -92,9 +91,11 @@ func UpdatePod(obj *corev1.Pod, spec *Spec) { env := tabletEnvVars.Get(spec) vttabletEnv := append(vttabletEnvVars.Get(spec), env...) update.GOMAXPROCS(&vttabletEnv, spec.Vttablet.Resources) + mysqldExporterEnv := mysqldExporterEnvVars.Get(spec) // Then apply user-provided overrides last so they take precedence. update.Env(&env, spec.ExtraEnv) update.Env(&vttabletEnv, spec.ExtraEnv) + update.Env(&mysqldExporterEnv, spec.ExtraEnv) // Compute all operator-generated volume mounts first. mysqldMounts := append(mysqldVolumeMounts.Get(spec), volumeMounts...) @@ -208,12 +209,7 @@ func UpdatePod(obj *corev1.Pod, spec *Spec) { // memory usage. "--collect.info_schema.tables.databases=sys,_vt", }, - Env: []corev1.EnvVar{ - { - Name: "DATA_SOURCE_NAME", - Value: fmt.Sprintf("%s@unix(%s)/", mysqldExporterUser, mysqlSocketPath), - }, - }, + Env: mysqldExporterEnv, Ports: []corev1.ContainerPort{ { Name: mysqldExporterPortName,