Skip to content

Commit

Permalink
Merge pull request openstack-k8s-operators#537 from fao89/OSPRH-7090
Browse files Browse the repository at this point in the history
Requeue when TLS secret isn't found
  • Loading branch information
stuggi authored Jul 29, 2024
2 parents 431d0dc + d1c32e5 commit df36d69
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 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
4 changes: 2 additions & 2 deletions modules/certmanager/test/functional/certmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ var _ = Describe("certmanager module", func() {
timeout,
)

_, err := c.CreateOrPatch(ctx, h, nil)
_, _, err := c.CreateOrPatch(ctx, h, nil)
Expect(err).ShouldNot(HaveOccurred())
cert := th.GetCert(names.CertName)
Expect(cert.Spec.CommonName).To(Equal("keystone-public-openstack.apps-crc.testing"))
Expand Down Expand Up @@ -188,7 +188,7 @@ var _ = Describe("certmanager module", func() {
timeout,
)

_, err := c.CreateOrPatch(ctx, h, nil)
_, _, err := c.CreateOrPatch(ctx, h, nil)
Expect(err).ShouldNot(HaveOccurred())
cert := th.GetCert(names.CertName)
Expect(cert).NotTo(BeNil())
Expand Down

0 comments on commit df36d69

Please sign in to comment.