Skip to content

Commit 9bcdf1f

Browse files
committed
Use MaxUnavailable for PDB
1 parent bce5e79 commit 9bcdf1f

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

pkg/controller/elasticsearch/pdb/reconcile.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,7 @@ func expectedPDB(es esv1.Elasticsearch, statefulSets sset.StatefulSetList) (*pol
162162
// buildPDBSpec returns a PDBSpec computed from the current StatefulSets,
163163
// considering the cluster health and topology.
164164
func buildPDBSpec(es esv1.Elasticsearch, statefulSets sset.StatefulSetList) policyv1.PodDisruptionBudgetSpec {
165-
// compute MinAvailable based on the maximum number of Pods we're supposed to have
166-
nodeCount := statefulSets.ExpectedNodeCount()
167-
// maybe allow some Pods to be disrupted
168-
minAvailable := nodeCount - allowedDisruptions(es, statefulSets)
169-
170-
minAvailableIntStr := intstr.IntOrString{Type: intstr.Int, IntVal: minAvailable}
165+
maxUnavailableIntStr := intstr.IntOrString{Type: intstr.Int, IntVal: allowedDisruptions(es, statefulSets)}
171166

172167
return policyv1.PodDisruptionBudgetSpec{
173168
// match all pods for this cluster
@@ -176,10 +171,8 @@ func buildPDBSpec(es esv1.Elasticsearch, statefulSets sset.StatefulSetList) poli
176171
label.ClusterNameLabelName: es.Name,
177172
},
178173
},
179-
MinAvailable: &minAvailableIntStr,
180-
// MaxUnavailable can only be used if the selector matches a builtin controller selector
181-
// (eg. Deployments, StatefulSets, etc.). We cannot use it with our own cluster-name selector.
182-
MaxUnavailable: nil,
174+
MaxUnavailable: &maxUnavailableIntStr,
175+
MinAvailable: nil,
183176
}
184177
}
185178

pkg/controller/elasticsearch/pdb/reconcile_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ func TestReconcile(t *testing.T) {
4040
Labels: map[string]string{label.ClusterNameLabelName: "cluster", commonv1.TypeLabelName: label.Type},
4141
},
4242
Spec: policyv1.PodDisruptionBudgetSpec{
43-
MinAvailable: intStrPtr(intstr.FromInt(3)),
43+
MaxUnavailable: intStrPtr(intstr.FromInt(0)),
4444
Selector: &metav1.LabelSelector{
4545
MatchLabels: map[string]string{
4646
label.ClusterNameLabelName: "cluster",
4747
},
4848
},
49-
MaxUnavailable: nil,
49+
MinAvailable: nil,
5050
},
5151
}
5252
}
@@ -79,7 +79,7 @@ func TestReconcile(t *testing.T) {
7979
wantPDB: defaultPDB(),
8080
},
8181
{
82-
name: "pdb needs a MinAvailable update",
82+
name: "pdb doesn't need a MaxUnavailable update",
8383
args: args{
8484
initObjs: []client.Object{defaultPDB()},
8585
es: defaultEs,
@@ -92,13 +92,13 @@ func TestReconcile(t *testing.T) {
9292
Labels: map[string]string{label.ClusterNameLabelName: "cluster", commonv1.TypeLabelName: label.Type},
9393
},
9494
Spec: policyv1.PodDisruptionBudgetSpec{
95-
MinAvailable: intStrPtr(intstr.FromInt(5)),
95+
MaxUnavailable: intStrPtr(intstr.FromInt(0)),
9696
Selector: &metav1.LabelSelector{
9797
MatchLabels: map[string]string{
9898
label.ClusterNameLabelName: "cluster",
9999
},
100100
},
101-
MaxUnavailable: nil,
101+
MinAvailable: nil,
102102
},
103103
},
104104
},
@@ -196,13 +196,13 @@ func Test_expectedPDB(t *testing.T) {
196196
Labels: map[string]string{label.ClusterNameLabelName: "cluster", commonv1.TypeLabelName: label.Type},
197197
},
198198
Spec: policyv1.PodDisruptionBudgetSpec{
199-
MinAvailable: intStrPtr(intstr.FromInt(3)),
199+
MaxUnavailable: intStrPtr(intstr.FromInt(0)),
200200
Selector: &metav1.LabelSelector{
201201
MatchLabels: map[string]string{
202202
label.ClusterNameLabelName: "cluster",
203203
},
204204
},
205-
MaxUnavailable: nil,
205+
MinAvailable: nil,
206206
},
207207
},
208208
},
@@ -227,13 +227,13 @@ func Test_expectedPDB(t *testing.T) {
227227
Labels: map[string]string{"a": "b", "c": "d", label.ClusterNameLabelName: "cluster", commonv1.TypeLabelName: label.Type},
228228
},
229229
Spec: policyv1.PodDisruptionBudgetSpec{
230-
MinAvailable: intStrPtr(intstr.FromInt(3)),
230+
MaxUnavailable: intStrPtr(intstr.FromInt(0)),
231231
Selector: &metav1.LabelSelector{
232232
MatchLabels: map[string]string{
233233
label.ClusterNameLabelName: "cluster",
234234
},
235235
},
236-
MaxUnavailable: nil,
236+
MinAvailable: nil,
237237
},
238238
},
239239
},

0 commit comments

Comments
 (0)