Fix some error messages

This commit is contained in:
Jan Safranek 2019-07-22 10:54:33 +02:00
parent 17be780651
commit af0c2fe572
5 changed files with 25 additions and 38 deletions

View File

@ -1673,8 +1673,8 @@ func (kl *Kubelet) syncPod(o syncPodOptions) error {
if !kl.podIsTerminated(pod) { if !kl.podIsTerminated(pod) {
// Wait for volumes to attach/mount // Wait for volumes to attach/mount
if err := kl.volumeManager.WaitForAttachAndMount(pod); err != nil { if err := kl.volumeManager.WaitForAttachAndMount(pod); err != nil {
kl.recorder.Eventf(pod, v1.EventTypeWarning, events.FailedMountVolume, "Unable to mount volumes for pod %q: %v", format.Pod(pod), err) kl.recorder.Eventf(pod, v1.EventTypeWarning, events.FailedMountVolume, "Unable to attach or mount volumes: %v", err)
klog.Errorf("Unable to mount volumes for pod %q: %v; skipping pod", format.Pod(pod), err) klog.Errorf("Unable to attach or mount volumes for pod %q: %v; skipping pod", format.Pod(pod), err)
return err return err
} }
} }

View File

@ -61,6 +61,7 @@ go_test(
"//staging/src/k8s.io/api/core/v1:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
"//staging/src/k8s.io/client-go/kubernetes:go_default_library", "//staging/src/k8s.io/client-go/kubernetes:go_default_library",
"//staging/src/k8s.io/client-go/kubernetes/fake:go_default_library", "//staging/src/k8s.io/client-go/kubernetes/fake:go_default_library",
"//staging/src/k8s.io/client-go/tools/record:go_default_library", "//staging/src/k8s.io/client-go/tools/record:go_default_library",

View File

@ -23,6 +23,7 @@ go_library(
"//staging/src/k8s.io/api/core/v1:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/resource:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/api/resource:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library", "//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
"//vendor/k8s.io/klog:go_default_library", "//vendor/k8s.io/klog:go_default_library",
], ],

View File

@ -21,6 +21,7 @@ caches in sync with the "ground truth".
package populator package populator
import ( import (
"errors"
"fmt" "fmt"
"sync" "sync"
"time" "time"
@ -317,7 +318,7 @@ func (dswp *desiredStateOfWorldPopulator) processPodVolumes(
uniquePodName, pod, volumeSpec, podVolume.Name, volumeGidValue) uniquePodName, pod, volumeSpec, podVolume.Name, volumeGidValue)
if err != nil { if err != nil {
klog.Errorf( klog.Errorf(
"Failed to add volume %q (specName: %q) for pod %q to desiredStateOfWorld. err=%v", "Failed to add volume %s (specName: %s) for pod %q to desiredStateOfWorld: %v",
podVolume.Name, podVolume.Name,
volumeSpec.Name(), volumeSpec.Name(),
uniquePodName, uniquePodName,
@ -497,7 +498,7 @@ func (dswp *desiredStateOfWorldPopulator) createVolumeSpec(
podNamespace, pvcSource.ClaimName) podNamespace, pvcSource.ClaimName)
if err != nil { if err != nil {
return nil, nil, "", fmt.Errorf( return nil, nil, "", fmt.Errorf(
"error processing PVC %q/%q: %v", "error processing PVC %s/%s: %v",
podNamespace, podNamespace,
pvcSource.ClaimName, pvcSource.ClaimName,
err) err)
@ -516,7 +517,7 @@ func (dswp *desiredStateOfWorldPopulator) createVolumeSpec(
dswp.getPVSpec(pvName, pvcSource.ReadOnly, pvcUID) dswp.getPVSpec(pvName, pvcSource.ReadOnly, pvcUID)
if err != nil { if err != nil {
return nil, nil, "", fmt.Errorf( return nil, nil, "", fmt.Errorf(
"error processing PVC %q/%q: %v", "error processing PVC %s/%s: %v",
podNamespace, podNamespace,
pvcSource.ClaimName, pvcSource.ClaimName,
err) err)
@ -539,20 +540,16 @@ func (dswp *desiredStateOfWorldPopulator) createVolumeSpec(
// Error if a container has volumeMounts but the volumeMode of PVC isn't Filesystem // Error if a container has volumeMounts but the volumeMode of PVC isn't Filesystem
if mountsMap[podVolume.Name] && volumeMode != v1.PersistentVolumeFilesystem { if mountsMap[podVolume.Name] && volumeMode != v1.PersistentVolumeFilesystem {
return nil, nil, "", fmt.Errorf( return nil, nil, "", fmt.Errorf(
"Volume %q has volumeMode %q, but is specified in volumeMounts for pod %q/%q", "volume %s has volumeMode %s, but is specified in volumeMounts",
podVolume.Name, podVolume.Name,
volumeMode, volumeMode)
podNamespace,
podName)
} }
// Error if a container has volumeDevices but the volumeMode of PVC isn't Block // Error if a container has volumeDevices but the volumeMode of PVC isn't Block
if devicesMap[podVolume.Name] && volumeMode != v1.PersistentVolumeBlock { if devicesMap[podVolume.Name] && volumeMode != v1.PersistentVolumeBlock {
return nil, nil, "", fmt.Errorf( return nil, nil, "", fmt.Errorf(
"Volume %q has volumeMode %q, but is specified in volumeDevices for pod %q/%q", "volume %s has volumeMode %s, but is specified in volumeDevices",
podVolume.Name, podVolume.Name,
volumeMode, volumeMode)
podNamespace,
podName)
} }
} }
return pvc, volumeSpec, volumeGidValue, nil return pvc, volumeSpec, volumeGidValue, nil
@ -573,11 +570,7 @@ func (dswp *desiredStateOfWorldPopulator) getPVCExtractPV(
pvc, err := pvc, err :=
dswp.kubeClient.CoreV1().PersistentVolumeClaims(namespace).Get(claimName, metav1.GetOptions{}) dswp.kubeClient.CoreV1().PersistentVolumeClaims(namespace).Get(claimName, metav1.GetOptions{})
if err != nil || pvc == nil { if err != nil || pvc == nil {
return nil, fmt.Errorf( return nil, fmt.Errorf("failed to fetch PVC from API server: %v", err)
"failed to fetch PVC %s/%s from API server. err=%v",
namespace,
claimName,
err)
} }
if utilfeature.DefaultFeatureGate.Enabled(features.StorageObjectInUseProtection) { if utilfeature.DefaultFeatureGate.Enabled(features.StorageObjectInUseProtection) {
@ -590,21 +583,15 @@ func (dswp *desiredStateOfWorldPopulator) getPVCExtractPV(
// It should happen only in very rare case when scheduler schedules // It should happen only in very rare case when scheduler schedules
// a pod and user deletes a PVC that's used by it at the same time. // a pod and user deletes a PVC that's used by it at the same time.
if pvc.ObjectMeta.DeletionTimestamp != nil { if pvc.ObjectMeta.DeletionTimestamp != nil {
return nil, fmt.Errorf( return nil, errors.New("PVC is being deleted")
"can't start pod because PVC %s/%s is being deleted",
namespace,
claimName)
} }
} }
if pvc.Status.Phase != v1.ClaimBound || pvc.Spec.VolumeName == "" { if pvc.Status.Phase != v1.ClaimBound {
return nil, errors.New("PVC is not bound")
return nil, fmt.Errorf( }
"PVC %s/%s has non-bound phase (%q) or empty pvc.Spec.VolumeName (%q)", if pvc.Spec.VolumeName == "" {
namespace, return nil, errors.New("PVC has empty pvc.Spec.VolumeName")
claimName,
pvc.Status.Phase,
pvc.Spec.VolumeName)
} }
return pvc, nil return pvc, nil
@ -620,18 +607,18 @@ func (dswp *desiredStateOfWorldPopulator) getPVSpec(
pv, err := dswp.kubeClient.CoreV1().PersistentVolumes().Get(name, metav1.GetOptions{}) pv, err := dswp.kubeClient.CoreV1().PersistentVolumes().Get(name, metav1.GetOptions{})
if err != nil || pv == nil { if err != nil || pv == nil {
return nil, "", fmt.Errorf( return nil, "", fmt.Errorf(
"failed to fetch PV %q from API server. err=%v", name, err) "failed to fetch PV %s from API server: %v", name, err)
} }
if pv.Spec.ClaimRef == nil { if pv.Spec.ClaimRef == nil {
return nil, "", fmt.Errorf( return nil, "", fmt.Errorf(
"found PV object %q but it has a nil pv.Spec.ClaimRef indicating it is not yet bound to the claim", "found PV object %s but it has a nil pv.Spec.ClaimRef indicating it is not yet bound to the claim",
name) name)
} }
if pv.Spec.ClaimRef.UID != expectedClaimUID { if pv.Spec.ClaimRef.UID != expectedClaimUID {
return nil, "", fmt.Errorf( return nil, "", fmt.Errorf(
"found PV object %q but its pv.Spec.ClaimRef.UID (%q) does not point to claim.UID (%q)", "found PV object %s but its pv.Spec.ClaimRef.UID %s does not point to claim.UID %s",
name, name,
pv.Spec.ClaimRef.UID, pv.Spec.ClaimRef.UID,
expectedClaimUID) expectedClaimUID)

View File

@ -376,12 +376,10 @@ func (vm *volumeManager) WaitForAttachAndMount(pod *v1.Pod) error {
} }
return fmt.Errorf( return fmt.Errorf(
"failed to attach or mount for pod %q/%q: %s. List of unmounted volumes=%v, list of unattached volumes=%v.", "unmounted volumes=%v, unattached volumes=%v: %s",
pod.Namespace,
pod.Name,
err,
unmountedVolumes, unmountedVolumes,
unattachedVolumes) unattachedVolumes,
err)
} }
klog.V(3).Infof("All volumes are attached and mounted for pod %q", format.Pod(pod)) klog.V(3).Infof("All volumes are attached and mounted for pod %q", format.Pod(pod))