Skip to content

Commit 70986f2

Browse files
committed
Switch to envvars from init container
1 parent 4e4bcb7 commit 70986f2

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

prometheus-ksonnet/lib/prometheus-ha-mixin.libsonnet

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
local container = $.core.v1.container;
2+
local statefulset = $.apps.v1.statefulSet;
3+
14
{
25
prometheus_config_0: $.prometheus_config,
36
prometheus_config_1: $.prometheus_config,
@@ -30,13 +33,14 @@
3033

3134
prometheus_config_mount:: {},
3235

33-
prometheus_init_container::
34-
container.new('prometheus-init', 'busybox') +
35-
container.withCommand(["ln", "-s", "/etc/$HOSTNAME", "/etc/prometheus"]),
36+
prometheus_config_file:: '/etc/$(POD_NAME)/prometheus.yml',
37+
38+
prometheus_container+:: container.withEnv([
39+
container.envType.fromFieldPath('POD_NAME', 'metadata.name'),
40+
]),
3641

3742
prometheus_statefulset:
3843
$.util.configVolumeMount('%s-config-0' % self.name, '/etc/prometheus-0') +
3944
$.util.configVolumeMount('%s-config-1' % self.name, '/etc/prometheus-1') +
40-
statefulset.mixin.spec.template.spec.withInitContainers(self.prometheus_init_container) +
4145
statefulset.mixin.spec.withReplicas(2),
4246
}

prometheus-ksonnet/lib/prometheus.libsonnet

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@
3030

3131
local container = $.core.v1.container,
3232

33+
prometheus_config_file:: '/etc/prometheus/prometheus.yml',
34+
3335
prometheus_container::
3436
local _config = self._config;
3537

3638
container.new('prometheus', $._images.prometheus) +
3739
container.withPorts($.core.v1.containerPort.new('http-metrics', _config.prometheus_port)) +
3840
container.withArgs([
39-
'--config.file=/etc/prometheus/prometheus.yml',
41+
'--config.file=' + self.prometheus_config_file,
4042
'--web.listen-address=:%s' % _config.prometheus_port,
4143
'--web.external-url=%(prometheus_external_hostname)s%(prometheus_path)s' % _config,
4244
'--web.enable-admin-api',

0 commit comments

Comments
 (0)