Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to using generated reconcilers #733

Merged
merged 1 commit into from
Sep 8, 2020
Merged

Conversation

dibyom
Copy link
Member

@dibyom dibyom commented Aug 28, 2020

Changes

Using genreconciler from knative/pkg should reduce the amount of boilerplate we
need to write a reconciler. One change I had to make to use genreconciler
is to add a Finalizer for deleting the logging config maps when an
EventListener is deleted.

Fixes #635

/kind misc

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

See the contribution guide for more details.

Release Notes

    Triggers reconciler now emits K8s events on reconciliation failures.

@tekton-robot tekton-robot added the kind/misc Categorizes issue or PR as a miscellaneuous one. label Aug 28, 2020
@tekton-robot tekton-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 28, 2020
@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/v1alpha1/eventlistener/eventlistener.go 73.7% 74.1% 0.4

@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/v1alpha1/eventlistener/eventlistener.go 73.7% 75.3% 1.6

@tekton-robot tekton-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 28, 2020
@dibyom
Copy link
Member Author

dibyom commented Aug 28, 2020

/assign @khrm
/cc @n3wscott

@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/v1alpha1/eventlistener/eventlistener.go 73.7% 75.3% 1.6

@dibyom
Copy link
Member Author

dibyom commented Aug 28, 2020

/test pull-tekton-triggers-integration-tests

@dibyom
Copy link
Member Author

dibyom commented Aug 28, 2020

/hold

Two potential issues:

  1. Sometimes we never set the ServiceExists status.Condition
  2. Some logs with the following message:
    {"level":"warn","logger":"controller","caller":"eventlistener/reconciler.go:190","msg":"Failed to update resource status","knative.dev/traceid":"461c4c63-7ea9-4def-86f6-13faba05254c","knative.dev/key":"arrakis-49bxn/my-eventlistener","targetMethod":"FinalizeKind","error":"resource name may not be empty"}

@tekton-robot tekton-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 28, 2020

// Don't modify the informer's copy
el := original.DeepCopy()
func (r *Reconciler) ReconcileKind(ctx context.Context, el *v1alpha1.EventListener) pkgreconciler.Event {
// Initial reconciliation
if equality.Semantic.DeepEqual(el.Status, v1alpha1.EventListenerStatus{}) {

Choose a reason for hiding this comment

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

this will never happen with the genreconciler, there is a pre-step (you can opt out) that will call InitializeConditions for you and it marks the generation after you return. It also will expose an error if you reconcile and do nothing (you need to call a mark method)

Copy link
Member Author

Choose a reason for hiding this comment

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

Interesting, I was following the generated stub: https://github.com/tektoncd/triggers/pull/733/files#diff-2518496f4b5a085db3dc51c69af781c2R52

Is there a newer version which calls the IntializeConditions? (This is the older version of genreconciler I think, before leader elections etc.)

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed. calling InitializeConditions in the ReconcileKind each time now

},
},
}
existingService, err := c.KubeClientSet.CoreV1().Services(el.Namespace).Get(el.Status.Configuration.GeneratedResourceName, metav1.GetOptions{})
existingService, err := r.KubeClientSet.CoreV1().Services(el.Namespace).Get(el.Status.Configuration.GeneratedResourceName, metav1.GetOptions{})

Choose a reason for hiding this comment

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

this is a direct api call, you likely want to avoid doing this and use a lister and informer instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed!

@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/v1alpha1/eventlistener/eventlistener.go 73.7% 75.5% 1.8

@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/v1alpha1/eventlistener/eventlistener.go 73.7% 75.5% 1.8

@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/v1alpha1/eventlistener/eventlistener.go 73.7% 75.5% 1.8

@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/v1alpha1/eventlistener/eventlistener.go 74.1% 75.9% 1.8

@dibyom
Copy link
Member Author

dibyom commented Sep 1, 2020

/hold cancel

@tekton-robot tekton-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 1, 2020
@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/v1alpha1/eventlistener/eventlistener.go 74.1% 76.0% 1.9

Copy link
Contributor

@savitaashture savitaashture left a comment

