diff --git a/pkg/tracker/tracker.go b/pkg/tracker/tracker.go index 636543d96..72d1022c7 100644 --- a/pkg/tracker/tracker.go +++ b/pkg/tracker/tracker.go @@ -25,9 +25,10 @@ import ( "sync" "time" - "github.com/pivotal/kpack/pkg/reconciler" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" + + "github.com/pivotal/kpack/pkg/reconciler" ) func New(callback func(types.NamespacedName), lease time.Duration) *Tracker { @@ -82,7 +83,7 @@ func (i *Tracker) TrackKind(kind schema.GroupKind, obj types.NamespacedName) { i.m.Lock() defer i.m.Unlock() - l, ok := i.objects[kind.String()] + l, ok := i.kinds[kind.String()] if !ok { l = set{} } diff --git a/pkg/tracker/tracker_test.go b/pkg/tracker/tracker_test.go index e3688b19c..969eb4fde 100644 --- a/pkg/tracker/tracker_test.go +++ b/pkg/tracker/tracker_test.go @@ -170,6 +170,34 @@ func testTracker(t *testing.T, when spec.G, it spec.S) { require.Equal(t, wasCalledWith, types.NamespacedName{}) }) + + it("supports multiple reconcilers tracking the same kind", func() { + calledWith := []types.NamespacedName{} + track := tracker.New(func(key types.NamespacedName) { + calledWith = append(calledWith, key) + }, 5*time.Minute) + + builder := &buildapi.Builder{ + ObjectMeta: v1.ObjectMeta{ + Name: "some-name", + }, + TypeMeta: v1.TypeMeta{ + Kind: "Builder", + APIVersion: "kpack.io/v1alpha2", + }, + } + + secondReconciler := types.NamespacedName{Name: "second reconciler", Namespace: "some namespace"} + + track.TrackKind(groupKind, reconcilerName) + track.TrackKind(groupKind, secondReconciler) + + track.OnChanged(builder) + + require.Len(t, calledWith, 2) + require.Contains(t, calledWith, reconcilerName) + require.Contains(t, calledWith, secondReconciler) + }) }) when("tracking expires", func() {