From 2e273fa98af5c336043c0b72ac8f174514cd5cd5 Mon Sep 17 00:00:00 2001 From: Philip Gough Date: Tue, 11 Jul 2023 15:59:51 +0100 Subject: [PATCH] Add Pod anti-affinity to Thanos Rule Signed-off-by: Philip Gough --- CHANGELOG.md | 1 + .../manifests/thanos-rule-statefulSet.yaml | 18 ++++++++++++++++ .../kube-thanos/kube-thanos-rule.libsonnet | 21 +++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81b5c94..165d9b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ We use *breaking* word for marking changes that are not backward compatible (rel - [#301](https://github.com/thanos-io/kube-thanos/pull/301) Receive: allow configuration of `minReadySeconds` for StatefulSet - [#305](https://github.com/thanos-io/kube-thanos/pull/305) Receive: allow configuration of limits-config-file - [#308](https://github.com/thanos-io/kube-thanos/pull/308) Recive: add store limits flags +- [#310](https://github.com/thanos-io/kube-thanos/pull/310) Ruler: Add host anti-affinity to ruler ### Fixed diff --git a/examples/all/manifests/thanos-rule-statefulSet.yaml b/examples/all/manifests/thanos-rule-statefulSet.yaml index 721ba98..bbbe815 100644 --- a/examples/all/manifests/thanos-rule-statefulSet.yaml +++ b/examples/all/manifests/thanos-rule-statefulSet.yaml @@ -24,6 +24,24 @@ spec: app.kubernetes.io/name: thanos-rule app.kubernetes.io/version: v0.30.2 spec: + affinity: + podAntiAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - podAffinityTerm: + labelSelector: + matchExpressions: + - key: app.kubernetes.io/name + operator: In + values: + - thanos-rule + - key: app.kubernetes.io/instance + operator: In + values: + - thanos-rule + namespaces: + - thanos + topologyKey: kubernetes.io/hostname + weight: 100 containers: - args: - rule diff --git a/jsonnet/kube-thanos/kube-thanos-rule.libsonnet b/jsonnet/kube-thanos/kube-thanos-rule.libsonnet index 4062c45..d78b8f0 100644 --- a/jsonnet/kube-thanos/kube-thanos-rule.libsonnet +++ b/jsonnet/kube-thanos/kube-thanos-rule.libsonnet @@ -328,6 +328,27 @@ function(params) { nodeSelector: { 'kubernetes.io/os': 'linux', }, + affinity: { podAntiAffinity: { + local labelSelector = { matchExpressions: [{ + key: 'app.kubernetes.io/name', + operator: 'In', + values: [tr.statefulSet.metadata.labels['app.kubernetes.io/name']], + }, { + key: 'app.kubernetes.io/instance', + operator: 'In', + values: [tr.statefulSet.metadata.labels['app.kubernetes.io/instance']], + }] }, + preferredDuringSchedulingIgnoredDuringExecution: [ + { + podAffinityTerm: { + namespaces: [tr.config.namespace], + topologyKey: 'kubernetes.io/hostname', + labelSelector: labelSelector, + }, + weight: 100, + }, + ], + } }, }, }, volumeClaimTemplates: if std.length(tr.config.volumeClaimTemplate) > 0 then [tr.config.volumeClaimTemplate {