From 091724a6d86eb8ce86ffd4aaca4e8d4fb07785ef Mon Sep 17 00:00:00 2001 From: Jordan Liggitt Date: Thu, 28 Oct 2021 00:16:19 -0400 Subject: [PATCH] apierrors: optimize ToAggregate() for zero-length lists --- .../k8s.io/apimachinery/pkg/util/validation/field/errors.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/staging/src/k8s.io/apimachinery/pkg/util/validation/field/errors.go b/staging/src/k8s.io/apimachinery/pkg/util/validation/field/errors.go index c283ad189a0..2ed368f5693 100644 --- a/staging/src/k8s.io/apimachinery/pkg/util/validation/field/errors.go +++ b/staging/src/k8s.io/apimachinery/pkg/util/validation/field/errors.go @@ -239,6 +239,9 @@ func NewErrorTypeMatcher(t ErrorType) utilerrors.Matcher { // ToAggregate converts the ErrorList into an errors.Aggregate. func (list ErrorList) ToAggregate() utilerrors.Aggregate { + if len(list) == 0 { + return nil + } errs := make([]error, 0, len(list)) errorMsgs := sets.NewString() for _, err := range list {