@@ -286,6 +286,7 @@ func (m *Manager) issue(ctx context.Context, volumeID string) error {
286
286
log .Info ("Created new CertificateRequest resource" )
287
287
288
288
// Poll every 1s for the CertificateRequest to be ready
289
+ lastFailureReason := ""
289
290
if err := wait .PollUntil (time .Second , func () (done bool , err error ) {
290
291
updatedReq , err := m .lister .CertificateRequests (req .Namespace ).Get (req .Name )
291
292
if apierrors .IsNotFound (err ) {
@@ -304,11 +305,25 @@ func (m *Manager) issue(ctx context.Context, volumeID string) error {
304
305
// Handle cases where the request has been explicitly denied
305
306
if apiutil .CertificateRequestIsDenied (updatedReq ) {
306
307
cond := apiutil .GetCertificateRequestCondition (updatedReq , cmapi .CertificateRequestConditionDenied )
308
+ // if a CR has been explicitly denied, we DO stop execution.
309
+ // there may be a case to be made that we could continue anyway even if the issuer ignores the approval
310
+ // status, however these cases are likely few and far between and this makes denial more responsive.
307
311
return false , fmt .Errorf ("request %q has been denied by the approval plugin: %s" , updatedReq .Name , cond .Message )
308
312
}
309
313
314
+ if ! apiutil .CertificateRequestIsApproved (updatedReq ) {
315
+ lastFailureReason = "request has not yet been approved by approval plugin"
316
+ // we don't stop execution here, as some versions of cert-manager (and some external issuer plugins)
317
+ // may not be aware/utilise approval.
318
+ // If the certificate is still issued despite never being approved, the CSI driver should continue
319
+ // and use the issued certificate despite not being approved.
320
+ }
321
+
310
322
readyCondition := apiutil .GetCertificateRequestCondition (updatedReq , cmapi .CertificateRequestConditionReady )
311
323
if readyCondition == nil {
324
+ if apiutil .CertificateRequestIsApproved (updatedReq ) {
325
+ lastFailureReason = "request has no ready condition"
326
+ }
312
327
log .V (2 ).Info ("CertificateRequest is still pending" )
313
328
// Issuance is still pending
314
329
return false , nil
@@ -320,9 +335,11 @@ func (m *Manager) issue(ctx context.Context, volumeID string) error {
320
335
case cmapi .CertificateRequestReasonFailed :
321
336
return false , fmt .Errorf ("request %q has failed: %s" , updatedReq .Name , readyCondition .Message )
322
337
case cmapi .CertificateRequestReasonPending :
338
+ lastFailureReason = fmt .Sprintf ("request pending: %v" , readyCondition .Message )
323
339
log .V (2 ).Info ("CertificateRequest is still pending" )
324
340
return false , nil
325
341
default :
342
+ lastFailureReason = fmt .Sprintf ("unrecognised Ready condition state (%s): %s" , readyCondition .Reason , readyCondition .Message )
326
343
log .Info ("unrecognised state for Ready condition" , "request_namespace" , updatedReq .Namespace , "request_name" , updatedReq .Name , "condition" , * readyCondition )
327
344
return false , nil
328
345
}
@@ -333,6 +350,10 @@ func (m *Manager) issue(ctx context.Context, volumeID string) error {
333
350
req = updatedReq
334
351
return true , nil
335
352
}, ctx .Done ()); err != nil {
353
+ if errors .Is (err , wait .ErrWaitTimeout ) {
354
+ // try and return a more helpful error message than "timed out waiting for the condition"
355
+ return fmt .Errorf ("waiting for request: %s" , lastFailureReason )
356
+ }
336
357
return fmt .Errorf ("waiting for request: %w" , err )
337
358
}
338
359
0 commit comments