Skip to content

Commit 39ade56

Browse files
committed
Improve error messages returned with pending & failing requests
Signed-off-by: James Munnelly <[email protected]>
1 parent adc6166 commit 39ade56

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

manager/manager.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ func (m *Manager) issue(ctx context.Context, volumeID string) error {
339339

340340
// Poll every 1s for the CertificateRequest to be ready
341341
lastFailureReason := ""
342-
if err := wait.PollUntil(time.Second, func() (done bool, err error) {
342+
if err := wait.PollUntilWithContext(ctx, time.Second, func(ctx context.Context) (done bool, err error) {
343343
updatedReq, err := m.lister.CertificateRequests(req.Namespace).Get(req.Name)
344344
if apierrors.IsNotFound(err) {
345345
// A NotFound error implies something deleted the resource - fail
@@ -363,8 +363,9 @@ func (m *Manager) issue(ctx context.Context, volumeID string) error {
363363
return false, fmt.Errorf("request %q has been denied by the approval plugin: %s", updatedReq.Name, cond.Message)
364364
}
365365

366-
if !apiutil.CertificateRequestIsApproved(updatedReq) {
367-
lastFailureReason = "request has not yet been approved by approval plugin"
366+
isApproved := apiutil.CertificateRequestIsApproved(updatedReq)
367+
if !isApproved {
368+
lastFailureReason = fmt.Sprintf("request %q has not yet been approved by approval plugin", updatedReq.Name)
368369
// we don't stop execution here, as some versions of cert-manager (and some external issuer plugins)
369370
// may not be aware/utilise approval.
370371
// If the certificate is still issued despite never being approved, the CSI driver should continue
@@ -373,11 +374,11 @@ func (m *Manager) issue(ctx context.Context, volumeID string) error {
373374

374375
readyCondition := apiutil.GetCertificateRequestCondition(updatedReq, cmapi.CertificateRequestConditionReady)
375376
if readyCondition == nil {
376-
if apiutil.CertificateRequestIsApproved(updatedReq) {
377-
lastFailureReason = "request has no ready condition"
377+
// only overwrite the approval failure message if the request is actually approved
378+
// otherwise we may hide more useful information from the user by accident.
379+
if isApproved {
380+
lastFailureReason = fmt.Sprintf("request %q has no ready condition", updatedReq.Name)
378381
}
379-
log.V(2).Info("CertificateRequest is still pending")
380-
// Issuance is still pending
381382
return false, nil
382383
}
383384

@@ -387,11 +388,12 @@ func (m *Manager) issue(ctx context.Context, volumeID string) error {
387388
case cmapi.CertificateRequestReasonFailed:
388389
return false, fmt.Errorf("request %q has failed: %s", updatedReq.Name, readyCondition.Message)
389390
case cmapi.CertificateRequestReasonPending:
390-
lastFailureReason = fmt.Sprintf("request pending: %v", readyCondition.Message)
391-
log.V(2).Info("CertificateRequest is still pending")
391+
if isApproved {
392+
lastFailureReason = fmt.Sprintf("request %q is pending: %v", updatedReq.Name, readyCondition.Message)
393+
}
392394
return false, nil
393395
default:
394-
lastFailureReason = fmt.Sprintf("unrecognised Ready condition state (%s): %s", readyCondition.Reason, readyCondition.Message)
396+
lastFailureReason = fmt.Sprintf("request %q has unrecognised Ready condition state (%s): %s", updatedReq.Name, readyCondition.Reason, readyCondition.Message)
395397
log.Info("unrecognised state for Ready condition", "request_namespace", updatedReq.Namespace, "request_name", updatedReq.Name, "condition", *readyCondition)
396398
return false, nil
397399
}
@@ -401,7 +403,7 @@ func (m *Manager) issue(ctx context.Context, volumeID string) error {
401403
// writing out signed certificate
402404
req = updatedReq
403405
return true, nil
404-
}, ctx.Done()); err != nil {
406+
}); err != nil {
405407
if errors.Is(err, wait.ErrWaitTimeout) {
406408
// try and return a more helpful error message than "timed out waiting for the condition"
407409
return fmt.Errorf("waiting for request: %s", lastFailureReason)

0 commit comments

Comments
 (0)