-
Notifications
You must be signed in to change notification settings - Fork 106
/
certificate.go
40 lines (31 loc) · 1.01 KB
/
certificate.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
package statuscheck
import (
"context"
certv1 "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1"
cmmeta "github.com/jetstack/cert-manager/pkg/apis/meta/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)
func CertificateCheck(ctx context.Context, object client.Object) (bool, error) {
cert := object.(*certv1.Certificate)
expiration := cert.Status.NotAfter
if !expiration.IsZero() && metav1.Now().After(expiration.Time) {
// Certificate expired
return false, nil
}
for _, condition := range cert.Status.Conditions {
if condition.Type == certv1.CertificateConditionReady {
return condition.Status == cmmeta.ConditionTrue, nil
}
}
return false, nil
}
func IssuerCheck(ctx context.Context, object client.Object) (bool, error) {
issuer := object.(*certv1.Issuer)
for _, condition := range issuer.Status.Conditions {
if condition.Type == certv1.IssuerConditionReady {
return condition.Status == cmmeta.ConditionTrue, nil
}
}
return false, nil
}