diff --git a/pkg/controller/elasticsearch/pdb/reconcile.go b/pkg/controller/elasticsearch/pdb/reconcile.go index 0e3a5abce5..22eea64ed8 100644 --- a/pkg/controller/elasticsearch/pdb/reconcile.go +++ b/pkg/controller/elasticsearch/pdb/reconcile.go @@ -162,12 +162,7 @@ func expectedPDB(es esv1.Elasticsearch, statefulSets sset.StatefulSetList) (*pol // buildPDBSpec returns a PDBSpec computed from the current StatefulSets, // considering the cluster health and topology. func buildPDBSpec(es esv1.Elasticsearch, statefulSets sset.StatefulSetList) policyv1.PodDisruptionBudgetSpec { - // compute MinAvailable based on the maximum number of Pods we're supposed to have - nodeCount := statefulSets.ExpectedNodeCount() - // maybe allow some Pods to be disrupted - minAvailable := nodeCount - allowedDisruptions(es, statefulSets) - - minAvailableIntStr := intstr.IntOrString{Type: intstr.Int, IntVal: minAvailable} + maxUnavailableIntStr := intstr.IntOrString{Type: intstr.Int, IntVal: allowedDisruptions(es, statefulSets)} return policyv1.PodDisruptionBudgetSpec{ // match all pods for this cluster @@ -176,10 +171,8 @@ func buildPDBSpec(es esv1.Elasticsearch, statefulSets sset.StatefulSetList) poli label.ClusterNameLabelName: es.Name, }, }, - MinAvailable: &minAvailableIntStr, - // MaxUnavailable can only be used if the selector matches a builtin controller selector - // (eg. Deployments, StatefulSets, etc.). We cannot use it with our own cluster-name selector. - MaxUnavailable: nil, + MaxUnavailable: &maxUnavailableIntStr, + MinAvailable: nil, } } diff --git a/pkg/controller/elasticsearch/pdb/reconcile_test.go b/pkg/controller/elasticsearch/pdb/reconcile_test.go index 03958fc0d7..60841f05fb 100644 --- a/pkg/controller/elasticsearch/pdb/reconcile_test.go +++ b/pkg/controller/elasticsearch/pdb/reconcile_test.go @@ -40,13 +40,13 @@ func TestReconcile(t *testing.T) { Labels: map[string]string{label.ClusterNameLabelName: "cluster", commonv1.TypeLabelName: label.Type}, }, Spec: policyv1.PodDisruptionBudgetSpec{ - MinAvailable: intStrPtr(intstr.FromInt(3)), + MaxUnavailable: intStrPtr(intstr.FromInt(0)), Selector: &metav1.LabelSelector{ MatchLabels: map[string]string{ label.ClusterNameLabelName: "cluster", }, }, - MaxUnavailable: nil, + MinAvailable: nil, }, } } @@ -79,7 +79,7 @@ func TestReconcile(t *testing.T) { wantPDB: defaultPDB(), }, { - name: "pdb needs a MinAvailable update", + name: "pdb doesn't need a MaxUnavailable update", args: args{ initObjs: []client.Object{defaultPDB()}, es: defaultEs, @@ -92,13 +92,13 @@ func TestReconcile(t *testing.T) { Labels: map[string]string{label.ClusterNameLabelName: "cluster", commonv1.TypeLabelName: label.Type}, }, Spec: policyv1.PodDisruptionBudgetSpec{ - MinAvailable: intStrPtr(intstr.FromInt(5)), + MaxUnavailable: intStrPtr(intstr.FromInt(0)), Selector: &metav1.LabelSelector{ MatchLabels: map[string]string{ label.ClusterNameLabelName: "cluster", }, }, - MaxUnavailable: nil, + MinAvailable: nil, }, }, }, @@ -196,13 +196,13 @@ func Test_expectedPDB(t *testing.T) { Labels: map[string]string{label.ClusterNameLabelName: "cluster", commonv1.TypeLabelName: label.Type}, }, Spec: policyv1.PodDisruptionBudgetSpec{ - MinAvailable: intStrPtr(intstr.FromInt(3)), + MaxUnavailable: intStrPtr(intstr.FromInt(0)), Selector: &metav1.LabelSelector{ MatchLabels: map[string]string{ label.ClusterNameLabelName: "cluster", }, }, - MaxUnavailable: nil, + MinAvailable: nil, }, }, }, @@ -227,13 +227,13 @@ func Test_expectedPDB(t *testing.T) { Labels: map[string]string{"a": "b", "c": "d", label.ClusterNameLabelName: "cluster", commonv1.TypeLabelName: label.Type}, }, Spec: policyv1.PodDisruptionBudgetSpec{ - MinAvailable: intStrPtr(intstr.FromInt(3)), + MaxUnavailable: intStrPtr(intstr.FromInt(0)), Selector: &metav1.LabelSelector{ MatchLabels: map[string]string{ label.ClusterNameLabelName: "cluster", }, }, - MaxUnavailable: nil, + MinAvailable: nil, }, }, },