-
Notifications
You must be signed in to change notification settings - Fork 8
/
event_handlers.go
125 lines (105 loc) · 4.84 KB
/
event_handlers.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Code generated by skv2. DO NOT EDIT.
//go:generate mockgen -source ./event_handlers.go -destination mocks/event_handlers.go
// Definitions for the Kubernetes Controllers
package controller
import (
"context"
certificates_k8s_io_v1beta1 "k8s.io/api/certificates/v1beta1"
"github.com/pkg/errors"
"github.com/solo-io/skv2/pkg/events"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/predicate"
)
// Handle events for the CertificateSigningRequest Resource
// DEPRECATED: Prefer reconciler pattern.
type CertificateSigningRequestEventHandler interface {
CreateCertificateSigningRequest(obj *certificates_k8s_io_v1beta1.CertificateSigningRequest) error
UpdateCertificateSigningRequest(old, new *certificates_k8s_io_v1beta1.CertificateSigningRequest) error
DeleteCertificateSigningRequest(obj *certificates_k8s_io_v1beta1.CertificateSigningRequest) error
GenericCertificateSigningRequest(obj *certificates_k8s_io_v1beta1.CertificateSigningRequest) error
}
type CertificateSigningRequestEventHandlerFuncs struct {
OnCreate func(obj *certificates_k8s_io_v1beta1.CertificateSigningRequest) error
OnUpdate func(old, new *certificates_k8s_io_v1beta1.CertificateSigningRequest) error
OnDelete func(obj *certificates_k8s_io_v1beta1.CertificateSigningRequest) error
OnGeneric func(obj *certificates_k8s_io_v1beta1.CertificateSigningRequest) error
}
func (f *CertificateSigningRequestEventHandlerFuncs) CreateCertificateSigningRequest(obj *certificates_k8s_io_v1beta1.CertificateSigningRequest) error {
if f.OnCreate == nil {
return nil
}
return f.OnCreate(obj)
}
func (f *CertificateSigningRequestEventHandlerFuncs) DeleteCertificateSigningRequest(obj *certificates_k8s_io_v1beta1.CertificateSigningRequest) error {
if f.OnDelete == nil {
return nil
}
return f.OnDelete(obj)
}
func (f *CertificateSigningRequestEventHandlerFuncs) UpdateCertificateSigningRequest(objOld, objNew *certificates_k8s_io_v1beta1.CertificateSigningRequest) error {
if f.OnUpdate == nil {
return nil
}
return f.OnUpdate(objOld, objNew)
}
func (f *CertificateSigningRequestEventHandlerFuncs) GenericCertificateSigningRequest(obj *certificates_k8s_io_v1beta1.CertificateSigningRequest) error {
if f.OnGeneric == nil {
return nil
}
return f.OnGeneric(obj)
}
type CertificateSigningRequestEventWatcher interface {
AddEventHandler(ctx context.Context, h CertificateSigningRequestEventHandler, predicates ...predicate.Predicate) error
}
type certificateSigningRequestEventWatcher struct {
watcher events.EventWatcher
}
func NewCertificateSigningRequestEventWatcher(name string, mgr manager.Manager) CertificateSigningRequestEventWatcher {
return &certificateSigningRequestEventWatcher{
watcher: events.NewWatcher(name, mgr, &certificates_k8s_io_v1beta1.CertificateSigningRequest{}),
}
}
func (c *certificateSigningRequestEventWatcher) AddEventHandler(ctx context.Context, h CertificateSigningRequestEventHandler, predicates ...predicate.Predicate) error {
handler := genericCertificateSigningRequestHandler{handler: h}
if err := c.watcher.Watch(ctx, handler, predicates...); err != nil {
return err
}
return nil
}
// genericCertificateSigningRequestHandler implements a generic events.EventHandler
type genericCertificateSigningRequestHandler struct {
handler CertificateSigningRequestEventHandler
}
func (h genericCertificateSigningRequestHandler) Create(object client.Object) error {
obj, ok := object.(*certificates_k8s_io_v1beta1.CertificateSigningRequest)
if !ok {
return errors.Errorf("internal error: CertificateSigningRequest handler received event for %T", object)
}
return h.handler.CreateCertificateSigningRequest(obj)
}
func (h genericCertificateSigningRequestHandler) Delete(object client.Object) error {
obj, ok := object.(*certificates_k8s_io_v1beta1.CertificateSigningRequest)
if !ok {
return errors.Errorf("internal error: CertificateSigningRequest handler received event for %T", object)
}
return h.handler.DeleteCertificateSigningRequest(obj)
}
func (h genericCertificateSigningRequestHandler) Update(old, new client.Object) error {
objOld, ok := old.(*certificates_k8s_io_v1beta1.CertificateSigningRequest)
if !ok {
return errors.Errorf("internal error: CertificateSigningRequest handler received event for %T", old)
}
objNew, ok := new.(*certificates_k8s_io_v1beta1.CertificateSigningRequest)
if !ok {
return errors.Errorf("internal error: CertificateSigningRequest handler received event for %T", new)
}
return h.handler.UpdateCertificateSigningRequest(objOld, objNew)
}
func (h genericCertificateSigningRequestHandler) Generic(object client.Object) error {
obj, ok := object.(*certificates_k8s_io_v1beta1.CertificateSigningRequest)
if !ok {
return errors.Errorf("internal error: CertificateSigningRequest handler received event for %T", object)
}
return h.handler.GenericCertificateSigningRequest(obj)
}