Coder Social home page Coder Social logo

Drop dynamic wrapped client generation about pkg HOT 8 OPEN

dprotaso avatar dprotaso commented on September 23, 2024
Drop dynamic wrapped client generation

from pkg.

Comments (8)

dprotaso avatar dprotaso commented on September 23, 2024

cc @mattmoor in case you have more references to usages

from pkg.

mattmoor avatar mattmoor commented on September 23, 2024

We use this downstream to inject clients that exhibit different behavior.

cc @wlynch who I know spent a bunch of time looking at improving things a few weeks ago to streamline updates.

from pkg.

dprotaso avatar dprotaso commented on September 23, 2024

exhibit different behavior.

In what way?

We use this downstream...

I'm thinking of making the generation optional - so you can just generate these yourself downstream

from pkg.

mattmoor avatar mattmoor commented on September 23, 2024

@dprotaso I think for downstream codegen to work, the clients would need to be in their own go module, so that folks can go mod -replace with additional options.

from pkg.

dprotaso avatar dprotaso commented on September 23, 2024

I don't understand - can you elaborate?

I'm suggesting downstream add a generation script like so

OUTPUT_PKG="knative.dev/pkg/client/injection/kube" \
VERSIONED_CLIENTSET_PKG="k8s.io/client-go/kubernetes" \
EXTERNAL_INFORMER_PKG="k8s.io/client-go/informers" \
${REPO_ROOT_DIR}/hack/generate-knative.sh "injection" \
k8s.io/client-go \
k8s.io/api \
"${K8S_TYPES}" \
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt \
--force-genreconciler-kinds "Namespace,ConfigMap,Deployment,Secret,Pod,CronJob,NetworkPolicy,Node,ValidatingWebhookConfiguration,MutatingWebhookConfiguration"

But add a flag --force-dynamic-clients or something to get the extra dynamic stuff

from pkg.

dprotaso avatar dprotaso commented on September 23, 2024

So looking at all the downstream packages that depend on injection.Dynamic I only see registration of dynamic clients and informers (due to codegen/cargo culting with no actual use).

The only downstream dependency that seems to setup the context with a dynamic client is tekton triggers

cache/github.com/tektoncd/triggers@v0.24.0/cmd/eventlistenersink/main.go:	ctx = injection.Dynamic.SetupDynamic(ctx)

But then they setup the injection.Default Informers and clients overriding everything. So injection.Dynamic doesn't really have any usage.

Also based on #2210

One of the long-standing motivations for the injection-based controller architecture has been to enable us to synthesize different backing implementations, which can be made available to controller constructors by substituting what foo.Get(ctx) accesses.

I agree with this statement but I would envision the implementation to just use the same object graph as injection.Default vs. a separate one

ie. I would setup things this way

import "context"
import "k8s.io/client-go/dynamic"
import "knative.dev/pkg/client/injection/kube/client"
import "knative.dev/pkg/injection/clients/dynamicclient"

func main() {
  ctx := context.Background()
  dc := dynamic.NewForConfigOrDie(cfg)

 ctx = context.WithValue(ctx, dynamicclient.Key{}, dynamic.NewForConfigOrDie(cfg))
 ctx = context.WithValue(ctx, client.Key{}, myOwnKubernetesWrapper{dc})

 ... := injection.Default.SetupInformers(ctx)
}

type myOwnKubernetesWrapper struct {
   dc *dynamic.Client
}

var _ kubernetes.Interface = (*myOwnKubernetesWrapper)(nil)

Based on all this I'm inclined to delete the wrapped client, the informers, and injection.Dynamic - it should be fairly trivial to just remove registrations downstream (cause it's all done via codegen)

from pkg.

pierDipi avatar pierDipi commented on September 23, 2024

Thanks for the assessment @dprotaso !

from pkg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.