From 7eebf2182f850e1d4bfb10ea899d3567d09e7d0f Mon Sep 17 00:00:00 2001
From: Jared Hampson
Date: Thu, 4 Jan 2024 14:42:58 -0600
Subject: [PATCH 1/2] Propogate vttablet extraEnv to mysqld_exporter container
This change propogates the vttablet extraEnv to the mysqld_exporter.
This allows for the mysqld_exporter to be configured with the same
environment variables as the vttablet and mysqld containers. This
is useful for configuring an AWS IAM-based service account, which
automatically injects additional AWS_* environment variables into
the pod. Without this, the operator continuously restarts the
pod due to trying to remove the AWS_* environment variables from
the mysqld_exporter container.
Signed-off-by: Jared Hampson
---
pkg/operator/vttablet/env_vars.go | 10 ++++++++++
pkg/operator/vttablet/lazy_values.go | 2 ++
pkg/operator/vttablet/pod.go | 10 +++-------
3 files changed, 15 insertions(+), 7 deletions(-)
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,
From f786c62e44aae3dd8490e99be4d0d32854e8703d Mon Sep 17 00:00:00 2001
From: Jared Hampson
Date: Thu, 4 Jan 2024 15:45:51 -0600
Subject: [PATCH 2/2] Update docs/api.md
Signed-off-by: Jared Hampson
---
docs/api.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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.
|