Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

Commit eda8335

Browse files
committed
Update addEventHandler return values
Signed-off-by: jaellio <[email protected]>
1 parent 2d9d8a9 commit eda8335

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

pkg/k8s/informers/informers.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ func (ic *InformerCollection) AddEventHandler(informerKey InformerKey, handler c
184184
return
185185
}
186186

187-
i.AddEventHandler(handler)
187+
if _, err := i.AddEventHandler(handler); err != nil {
188+
log.Error().Err(err).Msgf("Error adding event handler for informer %s", informerKey)
189+
}
188190
}
189191

190192
// GetByKey retrieves an item (based on the given index) from the store of the informer indexed by the given InformerKey

pkg/reconciler/client.go

+22-8
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func NewReconcilerClient(kubeClient kubernetes.Interface, apiServerClient client
2929
}
3030

3131
// Initialize informers
32-
informerInitHandlerMap := map[k8s.InformerKey]func(){
32+
informerInitHandlerMap := map[k8s.InformerKey]func() error{
3333
CrdInformerKey: c.initCustomResourceDefinitionMonitor,
3434
MutatingWebhookInformerKey: c.initMutatingWebhookConfigurationMonitor,
3535
ValidatingWebhookInformerKey: c.initValidatingWebhookConfigurationMonitor,
@@ -46,7 +46,10 @@ func NewReconcilerClient(kubeClient kubernetes.Interface, apiServerClient client
4646
}
4747

4848
for _, informer := range selectInformers {
49-
informerInitHandlerMap[informer]()
49+
if err := informerInitHandlerMap[informer](); err != nil {
50+
log.Error().Err(err).Msgf("Error initializing informer %s", informer)
51+
return err
52+
}
5053
}
5154

5255
if err := c.run(stop); err != nil {
@@ -59,7 +62,7 @@ func NewReconcilerClient(kubeClient kubernetes.Interface, apiServerClient client
5962
}
6063

6164
// Initializes CustomResourceDefinition monitoring
62-
func (c *client) initCustomResourceDefinitionMonitor() {
65+
func (c *client) initCustomResourceDefinitionMonitor() error {
6366
// Use the OSM version as the selector for reconciliation
6467
osmCrdsLabel := map[string]string{constants.OSMAppNameLabelKey: constants.OSMAppNameLabelValue, constants.ReconcileLabel: c.osmVersion}
6568

@@ -74,11 +77,15 @@ func (c *client) initCustomResourceDefinitionMonitor() {
7477
c.informers[CrdInformerKey] = informerFactory
7578

7679
// Add event handler to informer
77-
c.informers[CrdInformerKey].AddEventHandler(c.crdEventHandler())
80+
if _, err := c.informers[CrdInformerKey].AddEventHandler(c.crdEventHandler()); err != nil {
81+
log.Error().Err(err).Msgf("Error adding event handler to informer %s", CrdInformerKey)
82+
return err
83+
}
84+
return nil
7885
}
7986

8087
// Initializes mutating webhook monitoring
81-
func (c *client) initMutatingWebhookConfigurationMonitor() {
88+
func (c *client) initMutatingWebhookConfigurationMonitor() error {
8289
osmMwhcLabel := map[string]string{constants.OSMAppNameLabelKey: constants.OSMAppNameLabelValue, constants.OSMAppInstanceLabelKey: c.meshName, constants.ReconcileLabel: strconv.FormatBool(true)}
8390
labelSelector := fields.SelectorFromSet(osmMwhcLabel).String()
8491
option := informers.WithTweakListOptions(func(opt *metav1.ListOptions) {
@@ -91,11 +98,15 @@ func (c *client) initMutatingWebhookConfigurationMonitor() {
9198
c.informers[MutatingWebhookInformerKey] = informerFactory.Admissionregistration().V1().MutatingWebhookConfigurations().Informer()
9299

93100
// Add event handler to informer
94-
c.informers[MutatingWebhookInformerKey].AddEventHandler(c.mutatingWebhookEventHandler())
101+
if _, err := c.informers[MutatingWebhookInformerKey].AddEventHandler(c.mutatingWebhookEventHandler()); err != nil {
102+
log.Error().Err(err).Msgf("Error adding event handler to informer %s", MutatingWebhookInformerKey)
103+
return err
104+
}
105+
return nil
95106
}
96107

97108
// Initializes validating webhook monitoring
98-
func (c *client) initValidatingWebhookConfigurationMonitor() {
109+
func (c *client) initValidatingWebhookConfigurationMonitor() error {
99110
osmVwhcLabel := map[string]string{constants.OSMAppNameLabelKey: constants.OSMAppNameLabelValue, constants.OSMAppInstanceLabelKey: c.meshName, constants.ReconcileLabel: strconv.FormatBool(true)}
100111
labelSelector := fields.SelectorFromSet(osmVwhcLabel).String()
101112
option := informers.WithTweakListOptions(func(opt *metav1.ListOptions) {
@@ -108,7 +119,10 @@ func (c *client) initValidatingWebhookConfigurationMonitor() {
108119
c.informers[ValidatingWebhookInformerKey] = informerFactory.Admissionregistration().V1().ValidatingWebhookConfigurations().Informer()
109120

110121
// Add event handler to informer
111-
c.informers[ValidatingWebhookInformerKey].AddEventHandler(c.validatingWebhookEventHandler())
122+
if _, err := c.informers[ValidatingWebhookInformerKey].AddEventHandler(c.validatingWebhookEventHandler()); err != nil {
123+
log.Error().Err(err).Msgf("Error adding event handler to informer %s", ValidatingWebhookInformerKey)
124+
}
125+
return nil
112126
}
113127

114128
func (c *client) run(stop <-chan struct{}) error {

0 commit comments

Comments
 (0)