From 023ccfbfa5fb436b313d51dbae8f1ed5a4ebd47c Mon Sep 17 00:00:00 2001 From: shirady <57721533+shirady@users.noreply.github.com> Date: Sun, 15 Oct 2023 11:53:07 +0300 Subject: [PATCH] code review changes (5) move minutesSinceCreation to func defaultBSCreationTimedout and edit message Signed-off-by: shirady <57721533+shirady@users.noreply.github.com> --- pkg/system/phase4_configuring.go | 38 ++++++++++++++------------------ 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/pkg/system/phase4_configuring.go b/pkg/system/phase4_configuring.go index 2d836fc786..99b7037358 100644 --- a/pkg/system/phase4_configuring.go +++ b/pkg/system/phase4_configuring.go @@ -763,7 +763,8 @@ func (r *Reconciler) preparePVPoolBackingStore() error { return nil } -func (r *Reconciler) defaultBSCreationTimedout(minutesSinceCreation float64) bool { +func (r *Reconciler) defaultBSCreationTimedout(timestampCreation time.Time) bool { + minutesSinceCreation := time.Since(timestampCreation).Minutes() minutesToWait := 10 // this number was chosen arbitrarily return minutesSinceCreation > float64(minutesToWait) } @@ -793,10 +794,9 @@ func (r *Reconciler) prepareAWSBackingStore() error { r.Logger.Infof("Secret %q was not created yet by cloud-credentials operator. retry on next reconcile..", r.AWSCloudCreds.Spec.SecretRef.Name) // in case we have a cred request but we do not get a secret - minutesSinceCreation := time.Since(r.AWSCloudCreds.CreationTimestamp.Time).Minutes() - if r.defaultBSCreationTimedout(minutesSinceCreation) { - message := fmt.Sprintf("Failed to get Secret %q in %d minutes, fallback to create PV Pool backingstore", - r.AWSCloudCreds.Spec.SecretRef.Name, int(minutesSinceCreation)) + if r.defaultBSCreationTimedout(r.AWSCloudCreds.CreationTimestamp.Time) { + message := fmt.Sprintf("Failed to get Secret %q, fallback to create PV Pool backingstore", + r.AWSCloudCreds.Spec.SecretRef.Name) return r.fallbackToPVpoolWithEvent(message) } return fmt.Errorf("cloud credentials secret %q is not ready yet", r.AWSCloudCreds.Spec.SecretRef.Name) @@ -849,10 +849,9 @@ func (r *Reconciler) prepareAzureBackingStore() error { r.Logger.Infof("Secret %q was not created yet by cloud-credentials operator. retry on next reconcile..", r.AzureCloudCreds.Spec.SecretRef.Name) // in case we have a cred request but we do not get a secret - minutesSinceCreation := time.Since(r.AzureCloudCreds.CreationTimestamp.Time).Minutes() - if r.defaultBSCreationTimedout(minutesSinceCreation) { - message := fmt.Sprintf("Failed to get Secret %q in %d minutes, fallback to create PV Pool backingstore", - r.AzureCloudCreds.Spec.SecretRef.Name, int(minutesSinceCreation)) + if r.defaultBSCreationTimedout(r.AzureCloudCreds.CreationTimestamp.Time) { + message := fmt.Sprintf("Failed to get Secret %q, fallback to create PV Pool backingstore", + r.AzureCloudCreds.Spec.SecretRef.Name) return r.fallbackToPVpoolWithEvent(message) } return fmt.Errorf("cloud credentials secret %q is not ready yet", r.AzureCloudCreds.Spec.SecretRef.Name) @@ -932,10 +931,9 @@ func (r *Reconciler) prepareGCPBackingStore() error { r.Logger.Infof("Secret %q was not created yet by cloud-credentials operator. retry on next reconcile..", r.GCPCloudCreds.Spec.SecretRef.Name) // in case we have a cred request but we do not get a secret - minutesSinceCreation := time.Since(r.GCPCloudCreds.CreationTimestamp.Time).Minutes() - if r.defaultBSCreationTimedout(minutesSinceCreation) { - message := fmt.Sprintf("Failed to get Secret %q in %d minutes, fallback to create PV Pool backingstore", - r.GCPCloudCreds.Spec.SecretRef.Name, int(minutesSinceCreation)) + if r.defaultBSCreationTimedout(r.GCPCloudCreds.CreationTimestamp.Time) { + message := fmt.Sprintf("Failed to get Secret %q, fallback to create PV Pool backingstore", + r.GCPCloudCreds.Spec.SecretRef.Name) return r.fallbackToPVpoolWithEvent(message) } return fmt.Errorf("cloud credentials secret %q is not ready yet", r.GCPCloudCreds.Spec.SecretRef.Name) @@ -999,10 +997,9 @@ func (r *Reconciler) prepareIBMBackingStore() error { r.Logger.Errorf("Cloud credentials secret %q is not ready yet", r.IBMCloudCOSCreds.Name) // in case we have a cred request but we do not get a secret - minutesSinceCreation := time.Since(r.IBMCloudCOSCreds.CreationTimestamp.Time).Minutes() - if r.defaultBSCreationTimedout(minutesSinceCreation) { - message := fmt.Sprintf("Failed to get Secret %q in %d minutes, fallback to create PV Pool backingstore", - r.IBMCloudCOSCreds.Name, int(minutesSinceCreation)) + if r.defaultBSCreationTimedout(r.IBMCloudCOSCreds.CreationTimestamp.Time) { + message := fmt.Sprintf("Failed to get Secret %q, fallback to create PV Pool backingstore", + r.IBMCloudCOSCreds.Name) return r.fallbackToPVpoolWithEvent(message) } return fmt.Errorf("Cloud credentials secret %q is not ready yet", r.IBMCloudCOSCreds.Name) @@ -1104,10 +1101,9 @@ func (r *Reconciler) prepareCephBackingStore() error { r.Logger.Infof("Ceph objectstore user %q is not ready. retry on next reconcile..", r.CephObjectStoreUser.Name) // in case it takes too long to have CephObjectStoreUser - minutesSinceCreation := time.Since(r.CephObjectStoreUser.CreationTimestamp.Time).Minutes() - if r.defaultBSCreationTimedout(minutesSinceCreation) { - message := fmt.Sprintf("Failed to get Secret %q in %d minutes, fallback to create PV Pool backingstore", - r.CephObjectStoreUser.Name, int(minutesSinceCreation)) + if r.defaultBSCreationTimedout(r.CephObjectStoreUser.CreationTimestamp.Time) { + message := fmt.Sprintf("Failed to get Secret %q, fallback to create PV Pool backingstore", + r.CephObjectStoreUser.Name) return r.fallbackToPVpoolWithEvent(message) } return fmt.Errorf("Ceph objectstore user %q is not ready", r.CephObjectStoreUser.Name)