Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup: fix errors in wrapped format and log capitalization in controller #101304

Merged
merged 1 commit into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (o *PersistentVolumeBinderControllerOptions) Validate() []error {

errs := []error{}
if _, err := ParseVolumeHostFilters(o.VolumeHostCIDRDenylist, o.VolumeHostAllowLocalLoopback); err != nil {
errs = append(errs, fmt.Errorf("Bad --volume-host-ip-denylist/--volume-host-allow-local-loopback %w", err))
errs = append(errs, fmt.Errorf("bad --volume-host-ip-denylist/--volume-host-allow-local-loopback %w", err))
}
return errs
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/endpointslice/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (r *reconciler) reconcile(service *corev1.Service, pods []*corev1.Pod, exis
for _, sliceToDelete := range slicesToDelete {
err := r.client.DiscoveryV1().EndpointSlices(service.Namespace).Delete(context.TODO(), sliceToDelete.Name, metav1.DeleteOptions{})
if err != nil {
errs = append(errs, fmt.Errorf("Error deleting %s EndpointSlice for Service %s/%s: %v", sliceToDelete.Name, service.Namespace, service.Name, err))
errs = append(errs, fmt.Errorf("error deleting %s EndpointSlice for Service %s/%s: %w", sliceToDelete.Name, service.Namespace, service.Name, err))
} else {
r.endpointSliceTracker.ExpectDeletion(sliceToDelete)
metrics.EndpointSliceChanges.WithLabelValues("delete").Inc()
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/endpointslicemirroring/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func (r *reconciler) deleteEndpoints(namespace, name string, endpointSlices []*d
}
}
if len(errs) > 0 {
return fmt.Errorf("Error(s) deleting %d/%d EndpointSlices for %s/%s Endpoints, including: %s", len(errs), len(endpointSlices), namespace, name, errs[0])
return fmt.Errorf("error(s) deleting %d/%d EndpointSlices for %s/%s Endpoints, including: %s", len(errs), len(endpointSlices), namespace, name, errs[0])
}
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func NewAttachDetachController(
adc.volumeAttachmentSynced = volumeAttachmentInformer.Informer().HasSynced

if err := adc.volumePluginMgr.InitPlugins(plugins, prober, adc); err != nil {
return nil, fmt.Errorf("Could not initialize volume plugins for Attach/Detach Controller: %+v", err)
return nil, fmt.Errorf("could not initialize volume plugins for Attach/Detach Controller: %w", err)
}

eventBroadcaster := record.NewBroadcaster()
Expand Down Expand Up @@ -206,7 +206,7 @@ func NewAttachDetachController(
// This custom indexer will index pods by its PVC keys. Then we don't need
// to iterate all pods every time to find pods which reference given PVC.
if err := common.AddPodPVCIndexerIfNotPresent(adc.podIndexer); err != nil {
return nil, fmt.Errorf("Could not initialize attach detach controller: %v", err)
return nil, fmt.Errorf("could not initialize attach detach controller: %w", err)
}

nodeInformer.Informer().AddEventHandler(kcache.ResourceEventHandlerFuncs{
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/volume/ephemeral/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func NewController(
DeleteFunc: ec.onPVCDelete,
})
if err := common.AddPodPVCIndexerIfNotPresent(ec.podIndexer); err != nil {
return nil, fmt.Errorf("Could not initialize pvc protection controller: %v", err)
return nil, fmt.Errorf("could not initialize pvc protection controller: %w", err)
}

return ec, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/volume/persistentvolume/binder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ func TestSync(t *testing.T) {
newVolumeArray("volume4-10", "10Gi", "uid4-10", "claim4-10", v1.VolumeAvailable, v1.PersistentVolumeReclaimDelete, classEmpty),
func() []*v1.PersistentVolume {
volumes := newVolumeArray("volume4-10", "10Gi", "uid4-10", "claim4-10", v1.VolumeFailed, v1.PersistentVolumeReclaimDelete, classEmpty)
volumes[0].Status.Message = `Error getting deleter volume plugin for volume "volume4-10": no volume plugin matched`
volumes[0].Status.Message = `error getting deleter volume plugin for volume "volume4-10": no volume plugin matched`
return volumes
}(),
noclaims,
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/volume/persistentvolume/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestDeleteSync(t *testing.T) {
// delete failure - plugin not found
"8-3 - plugin not found",
newVolumeArray("volume8-3", "1Gi", "uid8-3", "claim8-3", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty),
withMessage("Error getting deleter volume plugin for volume \"volume8-3\": no volume plugin matched", newVolumeArray("volume8-3", "1Gi", "uid8-3", "claim8-3", v1.VolumeFailed, v1.PersistentVolumeReclaimDelete, classEmpty)),
withMessage("error getting deleter volume plugin for volume \"volume8-3\": no volume plugin matched", newVolumeArray("volume8-3", "1Gi", "uid8-3", "claim8-3", v1.VolumeFailed, v1.PersistentVolumeReclaimDelete, classEmpty)),
noclaims,
noclaims,
[]string{"Warning VolumeFailedDelete"}, noerrors, testSyncVolume,
Expand All @@ -69,7 +69,7 @@ func TestDeleteSync(t *testing.T) {
// delete failure - newDeleter returns error
"8-4 - newDeleter returns error",
newVolumeArray("volume8-4", "1Gi", "uid8-4", "claim8-4", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty),
withMessage("Failed to create deleter for volume \"volume8-4\": Mock plugin error: no deleteCalls configured", newVolumeArray("volume8-4", "1Gi", "uid8-4", "claim8-4", v1.VolumeFailed, v1.PersistentVolumeReclaimDelete, classEmpty)),
withMessage("failed to create deleter for volume \"volume8-4\": Mock plugin error: no deleteCalls configured", newVolumeArray("volume8-4", "1Gi", "uid8-4", "claim8-4", v1.VolumeFailed, v1.PersistentVolumeReclaimDelete, classEmpty)),
noclaims,
noclaims,
[]string{"Warning VolumeFailedDelete"}, noerrors,
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/volume/persistentvolume/framework_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,18 @@ func checkEvents(t *testing.T, expectedEvents []string, ctrl *PersistentVolumeCo
for i, expected := range expectedEvents {
if len(gotEvents) <= i {
t.Errorf("Event %q not emitted", expected)
err = fmt.Errorf("Events do not match")
err = fmt.Errorf("events do not match")
continue
}
received := gotEvents[i]
if !strings.HasPrefix(received, expected) {
t.Errorf("Unexpected event received, expected %q, got %q", expected, received)
err = fmt.Errorf("Events do not match")
err = fmt.Errorf("events do not match")
}
}
for i := len(expectedEvents); i < len(gotEvents); i++ {
t.Errorf("Unexpected event received: %q", gotEvents[i])
err = fmt.Errorf("Events do not match")
err = fmt.Errorf("events do not match")
}
return err
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/controller/volume/persistentvolume/pv_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func (ctrl *PersistentVolumeController) syncUnboundClaim(claim *v1.PersistentVol
volume, err := ctrl.volumes.findBestMatchForClaim(claim, delayBinding)
if err != nil {
klog.V(2).Infof("synchronizing unbound PersistentVolumeClaim[%s]: Error finding PV for claim: %v", claimToClaimKey(claim), err)
return fmt.Errorf("Error finding PV for claim %q: %v", claimToClaimKey(claim), err)
return fmt.Errorf("error finding PV for claim %q: %w", claimToClaimKey(claim), err)
}
if volume == nil {
klog.V(4).Infof("synchronizing unbound PersistentVolumeClaim[%s]: no volume found", claimToClaimKey(claim))
Expand Down Expand Up @@ -410,7 +410,7 @@ func (ctrl *PersistentVolumeController) syncUnboundClaim(claim *v1.PersistentVol
} else {
volume, ok := obj.(*v1.PersistentVolume)
if !ok {
return fmt.Errorf("Cannot convert object from volume cache to volume %q!?: %+v", claim.Spec.VolumeName, obj)
return fmt.Errorf("cannot convert object from volume cache to volume %q!?: %+v", claim.Spec.VolumeName, obj)
}
klog.V(4).Infof("synchronizing unbound PersistentVolumeClaim[%s]: volume %q requested and found: %s", claimToClaimKey(claim), claim.Spec.VolumeName, getVolumeStatusForLogging(volume))
if volume.Spec.ClaimRef == nil {
Expand Down Expand Up @@ -463,7 +463,7 @@ func (ctrl *PersistentVolumeController) syncUnboundClaim(claim *v1.PersistentVol
claimMsg := fmt.Sprintf("volume %q already bound to a different claim.", volume.Name)
ctrl.eventRecorder.Event(claim, v1.EventTypeWarning, events.FailedBinding, claimMsg)

return fmt.Errorf("Invalid binding of claim %q to volume %q: volume already claimed by %q", claimToClaimKey(claim), claim.Spec.VolumeName, claimrefToClaimKey(volume.Spec.ClaimRef))
return fmt.Errorf("invalid binding of claim %q to volume %q: volume already claimed by %q", claimToClaimKey(claim), claim.Spec.VolumeName, claimrefToClaimKey(volume.Spec.ClaimRef))
}
}
}
Expand Down Expand Up @@ -497,7 +497,7 @@ func (ctrl *PersistentVolumeController) syncBoundClaim(claim *v1.PersistentVolum
} else {
volume, ok := obj.(*v1.PersistentVolume)
if !ok {
return fmt.Errorf("Cannot convert object from volume cache to volume %q!?: %#v", claim.Spec.VolumeName, obj)
return fmt.Errorf("cannot convert object from volume cache to volume %q!?: %#v", claim.Spec.VolumeName, obj)
}

klog.V(4).Infof("synchronizing bound PersistentVolumeClaim[%s]: volume %q found: %s", claimToClaimKey(claim), claim.Spec.VolumeName, getVolumeStatusForLogging(volume))
Expand Down Expand Up @@ -615,7 +615,7 @@ func (ctrl *PersistentVolumeController) syncVolume(volume *v1.PersistentVolume)
var ok bool
claim, ok = obj.(*v1.PersistentVolumeClaim)
if !ok {
return fmt.Errorf("Cannot convert object from volume cache to volume %q!?: %#v", claim.Spec.VolumeName, obj)
return fmt.Errorf("cannot convert object from volume cache to volume %q!?: %#v", claim.Spec.VolumeName, obj)
}
klog.V(4).Infof("synchronizing PersistentVolume[%s]: claim %s found: %s", volume.Name, claimrefToClaimKey(volume.Spec.ClaimRef), getClaimStatusForLogging(claim))
}
Expand Down Expand Up @@ -1323,7 +1323,7 @@ func (ctrl *PersistentVolumeController) isVolumeReleased(volume *v1.PersistentVo
var ok bool
claim, ok = obj.(*v1.PersistentVolumeClaim)
if !ok {
return false, fmt.Errorf("Cannot convert object from claim cache to claim!?: %#v", obj)
return false, fmt.Errorf("cannot convert object from claim cache to claim!?: %#v", obj)
}
}
if claim != nil && claim.UID == volume.Spec.ClaimRef.UID {
Expand Down Expand Up @@ -1422,7 +1422,7 @@ func (ctrl *PersistentVolumeController) doDeleteVolume(volume *v1.PersistentVolu
deleter, err := plugin.NewDeleter(spec)
if err != nil {
// Cannot create deleter
return pluginName, false, fmt.Errorf("Failed to create deleter for volume %q: %v", volume.Name, err)
return pluginName, false, fmt.Errorf("failed to create deleter for volume %q: %w", volume.Name, err)
}

opComplete := util.OperationCompleteHook(pluginName, "volume_delete")
Expand Down Expand Up @@ -1832,7 +1832,7 @@ func (ctrl *PersistentVolumeController) findDeletablePlugin(volume *v1.Persisten
plugin, err := ctrl.volumePluginMgr.FindDeletablePluginBySpec(spec)
if err != nil {
// No deleter found. Emit an event and mark the volume Failed.
return nil, fmt.Errorf("Error getting deleter volume plugin for volume %q: %v", volume.Name, err)
return nil, fmt.Errorf("error getting deleter volume plugin for volume %q: %w", volume.Name, err)
}
return plugin, nil
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/controller/volume/persistentvolume/pv_controller_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func NewController(p ControllerParameters) (*PersistentVolumeController, error)

// Prober is nil because PV is not aware of Flexvolume.
if err := controller.volumePluginMgr.InitPlugins(p.VolumePlugins, nil /* prober */, controller); err != nil {
return nil, fmt.Errorf("Could not initialize volume plugins for PersistentVolume Controller: %v", err)
return nil, fmt.Errorf("could not initialize volume plugins for PersistentVolume Controller: %w", err)
}

p.VolumeInformer.Informer().AddEventHandler(
Expand Down Expand Up @@ -138,7 +138,7 @@ func NewController(p ControllerParameters) (*PersistentVolumeController, error)
// This custom indexer will index pods by its PVC keys. Then we don't need
// to iterate all pods every time to find pods which reference given PVC.
if err := common.AddPodPVCIndexerIfNotPresent(controller.podIndexer); err != nil {
return nil, fmt.Errorf("Could not initialize attach detach controller: %v", err)
return nil, fmt.Errorf("could not initialize attach detach controller: %w", err)
}

csiTranslator := csitrans.New()
Expand Down Expand Up @@ -595,11 +595,11 @@ func getVolumeStatusForLogging(volume *v1.PersistentVolume) string {
func storeObjectUpdate(store cache.Store, obj interface{}, className string) (bool, error) {
objName, err := controller.KeyFunc(obj)
if err != nil {
return false, fmt.Errorf("Couldn't get key for object %+v: %v", obj, err)
return false, fmt.Errorf("couldn't get key for object %+v: %w", obj, err)
}
oldObj, found, err := store.Get(obj)
if err != nil {
return false, fmt.Errorf("Error finding %s %q in controller cache: %v", className, objName, err)
return false, fmt.Errorf("error finding %s %q in controller cache: %w", className, objName, err)
}

objAccessor, err := meta.Accessor(obj)
Expand All @@ -611,7 +611,7 @@ func storeObjectUpdate(store cache.Store, obj interface{}, className string) (bo
// This is a new object
klog.V(4).Infof("storeObjectUpdate: adding %s %q, version %s", className, objName, objAccessor.GetResourceVersion())
if err = store.Add(obj); err != nil {
return false, fmt.Errorf("Error adding %s %q to controller cache: %v", className, objName, err)
return false, fmt.Errorf("error adding %s %q to controller cache: %w", className, objName, err)
}
return true, nil
}
Expand All @@ -623,11 +623,11 @@ func storeObjectUpdate(store cache.Store, obj interface{}, className string) (bo

objResourceVersion, err := strconv.ParseInt(objAccessor.GetResourceVersion(), 10, 64)
if err != nil {
return false, fmt.Errorf("Error parsing ResourceVersion %q of %s %q: %s", objAccessor.GetResourceVersion(), className, objName, err)
return false, fmt.Errorf("error parsing ResourceVersion %q of %s %q: %s", objAccessor.GetResourceVersion(), className, objName, err)
}
oldObjResourceVersion, err := strconv.ParseInt(oldObjAccessor.GetResourceVersion(), 10, 64)
if err != nil {
return false, fmt.Errorf("Error parsing old ResourceVersion %q of %s %q: %s", oldObjAccessor.GetResourceVersion(), className, objName, err)
return false, fmt.Errorf("error parsing old ResourceVersion %q of %s %q: %s", oldObjAccessor.GetResourceVersion(), className, objName, err)
}

// Throw away only older version, let the same version pass - we do want to
Expand All @@ -639,7 +639,7 @@ func storeObjectUpdate(store cache.Store, obj interface{}, className string) (bo

klog.V(4).Infof("storeObjectUpdate updating %s %q with version %s", className, objName, objAccessor.GetResourceVersion())
if err = store.Update(obj); err != nil {
return false, fmt.Errorf("Error updating %s %q in controller cache: %v", className, objName, err)
return false, fmt.Errorf("error updating %s %q in controller cache: %w", className, objName, err)
}
return true, nil
}
12 changes: 6 additions & 6 deletions pkg/controller/volume/persistentvolume/testing/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (r *VolumeReactor) React(action core.Action) (handled bool, ret runtime.Obj
// check the volume does not exist
_, found := r.volumes[volume.Name]
if found {
return true, nil, fmt.Errorf("Cannot create volume %s: volume already exists", volume.Name)
return true, nil, fmt.Errorf("cannot create volume %s: volume already exists", volume.Name)
}

// mimic apiserver defaulting
Expand All @@ -134,7 +134,7 @@ func (r *VolumeReactor) React(action core.Action) (handled bool, ret runtime.Obj
// check the claim does not exist
_, found := r.claims[claim.Name]
if found {
return true, nil, fmt.Errorf("Cannot create claim %s: claim already exists", claim.Name)
return true, nil, fmt.Errorf("cannot create claim %s: claim already exists", claim.Name)
}

// Store the updated object to appropriate places.
Expand Down Expand Up @@ -167,7 +167,7 @@ func (r *VolumeReactor) React(action core.Action) (handled bool, ret runtime.Obj
volume = volume.DeepCopy()
volume.ResourceVersion = strconv.Itoa(storedVer + 1)
} else {
return true, nil, fmt.Errorf("Cannot update volume %s: volume not found", volume.Name)
return true, nil, fmt.Errorf("cannot update volume %s: volume not found", volume.Name)
}

// Store the updated object to appropriate places.
Expand Down Expand Up @@ -200,7 +200,7 @@ func (r *VolumeReactor) React(action core.Action) (handled bool, ret runtime.Obj
claim = claim.DeepCopy()
claim.ResourceVersion = strconv.Itoa(storedVer + 1)
} else {
return true, nil, fmt.Errorf("Cannot update claim %s: claim not found", claim.Name)
return true, nil, fmt.Errorf("cannot update claim %s: claim not found", claim.Name)
}

// Store the updated object to appropriate places.
Expand Down Expand Up @@ -245,7 +245,7 @@ func (r *VolumeReactor) React(action core.Action) (handled bool, ret runtime.Obj
r.changedSinceLastSync++
return true, nil, nil
}
return true, nil, fmt.Errorf("Cannot delete volume %s: not found", name)
return true, nil, fmt.Errorf("cannot delete volume %s: not found", name)

case action.Matches("delete", "persistentvolumeclaims"):
name := action.(core.DeleteAction).GetName()
Expand All @@ -259,7 +259,7 @@ func (r *VolumeReactor) React(action core.Action) (handled bool, ret runtime.Obj
r.changedSinceLastSync++
return true, nil, nil
}
return true, nil, fmt.Errorf("Cannot delete claim %s: not found", name)
return true, nil, fmt.Errorf("cannot delete claim %s: not found", name)
}

return false, nil, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/volume/persistentvolume/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func GetBindVolumeToClaim(volume *v1.PersistentVolume, claim *v1.PersistentVolum

claimRef, err := reference.GetReference(scheme.Scheme, claim)
if err != nil {
return nil, false, fmt.Errorf("Unexpected error getting claim reference: %v", err)
return nil, false, fmt.Errorf("unexpected error getting claim reference: %w", err)
}
volumeClone.Spec.ClaimRef = claimRef
dirty = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func NewPVCProtectionController(pvcInformer coreinformers.PersistentVolumeClaimI
e.podListerSynced = podInformer.Informer().HasSynced
e.podIndexer = podInformer.Informer().GetIndexer()
if err := common.AddIndexerIfNotPresent(e.podIndexer, common.PodPVCIndex, common.PodPVCIndexFunc(genericEphemeralVolumeFeatureEnabled)); err != nil {
return nil, fmt.Errorf("Could not initialize pvc protection controller: %v", err)
return nil, fmt.Errorf("could not initialize pvc protection controller: %w", err)
}
podInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
Expand Down