Skip to content

Commit

Permalink
Changed to filtered informer for Subscription identity service account
Browse files Browse the repository at this point in the history
  • Loading branch information
yijie-04 committed Jan 6, 2024
1 parent bbefcc2 commit de30fc5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 4 additions & 2 deletions pkg/reconciler/subscription/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package subscription
import (
"context"

"knative.dev/eventing/pkg/apis/sources"

"k8s.io/client-go/tools/cache"
"knative.dev/eventing/pkg/apis/feature"
"knative.dev/pkg/client/injection/apiextensions/informers/apiextensions/v1/customresourcedefinition"
Expand All @@ -35,7 +37,7 @@ import (
subscriptionreconciler "knative.dev/eventing/pkg/client/injection/reconciler/messaging/v1/subscription"
"knative.dev/eventing/pkg/duck"
kubeclient "knative.dev/pkg/client/injection/kube/client"
serviceaccountinformer "knative.dev/pkg/client/injection/kube/informers/core/v1/serviceaccount"
serviceaccountinformer "knative.dev/pkg/client/injection/kube/informers/core/v1/serviceaccount/filtered"
"knative.dev/pkg/injection/clients/dynamicclient"
)

Expand All @@ -48,7 +50,7 @@ func NewController(

subscriptionInformer := subscription.Get(ctx)
channelInformer := channel.Get(ctx)
serviceaccountInformer := serviceaccountinformer.Get(ctx)
serviceaccountInformer := serviceaccountinformer.Get(ctx, sources.OIDCTokenRoleLabelSelector)

var globalResync func(obj interface{})

Expand Down
14 changes: 12 additions & 2 deletions pkg/reconciler/subscription/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ limitations under the License.
package subscription

import (
"context"
"testing"

"knative.dev/eventing/pkg/apis/sources"
filteredFactory "knative.dev/pkg/client/injection/kube/informers/factory/filtered"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/configmap"
Expand All @@ -27,16 +31,17 @@ import (
"knative.dev/eventing/pkg/apis/feature"

// Fake injection informers
_ "knative.dev/pkg/client/injection/kube/informers/factory/filtered/fake"
_ "knative.dev/eventing/pkg/client/injection/ducks/duck/v1/channelable/fake"
_ "knative.dev/eventing/pkg/client/injection/informers/messaging/v1/channel/fake"
_ "knative.dev/eventing/pkg/client/injection/informers/messaging/v1/subscription/fake"
_ "knative.dev/pkg/client/injection/apiextensions/informers/apiextensions/v1/customresourcedefinition/fake"
_ "knative.dev/pkg/client/injection/ducks/duck/v1/addressable/fake"
_ "knative.dev/pkg/client/injection/kube/informers/core/v1/serviceaccount/fake"
_ "knative.dev/pkg/client/injection/kube/informers/core/v1/serviceaccount/filtered/fake"
)

func TestNew(t *testing.T) {
ctx, _ := SetupFakeContext(t)
ctx, _ := SetupFakeContext(t, SetUpInformerSelector)

c := NewController(ctx, configmap.NewStaticWatcher(
&corev1.ConfigMap{
Expand All @@ -50,3 +55,8 @@ func TestNew(t *testing.T) {
t.Fatal("Expected NewController to return a non-nil value")
}
}

func SetUpInformerSelector(ctx context.Context) context.Context {
ctx = filteredFactory.WithSelectors(ctx, sources.OIDCTokenRoleLabelSelector)
return ctx
}

0 comments on commit de30fc5

Please sign in to comment.