Skip to content

move apiserver source to eventing#1108

Merged
knative-prow-robot merged 1 commit into
knative:masterfrom
lionelvillard:apiserversource
May 1, 2019
Merged

move apiserver source to eventing#1108
knative-prow-robot merged 1 commit into
knative:masterfrom
lionelvillard:apiserversource

Conversation

@lionelvillard
Copy link
Copy Markdown
Contributor

@lionelvillard lionelvillard commented Apr 26, 2019

Proposed Changes

  • Move Apiserver source eventing, in pkg/[adapter,reconciler]

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Apr 26, 2019
@knative-prow-robot knative-prow-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Apr 26, 2019
@knative-prow-robot knative-prow-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 26, 2019
@knative-prow-robot
Copy link
Copy Markdown
Contributor

Hi @lionelvillard. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

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.

Copy link
Copy Markdown
Contributor

@vaikas vaikas left a comment

Choose a reason for hiding this comment

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

Thanks for doing this! Super useful!!!

type: object
spec:
properties:
serviceAccountName:
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 we add a "description" to all these fields? Most of the existing ones don't specify them, but we should so that you get a more descriptive message what these fields are. This can be done as a follow on, just jotting it down as I see them.

Comment thread pkg/adapter/apiserver/adapter.go Outdated
for {
stri := strconv.Itoa(i)

apiVersion, defined := os.LookupEnv(envAPIVersion + stri)
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'd use this package for env variables.
"github.com/kelseyhightower/envconfig"

You can see a use here:
https://github.com/vaikas-google/twitter/blob/master/cmd/source/main.go#L26

Filing an issue and doing in a follow up is totes fine. If you do this, please tag it as good first issue.


// OwnerReferences is the list of dependents to watch.
// Only APIVersion and Kind are used. The other fields are ignored.
OwnerReferences []metav1.OwnerReference `json:"ownerReferences"`
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.

Why is this OwnerReference instead of ObjectReference?

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.

Because of the Controller field in OwnerReference. It's not currently used but eventually it will.

Comment thread cmd/apiserver_receive_adapter/main.go Outdated

"github.com/knative/eventing/pkg/adapter/apiserver"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"sigs.k8s.io/controller-runtime/pkg/client/config"
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.

We're getting rid of the controller-runtime, so this should really be using the knative/pkg controller. I'd really prefer to do this before merging so we don't then have to migrate it later. Thoughts?

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 thought I could get away with this since this belongs to the receiver only. I'm fine removing the dependency on controller-runtime and migrate to pkg/controller

Out of curiosity, what the rationale behind the decision of getting rid of controller-runtime?

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.

Comment thread pkg/adapter/apiserver/adapter.go Outdated
return err
}

// Create one controller per watch
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.

Why are we creating controllers for everything and not just create cache informers for each one that we care about? handler is all the same?

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 handler state is not the same: the gvk is different. Maybe by using pkg/controller we can use one controller.

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 was trying to say that we do not need a controller at all. You can just construct a duck type that watches for duck type that's type/objectmeta and just register handlers for each of them. So, in your main you'd construct a kubeclient (like the k8s watcher does today), then create a dynamic client:

"k8s.io/client-go/dynamic"
dynamicClient, err := dynamic.NewForConfig(cfg)

Then for each type that you need, you'd create one of these:
tif := &duck.TypedInformerFactory{
Client: dynamicClient,
Type: &<DUCK_TYPE_FOR_ALL_OBJECTS>,
ResyncPeriod: resyncPeriod,
StopChannel: stopCh,
}

for each of the watched object gvk {
gvr, _ := meta.UnsafeGuessKindToResource(gvk)
informer, lister, err := psif.Get(gvr)

informer.AddEventHandler(AddFunc: messageSender, UpdateFunc: messageSender, DeleteFunc: messageSender)

}

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.

We still need to create a controller in order to process multiple events concurrently. processorListener runs in one go routine only. Am I missing something?

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 think we need at least one deployment per service account. It could be something we optimize later.

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.

yes I agree

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.

Ok I understand what Ville is saying a bit better now. The issue here is there is no need for the controller. This can just be a kube client and a dynamic.Interface that sets up duck.TypedInformerFactory

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.

