forked from cert-manager/cert-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.go
60 lines (46 loc) · 1.88 KB
/
setup.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
60
package ca
import (
"context"
"fmt"
"k8s.io/api/core/v1"
"github.com/golang/glog"
"github.com/jetstack/cert-manager/pkg/apis/certmanager/v1alpha1"
"github.com/jetstack/cert-manager/pkg/util/kube"
)
const (
errorGetKeyPair = "ErrGetKeyPair"
errorInvalidKeyPair = "ErrInvalidKeyPair"
successKeyPairVerified = "KeyPairVerified"
messageErrorGetKeyPair = "Error getting keypair for CA issuer: "
messageErrorInvalidKeyPair = "Invalid signing key pair: "
messageKeyPairVerified = "Signing CA verified"
)
func (c *CA) Setup(ctx context.Context) error {
cert, err := kube.SecretTLSCert(c.secretsLister, c.issuerResourcesNamespace, c.issuer.GetSpec().CA.SecretName)
if err != nil {
s := messageErrorGetKeyPair + err.Error()
glog.Info(s)
c.recorder.Event(c.issuer, v1.EventTypeWarning, errorGetKeyPair, s)
c.issuer.UpdateStatusCondition(v1alpha1.IssuerConditionReady, v1alpha1.ConditionFalse, errorGetKeyPair, s)
return err
}
_, err = kube.SecretTLSKey(c.secretsLister, c.issuerResourcesNamespace, c.issuer.GetSpec().CA.SecretName)
if err != nil {
s := messageErrorGetKeyPair + err.Error()
glog.Info(s)
c.recorder.Event(c.issuer, v1.EventTypeWarning, errorGetKeyPair, s)
c.issuer.UpdateStatusCondition(v1alpha1.IssuerConditionReady, v1alpha1.ConditionFalse, errorGetKeyPair, s)
return err
}
if !cert.IsCA {
s := messageErrorGetKeyPair + "certificate is not a CA"
glog.Info(s)
c.recorder.Event(c.issuer, v1.EventTypeWarning, errorInvalidKeyPair, s)
c.issuer.UpdateStatusCondition(v1alpha1.IssuerConditionReady, v1alpha1.ConditionFalse, errorInvalidKeyPair, s)
return fmt.Errorf(s)
}
glog.Info(messageKeyPairVerified)
c.recorder.Event(c.issuer, v1.EventTypeNormal, successKeyPairVerified, messageKeyPairVerified)
c.issuer.UpdateStatusCondition(v1alpha1.IssuerConditionReady, v1alpha1.ConditionTrue, successKeyPairVerified, messageKeyPairVerified)
return nil
}