Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass extra env to all vttablet containers #518

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading