Skip to content
This repository was archived by the owner on Jun 4, 2021. It is now read-only.

Use CR unstructured client for dynamic objects#137

Merged
knative-prow-robot merged 5 commits into
knative:masterfrom
grantr:unstructured-client
Dec 5, 2018
Merged

Use CR unstructured client for dynamic objects#137
knative-prow-robot merged 5 commits into
knative:masterfrom
grantr:unstructured-client

Conversation

@grantr
Copy link
Copy Markdown
Contributor

@grantr grantr commented Dec 3, 2018

Since kubernetes-sigs/controller-runtime#101, controller-runtime will create and manage dynamic clients when given unstructured.Unstructured objects with a filled in TypeMeta. Using this allows us to eliminate the dynamic clients created to deal with Addressable objects.

Also updates tests to call the interface Addressable instead of Sinkable.

No longer need to create dynamic clients. CR will do this for
us internally based on the TypeMeta of the unstructured object.

Also updates tests to call the interface Addressable instead of
Sinkable.
@knative-prow-robot knative-prow-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Dec 3, 2018
@knative-prow-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: grantr

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 3, 2018
Comment thread pkg/controller/sdk/provider.go Outdated
Reconcile(ctx context.Context, object runtime.Object) (runtime.Object, error)
InjectClient(c client.Client) error
//TODO(grantr) make these separate interfaces
InjectConfig(c *rest.Config) error
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does anything need this anymore? I thought it was only used for the dynamic client.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had originally pulled this out into a separate PR, but it was complicated to make this change separately. Further commits forthcoming.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/hold cancel

PTAL.

@grantr
Copy link
Copy Markdown
Contributor Author

grantr commented Dec 3, 2018

/hold
for update to sdk reconciler interface.

@knative-prow-robot knative-prow-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 3, 2018
Can use the standard CR client now that it supports unstructured
objects.
CR provides interfaces and helpers to detect when injection is possible.
@knative-prow-robot knative-prow-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 3, 2018

type KnativeReconciler interface {
Reconcile(ctx context.Context, object runtime.Object) (runtime.Object, error)
InjectClient(c client.Client) error
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised this line can be removed. Are any of these reconcilers viable without a client?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inject.ClientInto method will detect if the reconciler implements InjectClient and call it if so.

There's no need to require this method in the interface because there are other ways of injecting the client. For example, in pkg/controller/containersource/provider.go:

   p := &sdk.Provider{
     AgentName: controllerAgentName,
     Parent:    &v1alpha1.ContainerSource{},
     Owns:      []runtime.Object{&appsv1.Deployment{}},
     Reconciler: &reconciler{
       recorder: mgr.GetRecorder(controllerAgentName),
       scheme:   mgr.GetScheme(),
+      client:  mgr.GetClient(),
     },
   }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So my preference is to continue to require it in the interface. You are right that there are other ways to do it, but do they provide any advantages?

If an author forgets to somehow inject the client (via whichever method they prefer), then this controller will fail at runtime. And even then, only after the controller is trying to do something. I'm a fan of keeping this a compile-time error 😄

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the advantage of the field setter is that it's slightly more obvious when the client value is set and where it comes from. I don't have a strong preference either way though, so I added it back.

This is intended to make forgetting to inject a client a compile
error instead of a runtime error.
@@ -216,7 +214,5 @@ func (r *reconciler) InjectClient(c client.Client) error {
}

func (r *reconciler) InjectConfig(c *rest.Config) error {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be removed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Copy Markdown
Contributor

@Harwayne Harwayne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 5, 2018
@knative-metrics-robot
Copy link
Copy Markdown

The following is the coverage report on pkg/.
Say /test pull-knative-eventing-sources-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/controller/containersource/reconcile.go 93.7% 93.4% -0.2
pkg/controller/gcppubsub/reconcile.go 94.7% 94.5% -0.2
pkg/controller/githubsource/reconcile.go 90.2% 89.9% -0.3
pkg/controller/sinks/sinks.go 95.5% 93.8% -1.7

@knative-prow-robot knative-prow-robot merged commit 6ebd60a into knative:master Dec 5, 2018
@grantr grantr deleted the unstructured-client branch December 6, 2018 18:44
grantr added a commit to grantr/eventing-contrib that referenced this pull request Jan 11, 2019
The controllers written before knative#137 are reverted to use the dynamic
client. More recent controllers cronjobsource and awssqssource use
the controller-runtime client still, since there was never a version of
them that used the dynamic client.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants