Skip to content

Commit

Permalink
code review changes (5)
Browse files Browse the repository at this point in the history
move minutesSinceCreation to func defaultBSCreationTimedout and edit message

Signed-off-by: shirady <[email protected]>
  • Loading branch information
shirady committed Oct 15, 2023
1 parent d6e26d8 commit 023ccfb
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions pkg/system/phase4_configuring.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 023ccfb

Please sign in to comment.