fix RemoveStatusCondition() cap out of range

This commit is contained in:
lala123912 2021-03-04 11:53:24 +08:00
parent 4f9317596c
commit b96e7f5a8a
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 {