diff --git a/pkg/apis/sources/v1/sinkbinding_lifecycle.go b/pkg/apis/sources/v1/sinkbinding_lifecycle.go index 2928f4ce848..5705a5b5b0c 100644 --- a/pkg/apis/sources/v1/sinkbinding_lifecycle.go +++ b/pkg/apis/sources/v1/sinkbinding_lifecycle.go @@ -23,8 +23,8 @@ import ( "strings" "go.uber.org/zap" + "k8s.io/client-go/kubernetes" corev1listers "k8s.io/client-go/listers/core/v1" - kubeclient "knative.dev/pkg/client/injection/kube/client" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime/schema" @@ -202,7 +202,7 @@ func (sb *SinkBinding) Do(ctx context.Context, ps *duckv1.WithPod) { Version: SchemeGroupVersion.Version, Kind: "SinkBinding", } - bundles, err := eventingtls.PropagateTrustBundles(ctx, kubeclient.Get(ctx), GetTrustBundleConfigMapLister(ctx), gvk, sb) + bundles, err := eventingtls.PropagateTrustBundles(ctx, getKubeClient(ctx), GetTrustBundleConfigMapLister(ctx), gvk, sb) if err != nil { logging.FromContext(ctx).Errorw("Failed to propagate trust bundles", zap.Error(err)) } @@ -328,6 +328,20 @@ func (sb *SinkBinding) Undo(ctx context.Context, ps *duckv1.WithPod) { } } +type kubeClientKey struct{} + +func WithKubeClient(ctx context.Context, k kubernetes.Interface) context.Context { + return context.WithValue(ctx, kubeClientKey{}, k) +} + +func getKubeClient(ctx context.Context) kubernetes.Interface { + k := ctx.Value(kubeClientKey{}) + if k == nil { + panic("No Kube client found in context.") + } + return k.(kubernetes.Interface) +} + type configMapListerKey struct{} func WithTrustBundleConfigMapLister(ctx context.Context, lister corev1listers.ConfigMapLister) context.Context { diff --git a/pkg/reconciler/sinkbinding/controller.go b/pkg/reconciler/sinkbinding/controller.go index 573b3c737e6..bcaec7af49d 100644 --- a/pkg/reconciler/sinkbinding/controller.go +++ b/pkg/reconciler/sinkbinding/controller.go @@ -142,8 +142,9 @@ func NewController( trustBundleConfigMapLister: trustBundleConfigMapLister, } + k8s := kubeclient.Get(ctx) c.WithContext = func(ctx context.Context, b psbinding.Bindable) (context.Context, error) { - return v1.WithTrustBundleConfigMapLister(v1.WithURIResolver(ctx, sbResolver), trustBundleConfigMapLister), nil + return v1.WithKubeClient(v1.WithTrustBundleConfigMapLister(v1.WithURIResolver(ctx, sbResolver), trustBundleConfigMapLister), k8s), nil } c.Tracker = impl.Tracker c.Factory = &duck.CachedInformerFactory{ @@ -226,9 +227,10 @@ func ListAll(ctx context.Context, handler cache.ResourceEventHandler) psbinding. func WithContextFactory(ctx context.Context, lister corev1listers.ConfigMapLister, handler func(types.NamespacedName)) psbinding.BindableContext { r := resolver.NewURIResolverFromTracker(ctx, tracker.New(handler, controller.GetTrackerLease(ctx))) + k := kubeclient.Get(ctx) return func(ctx context.Context, b psbinding.Bindable) (context.Context, error) { - return v1.WithTrustBundleConfigMapLister(v1.WithURIResolver(ctx, r), lister), nil + return v1.WithKubeClient(v1.WithTrustBundleConfigMapLister(v1.WithURIResolver(ctx, r), lister), k), nil } }