Skip to content

Commit

Permalink
Requeue when TLS secret isn't found
Browse files Browse the repository at this point in the history
closes OSPRH-7090

Signed-off-by: Fabricio Aguiar <[email protected]>
  • Loading branch information
fao89 committed Jul 24, 2024
1 parent bd202c8 commit fb6446a
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions modules/certmanager/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (c *Certificate) CreateOrPatch(
ctx context.Context,
h *helper.Helper,
owner client.Object,
) (ctrl.Result, error) {
) (ctrl.Result, controllerutil.OperationResult, error) {
var err error
cert := &certmgrv1.Certificate{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -131,15 +131,15 @@ func (c *Certificate) CreateOrPatch(
if err != nil {
if k8s_errors.IsNotFound(err) {
h.GetLogger().Info(fmt.Sprintf("Certificate %s not found, reconcile in %s", cert.Name, c.timeout))
return ctrl.Result{RequeueAfter: c.timeout}, nil
return ctrl.Result{RequeueAfter: c.timeout}, op, nil
}
return ctrl.Result{}, err
return ctrl.Result{}, op, err
}
if op != controllerutil.OperationResultNone {
h.GetLogger().Info(fmt.Sprintf("Route %s - %s", cert.Name, op))
}

return ctrl.Result{}, nil
return ctrl.Result{}, op, nil
}

// Delete - delete a certificate.
Expand All @@ -156,7 +156,7 @@ func (c *Certificate) Delete(
return nil
}

// EnsureCert - creates a certificate, ensures the sercret has the required key/cert and return the secret
// EnsureCert - creates a certificate, ensures the secret has the required key/cert and return the secret
func EnsureCert(
ctx context.Context,
helper *helper.Helper,
Expand Down Expand Up @@ -233,7 +233,7 @@ func EnsureCert(
)

cert := NewCertificate(certReq, 5)
ctrlResult, err := cert.CreateOrPatch(ctx, helper, owner)
ctrlResult, op, err := cert.CreateOrPatch(ctx, helper, owner)
if err != nil {
return nil, ctrlResult, err
} else if (ctrlResult != ctrl.Result{}) {
Expand All @@ -243,6 +243,10 @@ func EnsureCert(
// get cert secret
certSecret, _, err := secret.GetSecret(ctx, helper, certSecretName, namespace)
if err != nil {
if k8s_errors.IsNotFound(err) && op == controllerutil.OperationResultCreated {
helper.GetLogger().Info(fmt.Sprintf("Secret %s not found, reconcile in %s", certSecretName, cert.timeout))
return nil, ctrl.Result{RequeueAfter: cert.timeout}, nil
}
return nil, ctrl.Result{}, err
}

Expand Down

0 comments on commit fb6446a

Please sign in to comment.