-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdb.go
40 lines (34 loc) · 1.06 KB
/
pdb.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
package gateway
import (
securityv1 "github.com/caapim/layer7-operator/api/v1"
"github.com/caapim/layer7-operator/pkg/util"
policyv1 "k8s.io/api/policy/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
// NewPDB - Pod Disruption Budget
func NewPDB(gw *securityv1.Gateway) *policyv1.PodDisruptionBudget {
labels := util.DefaultLabels(gw.Name, gw.Spec.App.Labels)
pdb := &policyv1.PodDisruptionBudget{
ObjectMeta: metav1.ObjectMeta{
Name: gw.Name,
Namespace: gw.Namespace,
},
TypeMeta: metav1.TypeMeta{
APIVersion: "policy/v1",
Kind: "PodDisruptionBudget",
},
Spec: policyv1.PodDisruptionBudgetSpec{
Selector: &metav1.LabelSelector{
MatchLabels: labels,
},
},
}
if gw.Spec.App.PodDisruptionBudget.MinAvailable != (intstr.IntOrString{}) {
pdb.Spec.MinAvailable = &gw.Spec.App.PodDisruptionBudget.MinAvailable
}
if gw.Spec.App.PodDisruptionBudget.MaxUnavailable != (intstr.IntOrString{}) {
pdb.Spec.MaxUnavailable = &gw.Spec.App.PodDisruptionBudget.MaxUnavailable
}
return pdb
}