Skip to content

support alertmanager configuration and extra volumes for thanos ruler. #225

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

Merged
merged 2 commits into from
Jan 5, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ We use *breaking* word for marking changes that are not backward compatible (rel
- [#213](https://github.com/thanos-io/kube-thanos/pull/213) Allow configuring `--min-time` and `--max-time` of store.
- [#218](https://github.com/thanos-io/kube-thanos/pull/218) Enable `--query.auto-downsampling` for query by default.
- [#221](https://github.com/thanos-io/kube-thanos/pull/221) Allow configuring `--tsdb.retention` and `--tsdb.block-duration` for rule.
- [#225](https://github.com/thanos-io/kube-thanos/pull/225) Add support for alertmanager configuration and extra volumes for rule.

[Full Changelog](https://github.com/thanos-io/kube-thanos/compare/v0.18.0...v0.19.0)

Expand Down
4 changes: 4 additions & 0 deletions all.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ local ru = t.rule(commonConfig {
replicas: 1,
rulesConfig: [{ name: 'test', key: 'test' }],
alertmanagersURLs: ['alertmanager:9093'],
alertmanagerConfigFile: {
name: 'thanos-ruler-config',
key: 'config.yaml',
},
reloaderImage: 'jimmidyson/configmap-reload:v0.5.0',
serviceMonitor: true,
});
Expand Down
10 changes: 10 additions & 0 deletions examples/all/manifests/thanos-rule-statefulSet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ spec:
- --tsdb.block-duration=2h
- --query=dnssrv+_http._tcp.thanos-query.thanos.svc.cluster.local
- --alertmanagers.url=alertmanager:9093
- --alertmanagers.config-file=/etc/thanos/config/thanos-ruler-config/config.yaml
- --rule-file=/etc/thanos/rules/test/test
- |-
--tracing.config="config":
Expand Down Expand Up @@ -98,14 +99,20 @@ spec:
readOnly: false
- mountPath: /etc/thanos/rules/test
name: test
- mountPath: /etc/thanos/config/thanos-ruler-config
name: thanos-ruler-config
readOnly: true
- args:
- -webhook-url=http://localhost:10902/-/reload
- -volume-dir=/etc/thanos/rules/test
- -volume-dir=/etc/thanos/config/thanos-ruler-config
image: jimmidyson/configmap-reload:v0.5.0
name: configmap-reloader
volumeMounts:
- mountPath: /etc/thanos/rules/test
name: test
- mountPath: /etc/thanos/config/thanos-ruler-config
name: thanos-ruler-config
nodeSelector:
kubernetes.io/os: linux
securityContext:
Expand All @@ -116,6 +123,9 @@ spec:
- configMap:
name: test
name: test
- configMap:
name: thanos-ruler-config
name: thanos-ruler-config
volumeClaimTemplates:
- metadata:
labels:
Expand Down
78 changes: 71 additions & 7 deletions jsonnet/kube-thanos/kube-thanos-rule.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ local defaults = {
ruleFiles: [],
rulesConfig: [],
alertmanagersURLs: [],
alertmanagerConfigFile: {},
extraVolumeMounts: [],
queriers: [],
logLevel: 'info',
logFormat: 'logfmt',
Expand Down Expand Up @@ -57,6 +59,8 @@ function(params) {
assert std.isArray(tr.config.ruleFiles),
assert std.isArray(tr.config.rulesConfig),
assert std.isArray(tr.config.alertmanagersURLs),
assert std.isObject(tr.config.alertmanagerConfigFile),
assert std.isArray(tr.config.extraVolumeMounts),
assert std.isObject(tr.config.resources),
assert std.isBoolean(tr.config.serviceMonitor),
assert std.isObject(tr.config.volumeClaimTemplate),
Expand Down Expand Up @@ -120,6 +124,11 @@ function(params) {
(['--rule-file=%s' % path for path in tr.config.ruleFiles]) +
(['--alertmanagers.url=%s' % url for url in tr.config.alertmanagersURLs]) +
(
if tr.config.alertmanagerConfigFile != {} then [
'--alertmanagers.config-file=/etc/thanos/config/' + tr.config.alertmanagerConfigFile.name + '/' + tr.config.alertmanagerConfigFile.key,
]
else []
) + (
if std.length(tr.config.rulesConfig) > 0 then [
'--rule-file=/etc/thanos/rules/' + ruleConfig.name + '/' + ruleConfig.key
for ruleConfig in tr.config.rulesConfig
Expand Down Expand Up @@ -163,6 +172,15 @@ function(params) {
{ name: ruleConfig.name, mountPath: '/etc/thanos/rules/' + ruleConfig.name }
for ruleConfig in tr.config.rulesConfig
] else []
) + (
if tr.config.alertmanagerConfigFile != {} then [
{ name: tr.config.alertmanagerConfigFile.name, mountPath: '/etc/thanos/config/' + tr.config.alertmanagerConfigFile.name, readOnly: true },
] else []
) + (
if std.length(tr.config.extraVolumeMounts) > 0 then [
{ name: volumeMount.name, mountPath: volumeMount.mountPath }
for volumeMount in tr.config.extraVolumeMounts
] else []
),
livenessProbe: { failureThreshold: 24, periodSeconds: 5, httpGet: {
scheme: 'HTTP',
Expand All @@ -186,11 +204,34 @@ function(params) {
[
'-webhook-url=http://localhost:' + tr.service.spec.ports[1].port + '/-/reload',
] +
(['-volume-dir=/etc/thanos/rules/' + ruleConfig.name for ruleConfig in tr.config.rulesConfig]),
(
if std.length(tr.config.rulesConfig) > 0 then [
'-volume-dir=/etc/thanos/rules/' + ruleConfig.name
for ruleConfig in tr.config.rulesConfig
] else []
) + (
if tr.config.alertmanagerConfigFile != {} then [
'-volume-dir=/etc/thanos/config/' + tr.config.alertmanagerConfigFile.name,
] else []
) + (
if std.length(tr.config.extraVolumeMounts) > 0 then [
'-volume-dir=' + volumeMount.mountPath
for volumeMount in tr.config.extraVolumeMounts
] else []
),
volumeMounts: [
{ name: ruleConfig.name, mountPath: '/etc/thanos/rules/' + ruleConfig.name }
for ruleConfig in tr.config.rulesConfig
],
] + (
if tr.config.alertmanagerConfigFile != {} then [
{ name: tr.config.alertmanagerConfigFile.name, mountPath: '/etc/thanos/config/' + tr.config.alertmanagerConfigFile.name },
] else []
) + (
if std.length(tr.config.extraVolumeMounts) > 0 then [
{ name: volumeMount.name, mountPath: volumeMount.mountPath }
for volumeMount in tr.config.extraVolumeMounts
] else []
),
};

{
Expand All @@ -213,11 +254,34 @@ function(params) {
serviceAccountName: tr.serviceAccount.metadata.name,
securityContext: tr.config.securityContext,
containers: [c] +
(if std.length(tr.config.rulesConfig) > 0 then [reloadContainer] else []),
volumes: [
{ name: ruleConfig.name, configMap: { name: ruleConfig.name } }
for ruleConfig in tr.config.rulesConfig
],
(if std.length(tr.config.rulesConfig) > 0 || std.length(tr.config.extraVolumeMounts) > 0 || tr.config.alertmanagerConfigFile != {} then [
reloadContainer,
] else []),
volumes: [] +
(
if std.length(tr.config.rulesConfig) > 0 then [
{ name: ruleConfig.name, configMap: { name: ruleConfig.name } }
for ruleConfig in tr.config.rulesConfig
] else []
) + (
if tr.config.alertmanagerConfigFile != {} then [{
name: tr.config.alertmanagerConfigFile.name,
configMap: { name: tr.config.alertmanagerConfigFile.name },
}] else []
) + (
if std.length(tr.config.extraVolumeMounts) > 0 then [
{ name: volumeMount.name } +
(
if volumeMount.type == 'configMap' then {
configMap: { name: volumeMount.name },
}
else {
secret: { name: volumeMount.name },
}
)
for volumeMount in tr.config.extraVolumeMounts
] else []
),
nodeSelector: {
'kubernetes.io/os': 'linux',
},
Expand Down