forked from cert-manager/cert-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync.go
54 lines (43 loc) · 1.26 KB
/
sync.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
package issuers
import (
"context"
"github.com/golang/glog"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/errors"
"github.com/jetstack/cert-manager/pkg/apis/certmanager/v1alpha1"
)
const (
errorInitIssuer = "ErrInitIssuer"
messageErrorInitIssuer = "Error initializing issuer: "
)
func (c *Controller) Sync(ctx context.Context, iss *v1alpha1.Issuer) (err error) {
issuerCopy := iss.DeepCopy()
i, err := c.issuerFactory.IssuerFor(issuerCopy)
if err != nil {
return err
}
err = i.Setup(ctx)
defer func() {
if saveErr := c.updateIssuerStatus(issuerCopy); saveErr != nil {
errs := []error{saveErr}
if err != nil {
errs = append(errs, err)
}
err = errors.NewAggregate(errs)
}
}()
if err != nil {
s := messageErrorInitIssuer + err.Error()
glog.Info(s)
c.recorder.Event(issuerCopy, v1.EventTypeWarning, errorInitIssuer, s)
return err
}
return nil
}
func (c *Controller) updateIssuerStatus(iss *v1alpha1.Issuer) error {
// TODO: replace Update call with UpdateStatus. This requires a custom API
// server with the /status subresource enabled and/or subresource support
// for CRDs (https://github.com/kubernetes/kubernetes/issues/38113)
_, err := c.cmClient.CertmanagerV1alpha1().Issuers(iss.Namespace).Update(iss)
return err
}