Skip to content

Commit e016e73

Browse files
author
Per Goncalves da Silva
committed
more small fixes
Signed-off-by: Per Goncalves da Silva <[email protected]>
1 parent f8c273c commit e016e73

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

pkg/lib/queueinformer/queueinformer.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package queueinformer
22

33
import (
44
"context"
5+
"fmt"
56

67
"github.com/pkg/errors"
78
"github.com/sirupsen/logrus"
@@ -43,21 +44,25 @@ func (q *QueueInformer) Enqueue(event kubestate.ResourceEvent) {
4344
return
4445
}
4546

46-
resource := event.Resource()
47+
e := event
4748

4849
// Delete operations should always carry either something assignable to
4950
// metev1.Object or cache.DeletedFinalStateUnknown.
5051
// Add/Update events coming from the informer should have their resource
5152
// converted to a key (string) before being enqueued.
5253
if event.Type() != kubestate.ResourceDeleted {
5354
// Extract key for add and update events
54-
if key, ok := q.key(resource); ok {
55-
resource = key
55+
if key, ok := q.key(e.Resource()); ok {
56+
e = kubestate.NewResourceEvent(event.Type(), key)
57+
} else {
58+
// if the resource cannot be keyed the worker will not be able to process it
59+
// since it will not be able to retrieve the resource
60+
q.logger.WithField("event", e).Warn(fmt.Sprintf("resource of type %T is not keyable - skipping enqueue", e.Resource()))
61+
return
5662
}
5763
}
5864

5965
// Create new resource event and add to queue
60-
e := kubestate.NewResourceEvent(event.Type(), resource)
6166
q.logger.WithField("event", e).Trace("enqueuing resource event")
6267
q.queue.Add(e)
6368
}

pkg/lib/queueinformer/queueinformer_operator.go

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -284,25 +284,20 @@ func (o *operator) processNextWorkItem(ctx context.Context, loop *QueueInformer)
284284
}
285285

286286
logger = logger.WithField("cache-key", key)
287-
288-
var resource interface{}
289-
if loop.indexer == nil {
290-
resource = item.Resource()
291-
} else {
292-
// Get the current cached version of the resource
293-
var exists bool
294-
var err error
295-
resource, exists, err = loop.indexer.GetByKey(key)
296-
if err != nil {
297-
logger.WithError(err).Error("cache get failed")
298-
queue.Forget(item)
299-
return true
300-
}
301-
if !exists {
302-
logger.WithField("existing-cache-keys", loop.indexer.ListKeys()).Debug("cache get failed, key not in cache")
303-
queue.Forget(item)
304-
return true
305-
}
287+
288+
// Get the current cached version of the resource
289+
var exists bool
290+
var err error
291+
resource, exists, err := loop.indexer.GetByKey(key)
292+
if err != nil {
293+
logger.WithError(err).Error("cache get failed")
294+
queue.Forget(item)
295+
return true
296+
}
297+
if !exists {
298+
logger.WithField("existing-cache-keys", loop.indexer.ListKeys()).Debug("cache get failed, key not in cache")
299+
queue.Forget(item)
300+
return true
306301
}
307302
event = kubestate.NewResourceEvent(item.Type(), resource)
308303
}

0 commit comments

Comments
 (0)