forked from cert-manager/cert-manager
/
checks.go
59 lines (48 loc) · 1.31 KB
/
checks.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package certificates
import (
"fmt"
corev1 "k8s.io/api/core/v1"
extv1beta1 "k8s.io/api/extensions/v1beta1"
"k8s.io/apimachinery/pkg/labels"
"github.com/jetstack/cert-manager/pkg/apis/certmanager/v1alpha1"
)
func (c *Controller) certificatesForSecret(secret *corev1.Secret) ([]*v1alpha1.Certificate, error) {
crts, err := c.certificateLister.List(labels.NewSelector())
if err != nil {
return nil, fmt.Errorf("error listing certificiates: %s", err.Error())
}
var affected []*v1alpha1.Certificate
for _, crt := range crts {
if crt.Namespace != secret.Namespace {
continue
}
if crt.Spec.SecretName == secret.Name {
affected = append(affected, crt)
}
}
return affected, nil
}
func (c *Controller) certificatesForIngress(ing *extv1beta1.Ingress) ([]*v1alpha1.Certificate, error) {
crts, err := c.certificateLister.List(labels.NewSelector())
if err != nil {
return nil, fmt.Errorf("error listing certificiates: %s", err.Error())
}
var affected []*v1alpha1.Certificate
for _, crt := range crts {
if crt.Namespace != ing.Namespace {
continue
}
if crt.Spec.ACME != nil {
for _, cfg := range crt.Spec.ACME.Config {
if cfg.HTTP01 == nil {
continue
}
if cfg.HTTP01.Ingress == ing.Name {
affected = append(affected, crt)
continue
}
}
}
}
return affected, nil
}