Skip to content

Commit a513f14

Browse files
committed
Inject Kubeclient
Signed-off-by: Pierangelo Di Pilato <[email protected]>
1 parent f3edb9d commit a513f14

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

pkg/apis/sources/v1/sinkbinding_lifecycle.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import (
2323
"strings"
2424

2525
"go.uber.org/zap"
26+
"k8s.io/client-go/kubernetes"
2627
corev1listers "k8s.io/client-go/listers/core/v1"
27-
kubeclient "knative.dev/pkg/client/injection/kube/client"
2828

2929
corev1 "k8s.io/api/core/v1"
3030
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -202,7 +202,7 @@ func (sb *SinkBinding) Do(ctx context.Context, ps *duckv1.WithPod) {
202202
Version: SchemeGroupVersion.Version,
203203
Kind: "SinkBinding",
204204
}
205-
bundles, err := eventingtls.PropagateTrustBundles(ctx, kubeclient.Get(ctx), GetTrustBundleConfigMapLister(ctx), gvk, sb)
205+
bundles, err := eventingtls.PropagateTrustBundles(ctx, getKubeClient(ctx), GetTrustBundleConfigMapLister(ctx), gvk, sb)
206206
if err != nil {
207207
logging.FromContext(ctx).Errorw("Failed to propagate trust bundles", zap.Error(err))
208208
}
@@ -328,6 +328,20 @@ func (sb *SinkBinding) Undo(ctx context.Context, ps *duckv1.WithPod) {
328328
}
329329
}
330330

331+
type kubeClientKey struct{}
332+
333+
func WithKubeClient(ctx context.Context, k kubernetes.Interface) context.Context {
334+
return context.WithValue(ctx, kubeClientKey{}, k)
335+
}
336+
337+
func getKubeClient(ctx context.Context) kubernetes.Interface {
338+
k := ctx.Value(kubeClientKey{})
339+
if k == nil {
340+
return nil
341+
}
342+
return k.(kubernetes.Interface)
343+
}
344+
331345
type configMapListerKey struct{}
332346

333347
func WithTrustBundleConfigMapLister(ctx context.Context, lister corev1listers.ConfigMapLister) context.Context {

pkg/reconciler/sinkbinding/controller.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,10 @@ func ListAll(ctx context.Context, handler cache.ResourceEventHandler) psbinding.
226226

227227
func WithContextFactory(ctx context.Context, lister corev1listers.ConfigMapLister, handler func(types.NamespacedName)) psbinding.BindableContext {
228228
r := resolver.NewURIResolverFromTracker(ctx, tracker.New(handler, controller.GetTrackerLease(ctx)))
229+
k := kubeclient.Get(ctx)
229230

230231
return func(ctx context.Context, b psbinding.Bindable) (context.Context, error) {
231-
return v1.WithTrustBundleConfigMapLister(v1.WithURIResolver(ctx, r), lister), nil
232+
return v1.WithKubeClient(v1.WithTrustBundleConfigMapLister(v1.WithURIResolver(ctx, r), lister), k), nil
232233
}
233234
}
234235

0 commit comments

Comments
 (0)