@@ -339,7 +339,7 @@ func (m *Manager) issue(ctx context.Context, volumeID string) error {
339
339
340
340
// Poll every 1s for the CertificateRequest to be ready
341
341
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 ) {
343
343
updatedReq , err := m .lister .CertificateRequests (req .Namespace ).Get (req .Name )
344
344
if apierrors .IsNotFound (err ) {
345
345
// A NotFound error implies something deleted the resource - fail
@@ -363,8 +363,9 @@ func (m *Manager) issue(ctx context.Context, volumeID string) error {
363
363
return false , fmt .Errorf ("request %q has been denied by the approval plugin: %s" , updatedReq .Name , cond .Message )
364
364
}
365
365
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 )
368
369
// we don't stop execution here, as some versions of cert-manager (and some external issuer plugins)
369
370
// may not be aware/utilise approval.
370
371
// 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 {
373
374
374
375
readyCondition := apiutil .GetCertificateRequestCondition (updatedReq , cmapi .CertificateRequestConditionReady )
375
376
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 )
378
381
}
379
- log .V (2 ).Info ("CertificateRequest is still pending" )
380
- // Issuance is still pending
381
382
return false , nil
382
383
}
383
384
@@ -387,11 +388,12 @@ func (m *Manager) issue(ctx context.Context, volumeID string) error {
387
388
case cmapi .CertificateRequestReasonFailed :
388
389
return false , fmt .Errorf ("request %q has failed: %s" , updatedReq .Name , readyCondition .Message )
389
390
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
+ }
392
394
return false , nil
393
395
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 )
395
397
log .Info ("unrecognised state for Ready condition" , "request_namespace" , updatedReq .Namespace , "request_name" , updatedReq .Name , "condition" , * readyCondition )
396
398
return false , nil
397
399
}
@@ -401,7 +403,7 @@ func (m *Manager) issue(ctx context.Context, volumeID string) error {
401
403
// writing out signed certificate
402
404
req = updatedReq
403
405
return true , nil
404
- }, ctx . Done () ); err != nil {
406
+ }); err != nil {
405
407
if errors .Is (err , wait .ErrWaitTimeout ) {
406
408
// try and return a more helpful error message than "timed out waiting for the condition"
407
409
return fmt .Errorf ("waiting for request: %s" , lastFailureReason )
0 commit comments