Skip to content

Commit 1d91743

Browse files
committed
fix: account for nil CRP policy
1 parent 9a3cd78 commit 1d91743

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

pkg/controllers/clusterresourceplacementeviction/controller.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func (r *Reconciler) executeEviction(ctx context.Context, validationResult *evic
209209
}
210210

211211
// handle special case for PickAll CRP.
212-
if crp.Spec.Policy.PlacementType == placementv1beta1.PickAllPlacementType {
212+
if crp.Spec.Policy == nil || crp.Spec.Policy.PlacementType == placementv1beta1.PickAllPlacementType {
213213
if db.Spec.MaxUnavailable != nil || (db.Spec.MinAvailable != nil && db.Spec.MinAvailable.Type == intstr.String) {
214214
markEvictionNotExecuted(eviction, evictionBlockedMisconfiguredPDBSpecifiedMessage)
215215
return nil
@@ -271,7 +271,12 @@ func isEvictionAllowed(bindings []placementv1beta1.ClusterResourceBinding, crp p
271271
}
272272

273273
var desiredBindings int
274-
placementType := crp.Spec.Policy.PlacementType
274+
var placementType placementv1beta1.PlacementType
275+
if crp.Spec.Policy != nil {
276+
placementType = crp.Spec.Policy.PlacementType
277+
} else {
278+
placementType = placementv1beta1.PickAllPlacementType
279+
}
275280
switch placementType {
276281
case placementv1beta1.PickNPlacementType:
277282
desiredBindings = int(*crp.Spec.Policy.NumberOfClusters)

pkg/controllers/clusterresourceplacementeviction/controller_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -536,18 +536,14 @@ func TestExecuteEviction(t *testing.T) {
536536
wantErr: nil,
537537
},
538538
{
539-
name: "PickAll CRP, Misconfigured PDB MinAvailable specified as percentage - eviction not executed",
539+
name: "PickAll CRP policy not specified, Misconfigured PDB MinAvailable specified as percentage - eviction not executed",
540540
validationResult: &evictionValidationResult{
541541
crb: availableBinding,
542542
crp: &placementv1beta1.ClusterResourcePlacement{
543543
ObjectMeta: metav1.ObjectMeta{
544544
Name: testCRPName,
545545
},
546-
Spec: placementv1beta1.ClusterResourcePlacementSpec{
547-
Policy: &placementv1beta1.PlacementPolicy{
548-
PlacementType: placementv1beta1.PickAllPlacementType,
549-
},
550-
},
546+
Spec: placementv1beta1.ClusterResourcePlacementSpec{},
551547
},
552548
},
553549
eviction: buildTestEviction(testEvictionName, testCRPName, testClusterName),
@@ -1361,8 +1357,13 @@ func TestIsEvictionAllowed(t *testing.T) {
13611357
wantAvailableBindings: 3,
13621358
},
13631359
{
1364-
name: "MinAvailable specified as Integer zero, available binding, PickAll CRP - allow eviction",
1365-
crp: buildTestPickAllCRP(testCRPName),
1360+
name: "MinAvailable specified as Integer zero, available binding, PickAll CRP, no policy specified - allow eviction",
1361+
crp: placementv1beta1.ClusterResourcePlacement{
1362+
ObjectMeta: metav1.ObjectMeta{
1363+
Name: testCRPName,
1364+
},
1365+
Spec: placementv1beta1.ClusterResourcePlacementSpec{},
1366+
},
13661367
bindings: []placementv1beta1.ClusterResourceBinding{boundAvailableBinding},
13671368
disruptionBudget: placementv1alpha1.ClusterResourcePlacementDisruptionBudget{
13681369
ObjectMeta: metav1.ObjectMeta{

0 commit comments

Comments
 (0)