Skip to content

Commit

Permalink
Fix TrackKind behavior
Browse files Browse the repository at this point in the history
- fix issue that prevented more than one clusterbuilder from tracking a particular kind
- Add testing for multiple reconcilers tracking the same kind

fixes buildpacks-community#1211
  • Loading branch information
tomkennedy513 committed May 18, 2023
1 parent 1c20046 commit 1625679
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/tracker/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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{}
}
Expand Down
28 changes: 28 additions & 0 deletions pkg/tracker/tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 1625679

Please sign in to comment.