Skip to content

Commit

Permalink
Merge pull request #395 from stuggi/getissuerbyname
Browse files Browse the repository at this point in the history
[certmanager] Adds func GetIssuerByName() to get an issuer by name
  • Loading branch information
stuggi authored Nov 21, 2023
2 parents f177971 + 160305b commit 853ac40
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
19 changes: 19 additions & 0 deletions modules/certmanager/issuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
)
Expand Down Expand Up @@ -146,3 +147,21 @@ func (i *Issuer) Delete(

return nil
}

// GetIssuerByName - get certmanager issuer by name
func GetIssuerByName(
ctx context.Context,
h *helper.Helper,
name string,
namespace string,
) (*certmgrv1.Issuer, error) {

issuer := &certmgrv1.Issuer{}

err := h.GetClient().Get(ctx, types.NamespacedName{Name: name, Namespace: namespace}, issuer)
if err != nil {
return nil, fmt.Errorf("Error getting issuer %s: %w", issuer.Name, err)
}

return issuer, nil
}
14 changes: 10 additions & 4 deletions modules/certmanager/test/functional/certmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@ var _ = Describe("certmanager module", func() {

_, err := i.CreateOrPatch(ctx, h)
Expect(err).ShouldNot(HaveOccurred())
issuer := th.GetIssuer(names.SelfSignedIssuerName)
Expect(issuer.Spec.SelfSigned).NotTo(BeNil())
Expect(issuer.Labels["f"]).To(Equal("l"))

Eventually(func(g Gomega) {
issuer, err := certmanager.GetIssuerByName(
th.Ctx,
h,
names.SelfSignedIssuerName.Name,
names.SelfSignedIssuerName.Namespace)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(issuer.Spec.SelfSigned).NotTo(BeNil())
g.Expect(issuer.ObjectMeta.Labels["f"]).To(Equal("l"))
}, timeout, interval).Should(Succeed())
})

It("creates CA issuer", func() {
Expand Down

0 comments on commit 853ac40

Please sign in to comment.