Merge pull request #106673 from qmloong/qmloong/master

refactor: use utilerrors instead of join error msg
This commit is contained in:
Kubernetes Prow Robot 2021-12-07 18:27:22 -08:00 committed by GitHub
commit d16a5e5feb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,8 +19,6 @@ package node
import (
"context"
"fmt"
"strings"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
@ -121,7 +119,7 @@ func SetPodTerminationReason(ctx context.Context, kubeClient clientset.Interface
func MarkPodsNotReady(ctx context.Context, kubeClient clientset.Interface, recorder record.EventRecorder, pods []*v1.Pod, nodeName string) error {
klog.V(2).InfoS("Update ready status of pods on node", "node", nodeName)
errMsg := []string{}
errs := []error{}
for i := range pods {
// Defensive check, also needed for tests.
if pods[i].Spec.NodeName != nodeName {
@ -146,7 +144,7 @@ func MarkPodsNotReady(ctx context.Context, kubeClient clientset.Interface, recor
continue
}
klog.InfoS("Failed to update status for pod", "pod", klog.KObj(pod), "err", err)
errMsg = append(errMsg, fmt.Sprintf("%v", err))
errs = append(errs, err)
}
// record NodeNotReady event after updateStatus to make sure pod still exists
recorder.Event(pod, v1.EventTypeWarning, "NodeNotReady", "Node is not ready")
@ -154,10 +152,8 @@ func MarkPodsNotReady(ctx context.Context, kubeClient clientset.Interface, recor
}
}
}
if len(errMsg) == 0 {
return nil
}
return fmt.Errorf("%v", strings.Join(errMsg, "; "))
return utilerrors.NewAggregate(errs)
}
// RecordNodeEvent records a event related to a node.