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

Enhance existing eventlistener to support PodTemplate for Deployment using duck type #734

Merged
merged 1 commit into from
Sep 21, 2020

Conversation

savitaashture
Copy link
Contributor

@savitaashture savitaashture commented Aug 31, 2020

Changes

Fix: #727

As described in the issue the feature is part of TEP and addresses supporting podtemplate duck type to kubernetes resources.

Signed-off-by: Savita Ashture sashture@redhat.com

/kind feature

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

A new field resources has been introduced as part of EventListener spec

apiVersion: triggers.tekton.dev/v1alpha1
kind: EventListener
metadata:
  name: github-listener-interceptor
spec:
  triggers:
    ...
  resources:
    kubernetesResource:
      serviceType: NodePort
      spec:
        template:
          metadata:
            labels:
              key: "value"
            annotations:
              key: "value"
          spec:
            serviceAccountName: tekton-triggers-github-sa
            nodeSelector:
              app: test
            tolerations:
              - key: key
                value: value
                operator: Equal
                effect: NoSchedule

resources field mainly contains information that whether the resource is built in kubernetes or custom

As of now resources field support kubernetesResource which helps to use PodSpecable ducktype and with the help of ducktype can avoid specifying serviceAccountName, serviceType and podTemplate as part of eventlistener spec

As of now for backward compatibility both way supported and resources are optional.

Once we deprecate old way then resources field becomes mandatory if anyone wants to specify serviceAccountName, serviceType and podSpec.

Advantages

  1. Including kubernetesResource as part of resources helps to make use of PodSpecable duck type
    and this way we can avoid hardcoding of podSpec fields as part of podTemplate.

  2. Including customResource as part of resources will help triggers to make use of any CRD ex: Knative Service which helps triggers to get the serverless functionality.
    this is not supported as part of this PR but will continue as part of this TEP

@tekton-robot tekton-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Aug 31, 2020
@savitaashture
Copy link
Contributor Author

/cc @dibyom

@tekton-robot tekton-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Aug 31, 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/apis/triggers/v1alpha1/event_listener_validation.go 93.4% 95.4% 1.9
pkg/reconciler/v1alpha1/eventlistener/eventlistener.go 73.7% 75.4% 1.7
test/builder/eventlistener.go 78.8% 81.5% 2.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/apis/triggers/v1alpha1/event_listener_validation.go 93.4% 95.4% 1.9
pkg/reconciler/v1alpha1/eventlistener/eventlistener.go 73.7% 75.4% 1.7
test/builder/eventlistener.go 78.8% 81.5% 2.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/apis/triggers/v1alpha1/event_listener_validation.go 93.4% 95.4% 1.9
pkg/reconciler/v1alpha1/eventlistener/eventlistener.go 73.7% 75.4% 1.7
test/builder/eventlistener.go 78.8% 81.5% 2.8

@zxDiscovery
Copy link

@savitaashture: PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@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/apis/triggers/v1alpha1/event_listener_validation.go 93.4% 95.4% 1.9
pkg/reconciler/v1alpha1/eventlistener/eventlistener.go 74.1% 75.8% 1.6
test/builder/eventlistener.go 78.8% 81.5% 2.8

@dibyom
Copy link
Member

dibyom commented Sep 1, 2020

@savitaashture are you planning on getting this for v0.8 or v0.9?

@zxDiscovery
Copy link

@savitaashture: PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@tekton-robot tekton-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 8, 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/apis/triggers/v1alpha1/event_listener_validation.go 100.0% 97.8% -2.2
pkg/reconciler/v1alpha1/eventlistener/eventlistener.go 76.2% 78.3% 2.1

@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/apis/triggers/v1alpha1/event_listener_validation.go 100.0% 97.8% -2.2
pkg/reconciler/v1alpha1/eventlistener/eventlistener.go 76.2% 78.3% 2.1
test/builder/eventlistener.go 79.3% 81.9% 2.6

@tekton-robot tekton-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 13, 2020
@savitaashture savitaashture changed the title Enhance existing eventlistener to support PodTemplate for Deployment using duck type [WIP] Enhance existing eventlistener to support PodTemplate for Deployment using duck type Sep 13, 2020
@tekton-robot tekton-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Sep 13, 2020
@savitaashture savitaashture changed the title [WIP] Enhance existing eventlistener to support PodTemplate for Deployment using duck type Enhance existing eventlistener to support PodTemplate for Deployment using duck type Sep 13, 2020
@tekton-robot tekton-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 13, 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 76.2% 78.3% 2.1
test/builder/eventlistener.go 79.3% 81.9% 2.6

