Skip to content

Commit

Permalink
Merge pull request #562 from bentito/OCPBUGS-16036
Browse files Browse the repository at this point in the history
OCPBUGS-16036: Set status on CR properly when STS provisioned
  • Loading branch information
openshift-merge-robot committed Jul 13, 2023
2 parents 51f9ae9 + 4f25b93 commit fbfc7a5
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions pkg/operator/credentialsrequest/credentialsrequest_controller.go
Expand Up @@ -19,6 +19,8 @@ package credentialsrequest
import (
"context"
"fmt"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/util/retry"
"reflect"
"time"

Expand Down Expand Up @@ -702,7 +704,10 @@ func (r *ReconcileCredentialsRequest) Reconcile(ctx context.Context, request rec
provisionErr = true
}

cr.Status.Provisioned = !provisionErr
updateErr := r.UpdateProvisionedStatus(cr, !provisionErr)
if updateErr != nil {
logger.Errorf("failed to update credentialsrequest status: %v", updateErr)
}

logger.Errorf("errored with condition: %v", t.Reason())
r.updateActuatorConditions(cr, t.Reason(), syncErr)
Expand All @@ -714,7 +719,11 @@ func (r *ReconcileCredentialsRequest) Reconcile(ctx context.Context, request rec
} else {
// it worked so clear any actuator conditions if they exist
r.updateActuatorConditions(cr, "", nil)
cr.Status.Provisioned = true
updateErr := r.UpdateProvisionedStatus(cr, true)

if updateErr != nil {
logger.Errorf("failed to update credentialsrequest status: %v", updateErr)
}
}
} else {
credentialsRootSecret, err := r.Actuator.GetCredentialsRootSecret(ctx, cr)
Expand Down Expand Up @@ -1040,3 +1049,28 @@ func checkForFailureConditions(cr *minterv1.CredentialsRequest) bool {
}
return false
}

// UpdateProvisionedStatus will update the status subresource of this CredentialsRequest
func (r *ReconcileCredentialsRequest) UpdateProvisionedStatus(cr *minterv1.CredentialsRequest, provisioned bool) error {
// Check if the status subresource is already set
if cr.Status.LastSyncTimestamp == nil {
// Create a new status object and set its fields
cr.Status = minterv1.CredentialsRequestStatus{
LastSyncTimestamp: &metav1.Time{Time: time.Now()},
Provisioned: provisioned,
ProviderStatus: &runtime.RawExtension{},
}
} else {
// Update the Provisioned field with the given parameter
cr.Status.Provisioned = provisioned
}

// Use retry.RetryOnConflict() to update the status subresource
err := retry.RetryOnConflict(retry.DefaultBackoff, func() error {
return r.Client.Status().Update(context.Background(), cr)
})
if err != nil {
return err
}
return nil
}

0 comments on commit fbfc7a5

Please sign in to comment.