Fix nil pointer dereference in disruption controller

This commit is contained in:
Morten Torkildsen
2021-02-03 21:04:29 -08:00
parent ebe7380b38
commit b63342af70
2 changed files with 41 additions and 3 deletions

View File

@@ -1160,6 +1160,44 @@ func TestUpdatePDBStatusRetries(t *testing.T) {
}
}
func TestInvalidSelectors(t *testing.T) {
testCases := map[string]struct {
labelSelector *metav1.LabelSelector
}{
"illegal value key": {
labelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"k8s.io/too/many/slashes": "value",
},
},
},
"illegal operator": {
labelSelector: &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{
{
Key: "foo",
Operator: metav1.LabelSelectorOperator("illegal"),
Values: []string{"bar"},
},
},
},
},
}
for tn, tc := range testCases {
t.Run(tn, func(t *testing.T) {
dc, ps := newFakeDisruptionController()
pdb, pdbName := newMinAvailablePodDisruptionBudget(t, intstr.FromInt(3))
pdb.Spec.Selector = tc.labelSelector
add(t, dc.pdbStore, pdb)
dc.sync(pdbName)
ps.VerifyPdbStatus(t, pdbName, 0, 0, 0, 0, map[string]metav1.Time{})
})
}
}
// waitForCacheCount blocks until the given cache store has the desired number
// of items in it. This will return an error if the condition is not met after a
// 10 second timeout.