Also, don't use processorListener, use the informer cache.

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'm using the informer cache directly which under the cover uses processorListener. I also refactored the code to use dynamic.Interface and duck.TypedInformerFactory (not pushed yet). I still think the controller is needed to process events concurrently.

apiserversource.NewController(
opt,
apiserverSourceInformer,
deploymentInformer,
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.

Could we just pass the RA Image here instead of buried in the controller?

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 this is a general issue applying to other sources, like cronjob

Comment thread pkg/adapter/apiserver/adapter.go Outdated
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/client"
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 we change this to use knative/pkg controller instead of controller runtime?

return nil
}

func (r *Reconciler) getReceiveAdapterImage() string {
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'd prefer that we grab this in the main package and fail there if it's not around. Also I'd prefer we pass it into this method directly instead of panicing here.

Copy link
Copy Markdown
Contributor Author

@lionelvillard lionelvillard Apr 26, 2019

Choose a reason for hiding this comment

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

I guess this is a general issue applying to other sources, like cronjob

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.

Yeah, seems bad to me :) We should fix them all.

@vaikas
Copy link
Copy Markdown
Contributor

vaikas commented Apr 26, 2019

/ok-to-test

@knative-prow-robot knative-prow-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 26, 2019
@n3wscott
Copy link
Copy Markdown
Contributor

FYI knative/docs#1235

@lionelvillard lionelvillard changed the title move apiserver source to eventing WIP: move apiserver source to eventing Apr 30, 2019
@knative-prow-robot knative-prow-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 30, 2019
@lionelvillard lionelvillard force-pushed the apiserversource branch 2 times, most recently from 1d70833 to 079f278 Compare April 30, 2019 14:52
@lionelvillard
Copy link
Copy Markdown
Contributor Author

@vaikas-google @n3wscott I removed the dependency on controller-runtime. I'm still using controllers for the reasons stated above. I'm happy to revisit the decision if needed.

I didn't implemented any e2e tests yet. I'm not sure yet how to do that.

@lionelvillard lionelvillard force-pushed the apiserversource branch 2 times, most recently from 1cde8ee to 7bd6551 Compare April 30, 2019 21:28

event := cloudevents.Event{
Context: cloudevents.EventContextV02{
ID: string(object.GetUID()),
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.

object.GetUID() will always return the same value so the cloudevent will not be unique.

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.

it satisfies https://github.com/cloudevents/spec/blob/v0.2/spec.md#id constraints, in particular MUST be unique within the scope of the producer. @n3wscott what is your concern?

@n3wscott
Copy link
Copy Markdown
Contributor

the error is eventing is out of date. Please run hack/update-codegen.sh

@knative-metrics-robot
Copy link
Copy Markdown

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

File Old Coverage New Coverage Delta
pkg/adapter/apiserver/adapter.go Do not exist 44.8%
pkg/apis/sources/v1alpha1/apiserver_lifecycle.go Do not exist 81.8%
pkg/apis/sources/v1alpha1/register.go Do not exist 100.0%
pkg/reconciler/apiserversource/apiserversource.go Do not exist 61.9%
pkg/reconciler/apiserversource/resources/labels.go Do not exist 0.0%
pkg/reconciler/apiserversource/resources/receive_adapter.go Do not exist 100.0%

@lionelvillard lionelvillard changed the title WIP: move apiserver source to eventing move apiserver source to eventing May 1, 2019
@knative-prow-robot knative-prow-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 1, 2019
@n3wscott
Copy link
Copy Markdown
Contributor

n3wscott commented May 1, 2019

Thanks a bunch! I think we should start with this and try it out, add some e2e tests...

/lgtm
/approve

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label May 1, 2019
@knative-prow-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lionelvillard, n3wscott

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 May 1, 2019
@n3wscott
Copy link
Copy Markdown
Contributor

n3wscott commented May 1, 2019

As a follow-up can you delete the api server source from eventing-sources?

@knative-prow-robot knative-prow-robot merged commit c7f1582 into knative:master May 1, 2019
@lionelvillard lionelvillard deleted the apiserversource branch January 20, 2020 14:58
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. cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. 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.

6 participants