Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Track selected workloads #335

Merged
merged 1 commit into from
Sep 14, 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
4 changes: 4 additions & 0 deletions controllers/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ type trackingClient struct {
func (c *trackingClient) Get(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error {
return c.Config.TrackAndGet(ctx, key, obj, opts...)
}

func (c *trackingClient) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error {
return c.Config.TrackAndList(ctx, list, opts...)
}
41 changes: 41 additions & 0 deletions controllers/servicebinding_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ import (
diemetav1 "dies.dev/apis/meta/v1"
"github.com/vmware-labs/reconciler-runtime/reconcilers"
rtesting "github.com/vmware-labs/reconciler-runtime/testing"
"github.com/vmware-labs/reconciler-runtime/tracker"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
apierrs "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -692,6 +694,19 @@ func TestResolveWorkload(t *testing.T) {
workload2.DieReleaseUnstructured(),
},
},
ExpectTracks: []rtesting.TrackRequest{
{
Tracker: types.NamespacedName{Namespace: serviceBinding.GetNamespace(), Name: serviceBinding.GetName()},
TrackedReference: tracker.Reference{
APIGroup: "apps",
Kind: "Deployment",
Namespace: serviceBinding.GetNamespace(),
Selector: labels.SelectorFromSet(labels.Set{
"app": "my",
}),
},
},
},
},
"resolve selected workload not found": {
GivenObjects: []client.Object{},
Expand All @@ -709,6 +724,19 @@ func TestResolveWorkload(t *testing.T) {
ExpectStashedValues: map[reconcilers.StashKey]interface{}{
controllers.WorkloadsStashKey: []runtime.Object{},
},
ExpectTracks: []rtesting.TrackRequest{
{
Tracker: types.NamespacedName{Namespace: serviceBinding.GetNamespace(), Name: serviceBinding.GetName()},
TrackedReference: tracker.Reference{
APIGroup: "apps",
Kind: "Deployment",
Namespace: serviceBinding.GetNamespace(),
Selector: labels.SelectorFromSet(labels.Set{
"app": "my",
}),
},
},
},
},
"resolve selected workload forbidden": {
Resource: serviceBinding.
Expand Down Expand Up @@ -756,6 +784,19 @@ func TestResolveWorkload(t *testing.T) {
)
}).
DieReleasePtr(),
ExpectTracks: []rtesting.TrackRequest{
{
Tracker: types.NamespacedName{Namespace: serviceBinding.GetNamespace(), Name: serviceBinding.GetName()},
TrackedReference: tracker.Reference{
APIGroup: "apps",
Kind: "Deployment",
Namespace: serviceBinding.GetNamespace(),
Selector: labels.SelectorFromSet(labels.Set{
"app": "my",
}),
},
},
},
},
}

Expand Down
Loading