github.com/caos/orbos@v1.5.14-0.20221103111702-e6cd0cea7ad4/pkg/kubernetes/resources/pdb/adapt.go (about) 1 package pdb 2 3 import ( 4 "github.com/caos/orbos/pkg/kubernetes" 5 "github.com/caos/orbos/pkg/kubernetes/resources" 6 "github.com/caos/orbos/pkg/labels" 7 policy "k8s.io/api/policy/v1beta1" 8 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 9 "k8s.io/apimachinery/pkg/util/intstr" 10 ) 11 12 func AdaptFuncToEnsure(namespace string, nameLabels *labels.Name, target *labels.Selector, maxUnavailable string) (resources.QueryFunc, error) { 13 maxUnavailableParsed := intstr.Parse(maxUnavailable) 14 pdb := &policy.PodDisruptionBudget{ 15 ObjectMeta: metav1.ObjectMeta{ 16 Name: nameLabels.Name(), 17 Namespace: namespace, 18 Labels: labels.MustK8sMap(nameLabels), 19 }, 20 Spec: policy.PodDisruptionBudgetSpec{ 21 Selector: &metav1.LabelSelector{ 22 MatchLabels: labels.MustK8sMap(target), 23 }, 24 MaxUnavailable: &maxUnavailableParsed, 25 }, 26 } 27 return func(_ kubernetes.ClientInt, _ map[string]interface{}) (resources.EnsureFunc, error) { 28 return func(k8sClient kubernetes.ClientInt) error { 29 return k8sClient.ApplyPodDisruptionBudget(pdb) 30 }, nil 31 }, nil 32 } 33 34 func AdaptFuncToDestroy(namespace, name string) (resources.DestroyFunc, error) { 35 return func(client kubernetes.ClientInt) error { 36 return client.DeletePodDisruptionBudget(namespace, name) 37 }, nil 38 }