@tekton-robot tekton-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Sep 13, 2020
@tekton-robot tekton-robot removed the do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. label Sep 13, 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 76.2% 78.3% 2.1
test/builder/eventlistener.go 79.3% 81.9% 2.6

docs/eventlisteners.md Outdated Show resolved Hide resolved
docs/eventlisteners.md Outdated Show resolved Hide resolved
docs/eventlisteners.md Outdated Show resolved Hide resolved
docs/eventlisteners.md Outdated Show resolved Hide resolved
// for backward compatibility with original behavior
var serviceType = el.Spec.ServiceType
if el.Spec.Resources.KubernetesResource != nil && el.Spec.Resources.KubernetesResource.ServiceType != "" {
serviceType = el.Spec.Resources.KubernetesResource.ServiceType
Copy link
Member

Choose a reason for hiding this comment

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

Do we also want to add some defaulting logic in el.SetDefaults to change el.Spec.ServiceType to el.Spec.Resources.KubernetesResource.ServiceType?

Copy link
Contributor Author

@savitaashture savitaashture Sep 16, 2020

Choose a reason for hiding this comment

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

I think we don't require because even if ServiceType is empty k8s itself set ClusterIP as default

WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, what I meant by defaulting is something like

  if el.Spec.ServiceType != nil {
    el.Spec.Resources.KubernetesResource.ServiceType = el.Spec.ServiceType

This is so that we can deprecate/remove the el.Spec.ServiceType field later.

pkg/reconciler/v1alpha1/eventlistener/eventlistener.go Outdated Show resolved Hide resolved
serviceAccountName string
)
podlabels = mergeMaps(el.Labels, GenerateResourceLabels(el.Name))

Copy link
Member

Choose a reason for hiding this comment

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

same comment as with serviceType -> it seems like we could also do some of this in the webhook via EL's SetDefaults.

if el.Spec.Resources.KubernetesResource.Template.Spec.ServiceAccountName != "" {
serviceAccountName = el.Spec.Resources.KubernetesResource.Template.Spec.ServiceAccountName
}
annotations = el.Spec.Resources.KubernetesResource.Template.Annotations
Copy link
Member

Choose a reason for hiding this comment

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

Don't we also have to mergeMaps for annotations too like we do in 7622d51

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel we don't require here because these are part of deployment.spec.template.metadata and there won't be any annotations which are added by k8s, So we don't get continuous loop issue.

So deployment.spec.template.metadata.annotation will add/update to annotations value if provided as part of el.Spec.Resources.KubernetesResource.Template.Annotations

even if user manually edit those directly on deployment it will not allow same like others.

Let me know if you have some other point to address

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, yeah you are right...I was confusing deployment.spec.template.metadata.annotations with deployment.metadata.annotations. I think this is fine then 👍

Kind of off topic, the reconciler code is getting kind of long and unwieldy, we might want to see how we can refactor/clean it up a bit. I'll open an issue.

@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 76.2% 77.6% 1.4
test/builder/eventlistener.go 79.3% 81.9% 2.6

@@ -313,3 +320,37 @@ func EventListenerCELOverlay(key, expression string) EventInterceptorOp {
}
}
}

// EventListenerResources set specified resources to the EventListener.
Copy link
Member

Choose a reason for hiding this comment

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

In pipelines, we've been trying to get rid of test builders and use structs as much as possible. For our reconciler tests too, we've started using single make(EL/Deployment/Service) functions. I think its ok to keep for now, but later we might end up removing builders just like in Pipeline.

@dibyom
Copy link
Member

dibyom commented Sep 17, 2020

Just a couple of small unresolved issues around defaulting (I think its ok to add them in a follow up if you want!)
/approve

@tekton-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dibyom

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 17, 2020
@savitaashture
Copy link
Contributor Author

Just a couple of small unresolved issues around defaulting (I think its ok to add them in a follow up if you want!)

I shall add it in follow up PR

Thank you 👍

@dibyom
Copy link
Member

dibyom commented Sep 21, 2020

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 21, 2020
@tekton-robot tekton-robot merged commit 8d2ba7d into tektoncd:master Sep 21, 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. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. 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.

Enhance existing eventlistener to support PodTemplate for Deployment using duck type
4 participants