Skip to content

Commit

Permalink
mysql exporter: force password env to be defined before `DATA_SOURCE_…
Browse files Browse the repository at this point in the history
…NAME` (grafana#440)
  • Loading branch information
dafydd-t authored Feb 1, 2021
1 parent 739cda1 commit 98dc5f3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
21 changes: 16 additions & 5 deletions mysql-exporter/mysql-exporter.libsonnet
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
local k = import 'ksonnet-util/kausal.libsonnet';
local container = k.core.v1.container;
local containerPort = k.core.v1.containerPort;
local envVar = k.core.v1.envVar;
local deployment = k.apps.v1.deployment;

local secrets = import 'secrets.libsonnet';


secrets {
{
image:: 'prom/mysqld-exporter:v0.12.1',
mysql_fqdn:: '%s.%s.svc.cluster.local' % [
$._config.deployment_name,
Expand All @@ -26,22 +24,35 @@ secrets {
MYSQL_HOST: $.mysql_fqdn,
},

// optionally define additional variables before DATA_SOURCE_NAME
mysql_additional_env_list:: [],

mysqld_exporter_container::
container.new('mysqld-exporter', $.image) +
container.withPorts(k.core.v1.containerPort.new('http-metrics', 9104)) +
container.withArgsMixin([
'--collect.info_schema.innodb_metrics',
]) +
container.withEnvMap($.mysqld_exporter_env) +
container.withEnvMixin($.mysql_additional_env_list) +
// Force DATA_SOURCE_NAME to be declared after the variables it references
container.withEnvMap({
DATA_SOURCE_NAME: '$(MYSQL_USER):$(MYSQL_PASSWORD)@tcp($(MYSQL_HOST):3306)/',
}),


mysql_exporter_deployment:
deployment.new('%s-mysql-exporter' % $._config.deployment_name, 1, [$.mysqld_exporter_container]),

mysql_exporter_deployment_service:
k.util.serviceFor($.mysql_exporter_deployment),

withSecretPassword(name, key='password'):: {
mysqld_exporter_env+:: {
MYSQL_PASSWORD:: '',
},

mysql_additional_env_list:: [
envVar.fromSecretRef('MYSQL_PASSWORD', name, key),
],
},
}
16 changes: 0 additions & 16 deletions mysql-exporter/secrets.libsonnet

This file was deleted.

0 comments on commit 98dc5f3

Please sign in to comment.