mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Merge pull request #106673 from qmloong/qmloong/master
refactor: use utilerrors instead of join error msg
This commit is contained in:
commit
d16a5e5feb
@ -19,8 +19,6 @@ package node
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
|
|
||||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"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 {
|
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)
|
klog.V(2).InfoS("Update ready status of pods on node", "node", nodeName)
|
||||||
|
|
||||||
errMsg := []string{}
|
errs := []error{}
|
||||||
for i := range pods {
|
for i := range pods {
|
||||||
// Defensive check, also needed for tests.
|
// Defensive check, also needed for tests.
|
||||||
if pods[i].Spec.NodeName != nodeName {
|
if pods[i].Spec.NodeName != nodeName {
|
||||||
@ -146,7 +144,7 @@ func MarkPodsNotReady(ctx context.Context, kubeClient clientset.Interface, recor
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
klog.InfoS("Failed to update status for pod", "pod", klog.KObj(pod), "err", err)
|
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
|
// record NodeNotReady event after updateStatus to make sure pod still exists
|
||||||
recorder.Event(pod, v1.EventTypeWarning, "NodeNotReady", "Node is not ready")
|
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 utilerrors.NewAggregate(errs)
|
||||||
}
|
|
||||||
return fmt.Errorf("%v", strings.Join(errMsg, "; "))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RecordNodeEvent records a event related to a node.
|
// RecordNodeEvent records a event related to a node.
|
||||||
|
Loading…
Reference in New Issue
Block a user