-
Notifications
You must be signed in to change notification settings - Fork 1
/
pdb_builder.go
50 lines (42 loc) · 1.39 KB
/
pdb_builder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package kibana
import (
"emperror.dev/errors"
"github.com/disaster37/k8sbuilder"
kibanacrd "github.com/webcenter-fr/elasticsearch-operator/apis/kibana/v1"
policyv1 "k8s.io/api/policy/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
// GeneratePodDisruptionBudget permit to generate pod disruption budgets for each node group
func buildPodDisruptionBudgets(kb *kibanacrd.Kibana) (pdbs []policyv1.PodDisruptionBudget, err error) {
if !kb.IsPdb() {
return nil, nil
}
pdbs = make([]policyv1.PodDisruptionBudget, 0, 1)
maxUnavailable := intstr.FromInt(1)
pdb := &policyv1.PodDisruptionBudget{
ObjectMeta: metav1.ObjectMeta{
Namespace: kb.Namespace,
Name: GetPDBName(kb),
Labels: getLabels(kb),
Annotations: getAnnotations(kb),
},
Spec: policyv1.PodDisruptionBudgetSpec{
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"cluster": kb.Name,
kibanacrd.KibanaAnnotationKey: "true",
},
},
},
}
// Merge with specified
if err = k8sbuilder.MergeK8s(&pdb.Spec, pdb.Spec, kb.Spec.Deployment.PodDisruptionBudgetSpec); err != nil {
return nil, errors.Wrap(err, "Error when merge expected PDB with global PDB")
}
if pdb.Spec.MinAvailable == nil && pdb.Spec.MaxUnavailable == nil {
pdb.Spec.MaxUnavailable = &maxUnavailable
}
pdbs = append(pdbs, *pdb)
return pdbs, nil
}