From 12768483efea193ae88d32f7ca2964b241dc3344 Mon Sep 17 00:00:00 2001 From: Thibault Mange <22740367+thibaultmg@users.noreply.github.com> Date: Thu, 28 Sep 2023 16:52:53 +0200 Subject: [PATCH] add pdb Signed-off-by: Thibault Mange <22740367+thibaultmg@users.noreply.github.com> --- .../observatorium-metrics-store-template.yaml | 17 ++++++++++++++ .../observatorium-metrics-store-template.yaml | 17 ++++++++++++++ services_go/observatorium/metrics.go | 23 +++++++++++++++++-- services_go/observatorium/observatorium.go | 13 +++++++++-- 4 files changed, 66 insertions(+), 4 deletions(-) diff --git a/resources/services/app-sre-stage-01/rhobs/observatorium-metrics-store-template.yaml b/resources/services/app-sre-stage-01/rhobs/observatorium-metrics-store-template.yaml index 2b1adeca8b..6e7bd9e2a3 100755 --- a/resources/services/app-sre-stage-01/rhobs/observatorium-metrics-store-template.yaml +++ b/resources/services/app-sre-stage-01/rhobs/observatorium-metrics-store-template.yaml @@ -63,6 +63,23 @@ objects: app.kubernetes.io/version: v0.32.3 name: hashmod-config-template namespace: rhobs +- metadata: + creationTimestamp: null + labels: + app.kubernetes.io/component: object-store-gateway + app.kubernetes.io/instance: observatorium + app.kubernetes.io/name: thanos-store + app.kubernetes.io/part-of: observatorium + name: store + namespace: rhobs + spec: + maxUnavailable: 1 + selector: + matchLabels: + app.kubernetes.io/component: object-store-gateway + app.kubernetes.io/instance: observatorium + app.kubernetes.io/name: thanos-store + app.kubernetes.io/part-of: observatorium - apiVersion: v1 kind: Service metadata: diff --git a/resources/services/telemeter-prod-01/rhobs/observatorium-metrics-store-template.yaml b/resources/services/telemeter-prod-01/rhobs/observatorium-metrics-store-template.yaml index d3b4279a01..49bd3b5ab3 100755 --- a/resources/services/telemeter-prod-01/rhobs/observatorium-metrics-store-template.yaml +++ b/resources/services/telemeter-prod-01/rhobs/observatorium-metrics-store-template.yaml @@ -63,6 +63,23 @@ objects: app.kubernetes.io/version: v0.32.3 name: hashmod-config-template namespace: rhobs +- metadata: + creationTimestamp: null + labels: + app.kubernetes.io/component: object-store-gateway + app.kubernetes.io/instance: observatorium + app.kubernetes.io/name: thanos-store + app.kubernetes.io/part-of: observatorium + name: store + namespace: rhobs + spec: + maxUnavailable: 1 + selector: + matchLabels: + app.kubernetes.io/component: object-store-gateway + app.kubernetes.io/instance: observatorium + app.kubernetes.io/name: thanos-store + app.kubernetes.io/part-of: observatorium - apiVersion: v1 kind: Service metadata: diff --git a/services_go/observatorium/metrics.go b/services_go/observatorium/metrics.go index 38293e2bc0..71aa9aa021 100644 --- a/services_go/observatorium/metrics.go +++ b/services_go/observatorium/metrics.go @@ -15,9 +15,11 @@ import ( monv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" + policyv1 "k8s.io/api/policy/v1" rbacv1 "k8s.io/api/rbac/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/intstr" ) const ( @@ -187,7 +189,6 @@ func makeStore(namespace string, preManifestHook func(*store.StoreStatefulSet)) labels := maps.Clone(statefulset.ObjectMeta.Labels) delete(labels, k8sutil.VersionLabel) manifests["list-pods-rbac"] = &rbacv1.Role{ - // ObjectMeta: ObjectMeta: metav1.ObjectMeta{ Name: "list-pods", Namespace: namespace, @@ -202,7 +203,6 @@ func makeStore(namespace string, preManifestHook func(*store.StoreStatefulSet)) }, } manifests["list-pods-rbac-binding"] = &rbacv1.RoleBinding{ - // ObjectMeta: ObjectMeta: metav1.ObjectMeta{ Name: "list-pods", Namespace: namespace, @@ -223,6 +223,25 @@ func makeStore(namespace string, preManifestHook func(*store.StoreStatefulSet)) }, } + // Add pod disruption budget + manifests["store-pdb"] = &policyv1.PodDisruptionBudget{ + ObjectMeta: metav1.ObjectMeta{ + Name: "store", + Namespace: namespace, + Labels: labels, + }, + Spec: policyv1.PodDisruptionBudgetSpec{ + MaxUnavailable: &intstr.IntOrString{ + + Type: intstr.Int, + IntVal: 1, + }, + Selector: &metav1.LabelSelector{ + MatchLabels: labels, + }, + }, + } + return manifests } diff --git a/services_go/observatorium/observatorium.go b/services_go/observatorium/observatorium.go index e426da23d6..25c0394eff 100644 --- a/services_go/observatorium/observatorium.go +++ b/services_go/observatorium/observatorium.go @@ -99,7 +99,16 @@ func (c *customYAML) EncodeComment(lines string) []byte { func (c *customYAML) clean(input []byte) []byte { // Remove status section from manifests - re := regexp.MustCompile(`\s*status:\n\s*availableReplicas: 0\n\s*replicas: 0`) - ret := re.ReplaceAllString(string(input), "") + re := []*regexp.Regexp{ + regexp.MustCompile(`\s*status:\n\s*availableReplicas: 0\n\s*replicas: 0`), + regexp.MustCompile(`\s*status:\n\s*currentHealthy: 0\n\s*desiredHealthy: 0\n\s*disruptionsAllowed: 0\n\s*expectedPods: 0`), + } + + ret := input + + for _, r := range re { + ret = r.ReplaceAll(ret, []byte{}) + } + return []byte(ret) }