Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix TrackKind behavior #1214

Merged
merged 1 commit into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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