-
Notifications
You must be signed in to change notification settings - Fork 787
/
certmanager.go
27 lines (24 loc) · 990 Bytes
/
certmanager.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package kube
import (
certmngclient "github.com/jetstack/cert-manager/pkg/client/clientset/versioned"
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
const labelLetsencryptService = "jenkins.io/letsencrypt-service"
// IsStagingCertificate looks at certmanager certificates to find if we are using staging or prod certs
func IsStagingCertificate(client certmngclient.Interface, ns string) (bool, error) {
certs, err := client.CertmanagerV1alpha1().Certificates(ns).List(metav1.ListOptions{})
if err != nil {
return false, err
}
// loop over certificates and look for a Jenkins X label to identify if we are using staging or prod certs
for _, cert := range certs.Items {
if cert.ObjectMeta.Labels[labelLetsencryptService] == "production" {
return false, nil
}
if cert.ObjectMeta.Labels[labelLetsencryptService] == "staging" {
return true, nil
}
}
return false, errors.New("no matching certificates found with letsencrypt-service label")
}