mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 12:15:52 +00:00
Wrap errors on VolumeBinding plugin
Signed-off-by: Aldo Culquicondor <acondor@google.com> Change-Id: I23053528ac6857124fddd7f9fa26e122202ff4bd Signed-off-by: Aldo Culquicondor <acondor@google.com>
This commit is contained in:
parent
94985e28ac
commit
7fb40fc03c
@ -443,7 +443,7 @@ func (b *volumeBinder) BindPodVolumes(assumedPod *v1.Pod, podVolumes *PodVolumes
|
||||
return b, err
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to bind volumes: %v", err)
|
||||
return fmt.Errorf("binding volumes: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -543,7 +543,7 @@ func (b *volumeBinder) checkBindings(pod *v1.Pod, bindings []*BindingInfo, claim
|
||||
|
||||
node, err := b.nodeLister.Get(pod.Spec.NodeName)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("failed to get node %q: %v", pod.Spec.NodeName, err)
|
||||
return false, fmt.Errorf("failed to get node %q: %w", pod.Spec.NodeName, err)
|
||||
}
|
||||
|
||||
csiNode, err := b.csiNodeLister.Get(node.Name)
|
||||
@ -559,7 +559,7 @@ func (b *volumeBinder) checkBindings(pod *v1.Pod, bindings []*BindingInfo, claim
|
||||
_, err = b.podLister.Pods(pod.Namespace).Get(pod.Name)
|
||||
if err != nil {
|
||||
if apierrors.IsNotFound(err) {
|
||||
return false, fmt.Errorf("pod %q does not exist any more", podName)
|
||||
return false, fmt.Errorf("pod does not exist any more: %w", err)
|
||||
}
|
||||
klog.Errorf("failed to get pod %s/%s from the lister: %v", pod.Namespace, pod.Name, err)
|
||||
}
|
||||
@ -567,12 +567,12 @@ func (b *volumeBinder) checkBindings(pod *v1.Pod, bindings []*BindingInfo, claim
|
||||
for _, binding := range bindings {
|
||||
pv, err := b.pvCache.GetAPIPV(binding.pv.Name)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("failed to check binding: %v", err)
|
||||
return false, fmt.Errorf("failed to check binding: %w", err)
|
||||
}
|
||||
|
||||
pvc, err := b.pvcCache.GetAPIPVC(getPVCName(binding.pvc))
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("failed to check binding: %v", err)
|
||||
return false, fmt.Errorf("failed to check binding: %w", err)
|
||||
}
|
||||
|
||||
// Because we updated PV in apiserver, skip if API object is older
|
||||
@ -583,12 +583,12 @@ func (b *volumeBinder) checkBindings(pod *v1.Pod, bindings []*BindingInfo, claim
|
||||
|
||||
pv, err = b.tryTranslatePVToCSI(pv, csiNode)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("failed to translate pv to csi: %v", err)
|
||||
return false, fmt.Errorf("failed to translate pv to csi: %w", err)
|
||||
}
|
||||
|
||||
// Check PV's node affinity (the node might not have the proper label)
|
||||
if err := volumeutil.CheckNodeAffinity(pv, node.Labels); err != nil {
|
||||
return false, fmt.Errorf("pv %q node affinity doesn't match node %q: %v", pv.Name, node.Name, err)
|
||||
return false, fmt.Errorf("pv %q node affinity doesn't match node %q: %w", pv.Name, node.Name, err)
|
||||
}
|
||||
|
||||
// Check if pv.ClaimRef got dropped by unbindVolume()
|
||||
@ -605,7 +605,7 @@ func (b *volumeBinder) checkBindings(pod *v1.Pod, bindings []*BindingInfo, claim
|
||||
for _, claim := range claimsToProvision {
|
||||
pvc, err := b.pvcCache.GetAPIPVC(getPVCName(claim))
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("failed to check provisioning pvc: %v", err)
|
||||
return false, fmt.Errorf("failed to check provisioning pvc: %w", err)
|
||||
}
|
||||
|
||||
// Because we updated PVC in apiserver, skip if API object is older
|
||||
@ -637,7 +637,7 @@ func (b *volumeBinder) checkBindings(pod *v1.Pod, bindings []*BindingInfo, claim
|
||||
// be unbound eventually.
|
||||
return false, nil
|
||||
}
|
||||
return false, fmt.Errorf("failed to get pv %q from cache: %v", pvc.Spec.VolumeName, err)
|
||||
return false, fmt.Errorf("failed to get pv %q from cache: %w", pvc.Spec.VolumeName, err)
|
||||
}
|
||||
|
||||
pv, err = b.tryTranslatePVToCSI(pv, csiNode)
|
||||
@ -646,7 +646,7 @@ func (b *volumeBinder) checkBindings(pod *v1.Pod, bindings []*BindingInfo, claim
|
||||
}
|
||||
|
||||
if err := volumeutil.CheckNodeAffinity(pv, node.Labels); err != nil {
|
||||
return false, fmt.Errorf("pv %q node affinity doesn't match node %q: %v", pv.Name, node.Name, err)
|
||||
return false, fmt.Errorf("pv %q node affinity doesn't match node %q: %w", pv.Name, node.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,7 +99,7 @@ func (pl *VolumeBinding) PreFilter(ctx context.Context, state *framework.CycleSt
|
||||
}
|
||||
boundClaims, claimsToBind, unboundClaimsImmediate, err := pl.Binder.GetPodVolumes(pod)
|
||||
if err != nil {
|
||||
return framework.NewStatus(framework.Error, err.Error())
|
||||
return framework.AsStatus(err)
|
||||
}
|
||||
if len(unboundClaimsImmediate) > 0 {
|
||||
// Return UnschedulableAndUnresolvable error if immediate claims are
|
||||
@ -153,7 +153,7 @@ func (pl *VolumeBinding) Filter(ctx context.Context, cs *framework.CycleState, p
|
||||
|
||||
state, err := getStateData(cs)
|
||||
if err != nil {
|
||||
return framework.NewStatus(framework.Error, err.Error())
|
||||
return framework.AsStatus(err)
|
||||
}
|
||||
|
||||
if state.skip {
|
||||
@ -184,14 +184,14 @@ func (pl *VolumeBinding) Filter(ctx context.Context, cs *framework.CycleState, p
|
||||
func (pl *VolumeBinding) Reserve(ctx context.Context, cs *framework.CycleState, pod *v1.Pod, nodeName string) *framework.Status {
|
||||
state, err := getStateData(cs)
|
||||
if err != nil {
|
||||
return framework.NewStatus(framework.Error, err.Error())
|
||||
return framework.AsStatus(err)
|
||||
}
|
||||
// we don't need to hold the lock as only one node will be reserved for the given pod
|
||||
podVolumes, ok := state.podVolumesByNode[nodeName]
|
||||
if ok {
|
||||
allBound, err := pl.Binder.AssumePodVolumes(pod, nodeName, podVolumes)
|
||||
if err != nil {
|
||||
return framework.NewStatus(framework.Error, err.Error())
|
||||
return framework.AsStatus(err)
|
||||
}
|
||||
state.allBound = allBound
|
||||
} else {
|
||||
@ -209,7 +209,7 @@ func (pl *VolumeBinding) Reserve(ctx context.Context, cs *framework.CycleState,
|
||||
func (pl *VolumeBinding) PreBind(ctx context.Context, cs *framework.CycleState, pod *v1.Pod, nodeName string) *framework.Status {
|
||||
s, err := getStateData(cs)
|
||||
if err != nil {
|
||||
return framework.NewStatus(framework.Error, err.Error())
|
||||
return framework.AsStatus(err)
|
||||
}
|
||||
if s.allBound {
|
||||
// no need to bind volumes
|
||||
@ -218,13 +218,13 @@ func (pl *VolumeBinding) PreBind(ctx context.Context, cs *framework.CycleState,
|
||||
// we don't need to hold the lock as only one node will be pre-bound for the given pod
|
||||
podVolumes, ok := s.podVolumesByNode[nodeName]
|
||||
if !ok {
|
||||
return framework.NewStatus(framework.Error, fmt.Sprintf("no pod volumes found for node %q", nodeName))
|
||||
return framework.AsStatus(fmt.Errorf("no pod volumes found for node %q", nodeName))
|
||||
}
|
||||
klog.V(5).Infof("Trying to bind volumes for pod \"%v/%v\"", pod.Namespace, pod.Name)
|
||||
err = pl.Binder.BindPodVolumes(pod, podVolumes)
|
||||
if err != nil {
|
||||
klog.V(1).Infof("Failed to bind volumes for pod \"%v/%v\": %v", pod.Namespace, pod.Name, err)
|
||||
return framework.NewStatus(framework.Error, err.Error())
|
||||
return framework.AsStatus(err)
|
||||
}
|
||||
klog.V(5).Infof("Success binding volumes for pod \"%v/%v\"", pod.Namespace, pod.Name)
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user