Skip to content

Commit

Permalink
Merge pull request #518 from jhampson-dbre/pass-extraEnv-to-all-vttab…
Browse files Browse the repository at this point in the history
…let-containers

Pass extra env to all vttablet containers
  • Loading branch information
frouioui authored Jan 10, 2024
2 parents b29cbb1 + f786c62 commit 61757d1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6675,7 +6675,7 @@ created for this component.</p>
<td>
<p>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.</p>
These values are applied to the vttablet, mysqld, and mysqld-exporter containers.</p>
</td>
</tr>
<tr>
Expand Down
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 61757d1

Please sign in to comment.