Choose a reason for hiding this comment

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

PR looks good to me 👍

I have few minor comments

@@ -4,6 +4,7 @@ run:
skip-dirs:
- vendor
- pkg/client/clientset/(.*)/fake
- pkg/client/injection
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason to skip only injection 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, so injection contains generated code container boilerplate for the reconciler. There were some lint errors I think that was causing the build tests to fail. It doesn't really make sense to fix generated code since it will be overwritten the next time we generate the code so I marked it as ignored from the linter.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right i totally agree with you.
One more point is along with injection i see most of the code from pkg/client contains generated code so is that okay if we skip all like pipeline https://github.com/tektoncd/pipeline/blob/master/.golangci.yml#L33 so that it gives clear information why we are skipping

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question: So pkg/client is mostly generated code but one folder is not: https://github.com/tektoncd/triggers/tree/master/pkg/client/dynamic/clientset

Copy link
Contributor

Choose a reason for hiding this comment

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

ah i see the will leave the way you did 👍

pkg/reconciler/v1alpha1/eventlistener/eventlistener.go Outdated Show resolved Hide resolved
TriggersClientSet triggersclientset.Interface

// CachingClientSet allows us to instantiate Image objects
CachingClientSet cachingclientset.Interface
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see any usage of CachingClientSet can we remove this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch :) I think this is a left over from copying over from the Pipelines controller

Copy link
Member Author

Choose a reason for hiding this comment

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

Turns out removing this also removes some dependencies on knative/pkg/caching!

pkg/reconciler/v1alpha1/eventlistener/eventlistener.go Outdated Show resolved Hide resolved
pkg/reconciler/v1alpha1/eventlistener/eventlistener.go Outdated Show resolved Hide resolved
pkg/reconciler/v1alpha1/eventlistener/eventlistener.go Outdated Show resolved Hide resolved
pkg/reconciler/v1alpha1/eventlistener/eventlistener.go Outdated Show resolved Hide resolved
pkg/reconciler/v1alpha1/eventlistener/eventlistener.go Outdated Show resolved Hide resolved
pkg/reconciler/v1alpha1/eventlistener/eventlistener.go Outdated Show resolved Hide resolved
Using genreconciler from knative/pkg should reduce the amount of boilerplate we
need to write a reconciler.

* Migrates the logic for deleting logging config maps to a finalizer
* Uses listers to get existing deployment, service, configMap instead
of making direct API calls.

Fixes tektoncd#635

Signed-off-by: Dibyo Mukherjee <dibyo@google.com>
@tekton-robot tekton-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Sep 2, 2020
@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/v1alpha1/eventlistener/eventlistener.go 74.1% 75.5% 1.3

Copy link
Member

@wlynch wlynch left a comment

Choose a reason for hiding this comment

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

LGTM! One minor comment.

/lgtm

c.Logger.Info("Setting up event handlers")
impl := eventlistenerreconciler.NewImpl(ctx, c, func(impl *controller.Impl) controller.Options {
return controller.Options{
AgentName: ControllerName,
Copy link
Member

Choose a reason for hiding this comment

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

Knative docs are a bit unclear here- is this the HTTP user agent that's used? If so, should we make this a little bit more specific so we can ID specific event listeners (e.g. incl namespace/EL name?)

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, this is just for the controller and not the actual HTTP agent name for the sinks.

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 2, 2020
@dibyom dibyom added kind/feature Categorizes issue or PR as related to a new feature. and removed kind/misc Categorizes issue or PR as a miscellaneuous one. labels Sep 3, 2020
@tekton-robot tekton-robot added the kind/misc Categorizes issue or PR as a miscellaneuous one. label Sep 3, 2020
@savitaashture
Copy link
Contributor

/lgtm

@tekton-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: khrm

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

The pull request process is described here

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

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 8, 2020
@tekton-robot tekton-robot merged commit 6372f4f into tektoncd:master Sep 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/feature Categorizes issue or PR as related to a new feature. kind/misc Categorizes issue or PR as a miscellaneuous one. lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pick up genreconciler
6 participants