Skip to content

Commit 4441d3f

Browse files
authored
Merge pull request #222 from Abrahami2/feat/add-logging
refactor(controller): add detailed logs for debuggability
2 parents 1b6e8f4 + 8355999 commit 4441d3f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

populator-machinery/controller.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,7 @@ func (c *controller) syncPvc(ctx context.Context, key, pvcNamespace, pvcName str
664664
if !errors.IsNotFound(err) {
665665
return err
666666
}
667+
klog.Warningf("Data source %s/%s for PVC %s/%s not found, will retry", dataSourceRefNamespace, dataSourceRef.Name, pvc.Namespace, pvc.Name)
667668
c.recorder.Eventf(pvc, corev1.EventTypeWarning, reasonDataSourceNotFound, "Data source %s/%s not found", dataSourceRefNamespace, dataSourceRef.Name)
668669
c.addNotification(key, "unstructured", pvc.Namespace, dataSourceRef.Name)
669670
// We'll get called again later when the data source exists
@@ -687,14 +688,15 @@ func (c *controller) syncPvc(ctx context.Context, key, pvcNamespace, pvcName str
687688
}
688689

689690
if err := c.checkIntreeStorageClass(pvc, storageClass); err != nil {
690-
klog.V(2).Infof("Ignoring PVC %s/%s: %s", pvcNamespace, pvcName, err)
691+
klog.V(4).Infof("Ignoring PVC %s/%s: %s", pvcNamespace, pvcName, err)
691692
return nil
692693
}
693694

694695
if storageClass.VolumeBindingMode != nil && storagev1.VolumeBindingWaitForFirstConsumer == *storageClass.VolumeBindingMode {
695696
waitForFirstConsumer = true
696697
nodeName = pvc.Annotations[annSelectedNode]
697698
if nodeName == "" {
699+
klog.V(4).Infof("Waiting for node selection due to WaitForFirstConsumer mode for PVC %s/%s", pvc.Namespace, pvc.Name)
698700
// Wait for the PVC to get a node name before continuing
699701
return nil
700702
}
@@ -780,6 +782,7 @@ func (c *controller) syncPvc(ctx context.Context, key, pvcNamespace, pvcName str
780782
return err
781783
}
782784
params.PvcPrime = pvcPrime
785+
klog.V(4).Infof("Created pvcPrime %s/%s for data population of PVC %s/%s", pvcPrime.Namespace, pvcPrime.Name, pvc.Namespace, pvc.Name)
783786
}
784787

785788
if "" == pvc.Spec.VolumeName {
@@ -817,6 +820,7 @@ func (c *controller) syncPvc(ctx context.Context, key, pvcNamespace, pvcName str
817820
return err
818821
}
819822
if !complete {
823+
klog.V(4).Infof("Data population for PVC %s/%s is not yet complete. Requeuing to check again later.", pvc.Namespace, pvc.Name)
820824
// TODO: Revisited if there is a better way to requeue pvc than return an error
821825
// Return error to force reque pvc. We'll get called again later when the population operation complete
822826
return fmt.Errorf(reasonWaitForDataPopulationFinished)
@@ -880,19 +884,22 @@ func (c *controller) syncPvc(ctx context.Context, key, pvcNamespace, pvcName str
880884
return err
881885
}
882886
c.recorder.Eventf(pvc, corev1.EventTypeNormal, reasonPodCreationSuccess, "Populator started")
887+
klog.V(4).Infof("Created populator pod %s/%s for PVC %s/%s", pod.Namespace, pod.Name, pvc.Namespace, pvc.Name)
883888

884889
// We'll get called again later when the pod exists
885890
return nil
886891
}
887892

888893
if corev1.PodSucceeded != pod.Status.Phase {
889894
if corev1.PodFailed == pod.Status.Phase {
895+
klog.Warningf("Populator pod %s/%s failed with message: %s", pod.Namespace, pod.Name, pod.Status.Message)
890896
c.recorder.Eventf(pvc, corev1.EventTypeWarning, reasonPodFailed, "Populator failed: %s", pod.Status.Message)
891897
// Delete failed pods so we can try again
892898
err = c.kubeClient.CoreV1().Pods(c.populatorNamespace).Delete(ctx, pod.Name, metav1.DeleteOptions{})
893899
if err != nil {
894900
return err
895901
}
902+
klog.V(4).Infof("Cleaned up temporary populator pod %s/%s for PVC %s/%s", pod.Namespace, pod.Name, pvc.Namespace, pvc.Name)
896903
}
897904
// We'll get called again later when the pod succeeds
898905
return nil
@@ -945,6 +952,7 @@ func (c *controller) syncPvc(ctx context.Context, key, pvcNamespace, pvcName str
945952
if err != nil {
946953
return err
947954
}
955+
klog.V(4).Infof("Successfully rebound PV %s to target PVC %s/%s", pv.Name, pvc.Namespace, pvc.Name)
948956

949957
// Don't start cleaning up yet -- we need to bind controller to acknowledge
950958
// the switch
@@ -998,6 +1006,7 @@ func (c *controller) syncPvc(ctx context.Context, key, pvcNamespace, pvcName str
9981006
if err != nil {
9991007
return err
10001008
}
1009+
klog.V(4).Infof("Cleaned up temporary populator resources for PVC %s/%s", pvc.Namespace, pvc.Name)
10011010

10021011
// Clean up our internal callback maps
10031012
c.cleanupNotifications(key)

0 commit comments

Comments
 (0)