mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-20 18:31:15 +00:00
Merge pull request #101304 from wangyx1992/capatial-log-controller
cleanup: fix errors in wrapped format and log capitalization in controller
This commit is contained in:
commit
fe88bdc1ab
@ -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
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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()
|
||||
@ -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{
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
@ -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,
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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))
|
||||
@ -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 {
|
||||
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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))
|
||||
@ -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))
|
||||
}
|
||||
@ -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 {
|
||||
@ -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")
|
||||
@ -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
|
||||
}
|
||||
|
@ -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(
|
||||
@ -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()
|
||||
@ -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)
|
||||
@ -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
|
||||
}
|
||||
@ -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
|
||||
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
@ -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.
|
||||
@ -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.
|
||||
@ -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.
|
||||
@ -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()
|
||||
@ -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
|
||||
|
@ -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
|
||||
|
@ -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{}) {
|
||||
|
Loading…
Reference in New Issue
Block a user