-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.go
51 lines (39 loc) · 1.59 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
package ca
import (
"context"
"fmt"
"k8s.io/api/core/v1"
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
"github.com/golang/glog"
"github.com/jetstack-experimental/cert-manager/pkg/apis/certmanager/v1alpha1"
"github.com/jetstack-experimental/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.resourceNamespace, c.issuer.GetSpec().CA.SecretName)
if k8sErrors.IsNotFound(err) {
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
}