Skip to content

Commit

Permalink
Propogate vttablet extraEnv to mysqld_exporter container
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Jared Hampson committed Jan 4, 2024
1 parent de214a8 commit 7eebf21
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
10 changes: 10 additions & 0 deletions pkg/operator/vttablet/env_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package vttablet

import (
"fmt"
"strings"

"planetscale.dev/vitess-operator/pkg/operator/lazy"
Expand All @@ -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),
},
}
})
}
2 changes: 2 additions & 0 deletions pkg/operator/vttablet/lazy_values.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 3 additions & 7 deletions pkg/operator/vttablet/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package vttablet

import (
"fmt"
"strconv"
"strings"

Expand Down Expand Up @@ -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...)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 7eebf21

Please sign in to comment.