diff --git a/util/conditions/setter.go b/util/conditions/setter.go index fcea28476a73..376c2c0890bb 100644 --- a/util/conditions/setter.go +++ b/util/conditions/setter.go @@ -116,7 +116,9 @@ func Delete(to Setter, conditionType string) { } conditions := to.GetConditions() - newConditions := make([]metav1.Condition, 0, len(conditions)-1) + // allocate same length array because the conditions length might be 0 + // or the condition to be deleted might not be part of the list. + newConditions := make([]metav1.Condition, 0, len(conditions)) for _, condition := range conditions { if condition.Type != conditionType { newConditions = append(newConditions, condition) diff --git a/util/deprecated/v1beta1/conditions/v1beta2/setter.go b/util/deprecated/v1beta1/conditions/v1beta2/setter.go index 75b1042b94e7..cbc1136642d1 100644 --- a/util/deprecated/v1beta1/conditions/v1beta2/setter.go +++ b/util/deprecated/v1beta1/conditions/v1beta2/setter.go @@ -117,7 +117,9 @@ func Delete(to Setter, conditionType string) { } conditions := to.GetV1Beta2Conditions() - newConditions := make([]metav1.Condition, 0, len(conditions)-1) + // allocate same length array because the conditions length might be 0 + // or the condition to be deleted might not be part of the list. + newConditions := make([]metav1.Condition, 0, len(conditions)) for _, condition := range conditions { if condition.Type != conditionType { newConditions = append(newConditions, condition)