Skip to content

Commit

Permalink
make comparison func generic
Browse files Browse the repository at this point in the history
Signed-off-by: njayp <[email protected]>
  • Loading branch information
njayp authored and thallgren committed Dec 28, 2022
1 parent 44aca8d commit b3c5ad2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
# k8sapi

A lightweight kubernetes api

```
git tag --annotate --message='Releasing version vSEMVER' vSEMVER
git push origin vSEMVER
```
1 change: 0 additions & 1 deletion examples/podLogger/cmd/main.go

This file was deleted.

10 changes: 5 additions & 5 deletions pkg/k8sapi/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ import (
const resyncPeriod = 2 * time.Minute

// Watcher watches some resource and can be cancelled.
type Watcher[T any] struct {
type Watcher[T runtime.Object] struct {
sync.Mutex
cancel context.CancelFunc
resource string
namespace string
getter cache.Getter
objType runtime.Object
objType T
cond *sync.Cond
controller cache.Controller
store cache.Store
equals func(runtime.Object, runtime.Object) bool
equals func(T, T) bool
stateListeners []*StateListener
}

Expand Down Expand Up @@ -65,7 +65,7 @@ func newListerWatcher(c context.Context, getter cache.Getter, resource, namespac
return &cache.ListWatch{ListFunc: listFunc, WatchFunc: watchFunc}
}

func NewWatcher[T runtime.Object](resource, namespace string, getter cache.Getter, objType T, cond *sync.Cond, equals func(runtime.Object, runtime.Object) bool) *Watcher[T] {
func NewWatcher[T runtime.Object](resource, namespace string, getter cache.Getter, objType T, cond *sync.Cond, equals func(T, T) bool) *Watcher[T] {
return &Watcher[T]{
resource: resource,
namespace: namespace,
Expand Down Expand Up @@ -257,7 +257,7 @@ func (w *Watcher[T]) process(c context.Context, ds cache.Deltas, eventCh chan<-
if err = w.store.Update(d.Object); err != nil {
return err
}
if w.equals(old.(runtime.Object), d.Object.(runtime.Object)) {
if w.equals(old.(T), d.Object.(T)) {
continue
}
verb = "update"
Expand Down

0 comments on commit b3c5ad2

Please sign in to comment.