Merge pull request #99755 from lala123912/out_of_range

fix RemoveStatusCondition()  cap out of range
This commit is contained in:
Kubernetes Prow Robot 2021-03-04 07:44:49 -08:00 committed by GitHub
commit e22e9b4f83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -57,7 +57,7 @@ func SetStatusCondition(conditions *[]metav1.Condition, newCondition metav1.Cond
// RemoveStatusCondition removes the corresponding conditionType from conditions.
// conditions must be non-nil.
func RemoveStatusCondition(conditions *[]metav1.Condition, conditionType string) {
if conditions == nil {
if conditions == nil || len(*conditions) == 0 {
return
}
newConditions := make([]metav1.Condition, 0, len(*conditions)-1)

View File

@ -121,6 +121,12 @@ func TestRemoveStatusCondition(t *testing.T) {
{Type: "third"},
},
},
{
name: "empty_conditions",
conditions: []metav1.Condition{},
conditionType: "Foo",
expected: []metav1.Condition{},
},
}
for _, test := range tests {