Skip to content

Commit

Permalink
MEDIUM: add info to eventChan data
Browse files Browse the repository at this point in the history
Add always the object Name and the source (FETCH, INFORMER, FETCH_FROM_PROXY)
  • Loading branch information
hdurand0710 committed Sep 27, 2024
1 parent dfac68b commit 8caf642
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 36 deletions.
10 changes: 8 additions & 2 deletions pkg/k8s/cr-backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@ func (c BackendCR) GetInformer(eventChan chan k8ssync.SyncDataEvent, factory inf
}
logger.Debugf("%s %s: %s", data.GetNamespace(), status, data.GetName())
if status == store.DELETED {
eventChan <- k8ssync.SyncDataEvent{SyncType: k8ssync.SyncType(c.GetKind()), Namespace: data.GetNamespace(), Name: data.GetName(), Data: nil}
eventChan <- k8ssync.SyncDataEvent{
SyncType: k8ssync.SyncType(c.GetKind()),
Namespace: data.GetNamespace(), Name: data.GetName(), Data: nil,
}
return
}
eventChan <- k8ssync.SyncDataEvent{SyncType: k8ssync.SyncType(c.GetKind()), Namespace: data.GetNamespace(), Name: data.GetName(), Data: data}
eventChan <- k8ssync.SyncDataEvent{
SyncType: k8ssync.SyncType(c.GetKind()),
Namespace: data.GetNamespace(), Name: data.GetName(), Data: data,
}
}

errW := informer.SetWatchErrorHandler(func(r *cache.Reflector, err error) {
Expand Down
10 changes: 8 additions & 2 deletions pkg/k8s/cr-defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@ func (c DefaultsCR) GetInformer(eventChan chan k8ssync.SyncDataEvent, factory in
}
logger.Debugf("%s %s: %s", data.GetNamespace(), status, data.GetName())
if status == store.DELETED {
eventChan <- k8ssync.SyncDataEvent{SyncType: k8ssync.SyncType(c.GetKind()), Namespace: data.GetNamespace(), Name: data.GetName(), Data: nil}
eventChan <- k8ssync.SyncDataEvent{
SyncType: k8ssync.SyncType(c.GetKind()),
Namespace: data.GetNamespace(), Name: data.GetName(), Data: nil,
}
return
}
eventChan <- k8ssync.SyncDataEvent{SyncType: k8ssync.SyncType(c.GetKind()), Namespace: data.GetNamespace(), Name: data.GetName(), Data: data}
eventChan <- k8ssync.SyncDataEvent{
SyncType: k8ssync.SyncType(c.GetKind()),
Namespace: data.GetNamespace(), Name: data.GetName(), Data: data,
}
}

errW := informer.SetWatchErrorHandler(func(r *cache.Reflector, err error) {
Expand Down
10 changes: 8 additions & 2 deletions pkg/k8s/cr-global.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@ func (c GlobalCR) GetInformer(eventChan chan k8ssync.SyncDataEvent, factory info
}
logger.Debugf("%s %s: %s", data.GetNamespace(), status, data.GetName())
if status == store.DELETED {
eventChan <- k8ssync.SyncDataEvent{SyncType: k8ssync.SyncType(c.GetKind()), Namespace: data.GetNamespace(), Name: data.GetName(), Data: nil}
eventChan <- k8ssync.SyncDataEvent{
SyncType: k8ssync.SyncType(c.GetKind()),
Namespace: data.GetNamespace(), Name: data.GetName(), Data: nil,
}
return
}
eventChan <- k8ssync.SyncDataEvent{SyncType: k8ssync.SyncType(c.GetKind()), Namespace: data.GetNamespace(), Name: data.GetName(), Data: data}
eventChan <- k8ssync.SyncDataEvent{
SyncType: k8ssync.SyncType(c.GetKind()),
Namespace: data.GetNamespace(), Name: data.GetName(), Data: data,
}
}

errW := informer.SetWatchErrorHandler(func(r *cache.Reflector, err error) {
Expand Down
30 changes: 24 additions & 6 deletions pkg/k8s/crs-deprecated-v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,16 @@ func (c GlobalCRV1Alpha2) GetInformer(eventChan chan k8ssync.SyncDataEvent, fact

logger.Debugf("%s %s: %s", data.GetNamespace(), status, data.GetName())
if status == store.DELETED {
eventChan <- k8ssync.SyncDataEvent{SyncType: k8ssync.SyncType(c.GetKind()), Namespace: data.GetNamespace(), Name: data.GetName(), Data: nil}
eventChan <- k8ssync.SyncDataEvent{
SyncType: k8ssync.SyncType(c.GetKind()),
Namespace: data.GetNamespace(), Name: data.GetName(), Data: nil,
}
return
}
eventChan <- k8ssync.SyncDataEvent{SyncType: k8ssync.SyncType(c.GetKind()), Namespace: data.GetNamespace(), Name: data.GetName(), Data: data}
eventChan <- k8ssync.SyncDataEvent{
SyncType: k8ssync.SyncType(c.GetKind()),
Namespace: data.GetNamespace(), Name: data.GetName(), Data: data,
}
}

_, err := informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
Expand Down Expand Up @@ -105,10 +111,16 @@ func (c DefaultsCRV1Alpha2) GetInformer(eventChan chan k8ssync.SyncDataEvent, fa
data.Spec = converters.DeepConvertDefaultsSpecA2toV1(dataV1Alpha2.Spec)
logger.Debugf("%s %s: %s", data.GetNamespace(), status, data.GetName())
if status == store.DELETED {
eventChan <- k8ssync.SyncDataEvent{SyncType: k8ssync.SyncType(c.GetKind()), Namespace: data.GetNamespace(), Name: data.GetName(), Data: nil}
eventChan <- k8ssync.SyncDataEvent{
SyncType: k8ssync.SyncType(c.GetKind()),
Namespace: data.GetNamespace(), Name: data.GetName(), Data: nil,
}
return
}
eventChan <- k8ssync.SyncDataEvent{SyncType: k8ssync.SyncType(c.GetKind()), Namespace: data.GetNamespace(), Name: data.GetName(), Data: data}
eventChan <- k8ssync.SyncDataEvent{
SyncType: k8ssync.SyncType(c.GetKind()),
Namespace: data.GetNamespace(), Name: data.GetName(), Data: data,
}
}

_, err := informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
Expand Down Expand Up @@ -147,10 +159,16 @@ func (c BackendCRV1Alpha2) GetInformer(eventChan chan k8ssync.SyncDataEvent, fac

logger.Debugf("%s %s: %s", data.GetNamespace(), status, data.GetName())
if status == store.DELETED {
eventChan <- k8ssync.SyncDataEvent{SyncType: k8ssync.SyncType(c.GetKind()), Namespace: data.GetNamespace(), Name: data.GetName(), Data: nil}
eventChan <- k8ssync.SyncDataEvent{
SyncType: k8ssync.SyncType(c.GetKind()),
Namespace: data.GetNamespace(), Name: data.GetName(), Data: nil,
}
return
}
eventChan <- k8ssync.SyncDataEvent{SyncType: k8ssync.SyncType(c.GetKind()), Namespace: data.GetNamespace(), Name: data.GetName(), Data: data}
eventChan <- k8ssync.SyncDataEvent{
SyncType: k8ssync.SyncType(c.GetKind()),
Namespace: data.GetNamespace(), Name: data.GetName(), Data: data,
}
}

_, err := informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
Expand Down
Loading

0 comments on commit 8caf642

Please sign in to comment.