mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-11-23 12:29:01 +00:00
volume: use contextual logging
This commit is contained in:
@@ -219,20 +219,21 @@ func (expc *expandController) syncHandler(ctx context.Context, key string) error
|
||||
if errors.IsNotFound(err) {
|
||||
return nil
|
||||
}
|
||||
logger := klog.FromContext(ctx)
|
||||
if err != nil {
|
||||
klog.V(5).Infof("Error getting PVC %q from informer : %v", key, err)
|
||||
logger.V(5).Info("Error getting PVC from informer", "pvcKey", key, "err", err)
|
||||
return err
|
||||
}
|
||||
|
||||
pv, err := expc.getPersistentVolume(ctx, pvc)
|
||||
if err != nil {
|
||||
klog.V(5).Infof("Error getting Persistent Volume for PVC %q (uid: %q) from informer : %v", key, pvc.UID, err)
|
||||
logger.V(5).Info("Error getting Persistent Volume for PVC from informer", "pvcKey", key, "pvcUID", pvc.UID, "err", err)
|
||||
return err
|
||||
}
|
||||
|
||||
if pv.Spec.ClaimRef == nil || pvc.Namespace != pv.Spec.ClaimRef.Namespace || pvc.UID != pv.Spec.ClaimRef.UID {
|
||||
err := fmt.Errorf("persistent Volume is not bound to PVC being updated : %s", key)
|
||||
klog.V(4).Infof("%v", err)
|
||||
logger.V(4).Info("", "err", err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -249,14 +250,14 @@ func (expc *expandController) syncHandler(ctx context.Context, key string) error
|
||||
volumeSpec := volume.NewSpecFromPersistentVolume(pv, false)
|
||||
migratable, err := expc.csiMigratedPluginManager.IsMigratable(volumeSpec)
|
||||
if err != nil {
|
||||
klog.V(4).Infof("failed to check CSI migration status for PVC: %s with error: %v", key, err)
|
||||
logger.V(4).Info("Failed to check CSI migration status for PVC with error", "pvcKey", key, "err", err)
|
||||
return nil
|
||||
}
|
||||
// handle CSI migration scenarios before invoking FindExpandablePluginBySpec for in-tree
|
||||
if migratable {
|
||||
inTreePluginName, err := expc.csiMigratedPluginManager.GetInTreePluginNameFromSpec(volumeSpec.PersistentVolume, volumeSpec.Volume)
|
||||
if err != nil {
|
||||
klog.V(4).Infof("Error getting in-tree plugin name from persistent volume %s: %v", volumeSpec.PersistentVolume.Name, err)
|
||||
logger.V(4).Info("Error getting in-tree plugin name from persistent volume", "volumeName", volumeSpec.PersistentVolume.Name, "err", err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -286,46 +287,45 @@ func (expc *expandController) syncHandler(ctx context.Context, key string) error
|
||||
eventType = v1.EventTypeWarning
|
||||
}
|
||||
expc.recorder.Event(pvc, eventType, events.ExternalExpanding, msg)
|
||||
klog.Infof("waiting for an external controller to expand the PVC %q (uid: %q)", key, pvc.UID)
|
||||
logger.Info("Waiting for an external controller to expand the PVC", "pvcKey", key, "pvcUID", pvc.UID)
|
||||
// If we are expecting that an external plugin will handle resizing this volume then
|
||||
// is no point in requeuing this PVC.
|
||||
return nil
|
||||
}
|
||||
|
||||
volumeResizerName := volumePlugin.GetPluginName()
|
||||
return expc.expand(pvc, pv, volumeResizerName)
|
||||
return expc.expand(logger, pvc, pv, volumeResizerName)
|
||||
}
|
||||
|
||||
func (expc *expandController) expand(pvc *v1.PersistentVolumeClaim, pv *v1.PersistentVolume, resizerName string) error {
|
||||
func (expc *expandController) expand(logger klog.Logger, pvc *v1.PersistentVolumeClaim, pv *v1.PersistentVolume, resizerName string) error {
|
||||
// if node expand is complete and pv's annotation can be removed, remove the annotation from pv and return
|
||||
if expc.isNodeExpandComplete(pvc, pv) && metav1.HasAnnotation(pv.ObjectMeta, util.AnnPreResizeCapacity) {
|
||||
if expc.isNodeExpandComplete(logger, pvc, pv) && metav1.HasAnnotation(pv.ObjectMeta, util.AnnPreResizeCapacity) {
|
||||
return util.DeleteAnnPreResizeCapacity(pv, expc.GetKubeClient())
|
||||
}
|
||||
|
||||
var generatedOptions volumetypes.GeneratedOperations
|
||||
var err error
|
||||
|
||||
if utilfeature.DefaultFeatureGate.Enabled(features.RecoverVolumeExpansionFailure) {
|
||||
generatedOptions, err = expc.operationGenerator.GenerateExpandAndRecoverVolumeFunc(pvc, pv, resizerName)
|
||||
if err != nil {
|
||||
klog.Errorf("Error starting ExpandVolume for pvc %s with %v", util.GetPersistentVolumeClaimQualifiedName(pvc), err)
|
||||
logger.Error(err, "Error starting ExpandVolume for pvc", "PVC", klog.KObj(pvc))
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
pvc, err := util.MarkResizeInProgressWithResizer(pvc, resizerName, expc.kubeClient)
|
||||
if err != nil {
|
||||
klog.Errorf("Error setting PVC %s in progress with error : %v", util.GetPersistentVolumeClaimQualifiedName(pvc), err)
|
||||
logger.Error(err, "Error setting PVC in progress with error", "PVC", klog.KObj(pvc), "err", err)
|
||||
return err
|
||||
}
|
||||
|
||||
generatedOptions, err = expc.operationGenerator.GenerateExpandVolumeFunc(pvc, pv)
|
||||
if err != nil {
|
||||
klog.Errorf("Error starting ExpandVolume for pvc %s with %v", util.GetPersistentVolumeClaimQualifiedName(pvc), err)
|
||||
logger.Error(err, "Error starting ExpandVolume for pvc with error", "PVC", klog.KObj(pvc), "err", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
klog.V(5).Infof("Starting ExpandVolume for volume %s", util.GetPersistentVolumeClaimQualifiedName(pvc))
|
||||
logger.V(5).Info("Starting ExpandVolume for volume", "volumeName", util.GetPersistentVolumeClaimQualifiedName(pvc))
|
||||
_, detailedErr := generatedOptions.Run()
|
||||
|
||||
return detailedErr
|
||||
@@ -335,9 +335,9 @@ func (expc *expandController) expand(pvc *v1.PersistentVolumeClaim, pv *v1.Persi
|
||||
func (expc *expandController) Run(ctx context.Context) {
|
||||
defer runtime.HandleCrash()
|
||||
defer expc.queue.ShutDown()
|
||||
|
||||
klog.Infof("Starting expand controller")
|
||||
defer klog.Infof("Shutting down expand controller")
|
||||
logger := klog.FromContext(ctx)
|
||||
logger.Info("Starting expand controller")
|
||||
defer logger.Info("Shutting down expand controller")
|
||||
|
||||
if !cache.WaitForNamedCacheSync("expand", ctx.Done(), expc.pvcsSynced, expc.pvSynced) {
|
||||
return
|
||||
@@ -367,8 +367,8 @@ func (expc *expandController) getPersistentVolume(ctx context.Context, pvc *v1.P
|
||||
}
|
||||
|
||||
// isNodeExpandComplete returns true if pvc.Status.Capacity >= pv.Spec.Capacity
|
||||
func (expc *expandController) isNodeExpandComplete(pvc *v1.PersistentVolumeClaim, pv *v1.PersistentVolume) bool {
|
||||
klog.V(4).Infof("pv %q capacity = %v, pvc %s capacity = %v", pv.Name, pv.Spec.Capacity[v1.ResourceStorage], pvc.ObjectMeta.Name, pvc.Status.Capacity[v1.ResourceStorage])
|
||||
func (expc *expandController) isNodeExpandComplete(logger klog.Logger, pvc *v1.PersistentVolumeClaim, pv *v1.PersistentVolume) bool {
|
||||
logger.V(4).Info("pv and pvc capacity", "PV", klog.KObj(pv), "pvCapacity", pv.Spec.Capacity[v1.ResourceStorage], "PVC", klog.KObj(pvc), "pvcCapacity", pvc.Status.Capacity[v1.ResourceStorage])
|
||||
pvcSpecCap := pvc.Spec.Resources.Requests.Storage()
|
||||
pvcStatusCap, pvCap := pvc.Status.Capacity[v1.ResourceStorage], pv.Spec.Capacity[v1.ResourceStorage]
|
||||
|
||||
@@ -469,7 +469,7 @@ func (expc *expandController) GetServiceAccountTokenFunc() func(_, _ string, _ *
|
||||
|
||||
func (expc *expandController) DeleteServiceAccountTokenFunc() func(types.UID) {
|
||||
return func(types.UID) {
|
||||
klog.Errorf("DeleteServiceAccountToken unsupported in expandController")
|
||||
klog.ErrorS(nil, "DeleteServiceAccountToken unsupported in expandController")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user