Skip to content

Commit 5e102b7

Browse files
committed
address review comments
Signed-off-by: Ashima-Ashima1 <[email protected]>
1 parent 2f2bb53 commit 5e102b7

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

controllers/recoverstalevolume_controller.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"context"
2323
"io"
2424
"strings"
25+
"time"
2526

2627
objectdriverv1alpha1 "github.com/IBM/ibm-object-csi-driver-operator/api/v1alpha1"
2728
"github.com/IBM/ibm-object-csi-driver-operator/controllers/constants"
@@ -143,7 +144,7 @@ func (r *RecoverStaleVolumeReconciler) Reconcile(ctx context.Context, req ctrl.R
143144

144145
if len(csiApplications) == 0 {
145146
reqLogger.Info("No Deployment found in requested namespace")
146-
return ctrl.Result{RequeueAfter: constants.ReconcilationTime}, nil
147+
continue
147148
}
148149

149150
var csiNodeServerPods = map[string]string{} // {nodeName1: csiNodePod1, nodeName2: csiNodePod2, ...}
@@ -229,7 +230,7 @@ func (r *RecoverStaleVolumeReconciler) Reconcile(ctx context.Context, req ctrl.R
229230

230231
// If CSI Driver Node Pods not found, reconcile
231232
if len(csiNodeServerPods) == 0 {
232-
return ctrl.Result{RequeueAfter: constants.ReconcilationTime}, nil
233+
continue
233234
}
234235

235236
for nodeName, volumesData := range nodeVolumePodMapping {
@@ -281,6 +282,8 @@ func (r *RecoverStaleVolumeReconciler) SetupWithManager(mgr ctrl.Manager) error
281282
}
282283

283284
func fetchCSIPVCAndPVNames(k8sOps *crutils.K8sResourceOps, log logr.Logger) (map[string]string, error) {
285+
defer LogFunctionDuration(log, "fetchCSIPVCAndPVNames", time.Now())
286+
284287
pvcList, err := k8sOps.ListPVC()
285288
if err != nil {
286289
log.Error(err, "failed to get pvc list")
@@ -314,6 +317,8 @@ func fetchCSIPVCAndPVNames(k8sOps *crutils.K8sResourceOps, log logr.Logger) (map
314317

315318
func fetchDeploymentsUsingCSIVolumes(k8sOps *crutils.K8sResourceOps, log logr.Logger, depNames []string,
316319
reqPVCNames []string) ([]string, error) {
320+
defer LogFunctionDuration(log, "fetchDeploymentsUsingCSIVolumes", time.Now())
321+
317322
var reqDeploymentNames []string
318323

319324
for _, name := range depNames {
@@ -361,6 +366,8 @@ func createK8sClient() (*KubernetesClient, error) {
361366

362367
func fetchVolumeStatsFromNodeServerPodLogs(ctx context.Context, nodeServerPod, namespace string, logTailLines int64,
363368
isTest bool) (map[string]string, error) {
369+
defer LogFunctionDuration(staleVolLog, "fetchVolumeStatsFromNodeServerPodLogs", time.Now())
370+
364371
staleVolLog.Info("Input Parameters: ", "nodeServerPod", nodeServerPod, "namespace", namespace, "isTest", isTest)
365372
podLogOpts := &corev1.PodLogOptions{
366373
Container: constants.NodeContainerName,
@@ -392,3 +399,9 @@ func fetchVolumeStatsFromNodeServerPodLogs(ctx context.Context, nodeServerPod, n
392399

393400
return parseLogs(nodeServerPodLogs), nil
394401
}
402+
403+
// LogFunctionDuration calculates time taken by a method
404+
func LogFunctionDuration(logger logr.Logger, methodName string, start time.Time) {
405+
duration := time.Since(start)
406+
logger.Info("Time to complete", methodName, duration.Seconds())
407+
}

0 commit comments

Comments
 (0)