Skip to content

Commit

Permalink
add pdb
Browse files Browse the repository at this point in the history
Signed-off-by: Thibault Mange <[email protected]>
  • Loading branch information
thibaultmg committed Sep 28, 2023
1 parent ee9c319 commit 1276848
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
23 changes: 21 additions & 2 deletions services_go/observatorium/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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
}

Expand Down
13 changes: 11 additions & 2 deletions services_go/observatorium/observatorium.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 1276848

Please sign in to comment.