Skip to content

GitHub Receive adapter as a serving Service.#276

Merged
mattmoor merged 26 commits into
knative:masterfrom
n3wscott:github_channel_service
Aug 10, 2018
Merged

GitHub Receive adapter as a serving Service.#276
mattmoor merged 26 commits into
knative:masterfrom
n3wscott:github_channel_service

Conversation

@n3wscott
Copy link
Copy Markdown
Contributor

Fixes #208

@google-prow-robot google-prow-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Jul 24, 2018
@n3wscott n3wscott changed the title GitHub Receive adapter as a serving Service. Managed by a feedlet. [WIP] GitHub Receive adapter as a serving Service. Managed by a feedlet. Jul 24, 2018
@google-prow-robot google-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 Jul 24, 2018
Comment thread pkg/controller/flow/flow.go Outdated
serviceName, ok := statusMap[targetFieldName]
if !ok {
return "", fmt.Errorf("%q does not contain field %q in status", targetFieldName, ref.Name)
return "", fmt.Errorf("%q/%q does not contain field %q in status", ref.Kind, ref.Name, targetFieldName)
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.

you probably don't want %q/%q here because then both are quoted? Maybe just:
%s/%s

Comment thread pkg/controller/flow/flow.go Outdated
serviceNameStr, ok := serviceName.(string)
if !ok {
return "", fmt.Errorf("%q status field %q is not a string", targetFieldName, ref.Name)
return "", fmt.Errorf("%q status field %q/%q is not a string", targetFieldName, ref.Kind, ref.Name)
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.

ditto.

Comment thread pkg/sources/github/eventsource.yaml Outdated
source: github
image: github.com/knative/eventing/pkg/sources/github
parameters:
image: github.com/knative/eventing/pkg/sources/github/receive_adapter No newline at end of file
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.

nit: looks like it's missing a newline here?

Comment thread sample/github/auth.yaml
namespace: default
roleRef:
kind: ClusterRole
name: cluster-admin
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.

Since you're making such big changes anyway, can you look at the changes that @evankanderson did for tightening up the rules for k8s events when he moved it under knative/docs/eventing and make it stricter here too.

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 took a look at those examples and I ... need to learn more about rbac. I am not sure how to do the same thing for this PR yet. Maybe @evankanderson can help me?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If you know what objects the service account is going to use in Kubernetes, you can basically just make a list.

You can start with create-deployment and feed-sa-deploy from the k8sevents/serviceaccount.yaml. Since you're using a service.serving.knative.dev resource, you'll probably need to add that to the list of rules on the create-deployment Role. (You'll probably also want to pick a different name.)

Comment thread sample/github/feed.yaml Outdated
@@ -15,19 +15,35 @@
apiVersion: feeds.knative.dev/v1alpha1
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 shouldn't need a feed.yaml with flow.yaml anymore.

knative.dev/type: function
spec:
container:
image: github.com/knative/eventing/sample/github
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 make the github function actually then talk back to the github to modify something like it did before?

@n3wscott
Copy link
Copy Markdown
Contributor Author

@vaikas-google I updated the sample to do what it did before now but it does not run as the github lib wehbook but just a normal webhook.. And then my cluster went craycray today and istio is just throwing 503's for posting to the channel... idk more tomorrow.

@google-prow-robot google-prow-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 Jul 26, 2018
@n3wscott n3wscott changed the title [WIP] GitHub Receive adapter as a serving Service. Managed by a feedlet. GitHub Receive adapter as a serving Service. Managed by a feedlet. Jul 26, 2018
@google-prow-robot google-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 Jul 26, 2018
@n3wscott
Copy link
Copy Markdown
Contributor Author

/assign @inlined

@n3wscott n3wscott changed the title GitHub Receive adapter as a serving Service. Managed by a feedlet. GitHub Receive adapter as a serving Service. Jul 26, 2018
Copy link
Copy Markdown
Contributor

@inlined inlined left a comment

Choose a reason for hiding this comment

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

Generally LGTM. As a follow-up, I think we should consider the trouble we have setting up GitHub's webhook to be a pretty common case & simplify it in the core infra. E.g. I think we should copy or factor out what serving does with its single ingress. I also have mixed feelings about the event source being implemented as a Service. On one hand, this lets the system scale down to zero. On the other hand, this means that eventing will never break its dependency on serving. At minimum, I'd want to move this event source out of the core repo.

Comment thread pkg/sources/github/feedlet.go Outdated
postfixReceiveAdapter = "rcvadptr"

// watchTimeout is the timeout that the feedlet will wait for the Receiver Adapter to get a domain name.
watchTimeout int64 = 60 * 5 // 5 minutes?
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.

Nit: time.Duration solves so many bugs by having unambiguous units and forced casts to primitives. I'd strongly prefer this to be

watchTimeout = 5 * time.Minute

and it to be used below as

TimeoutSeconds: int64(watchTimeout / time.Second)

Comment thread pkg/sources/github/feedlet.go Outdated
// watchTimeout is the timeout that the feedlet will wait for the Receiver Adapter to get a domain name.
watchTimeout int64 = 60 * 5 // 5 minutes?

//// secretName is the name of the secret that contains the GitHub credentials.
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 the double comments?

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.

copy pasta

Comment thread pkg/sources/github/feedlet.go Outdated
glog.Error("no Webhook ID Found, bailing...")
return nil
}
webhookID := feedContext.Context[webhookIDKey].(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.

As a matter of practice, I wonder if we should
A) Always , ok our casts. What if this somehow got corrupted? I'm glad you caught the nil case above since that had caused GCP Pub/Sub flows to be undeleteable.
B) Invest in certain framework safeguards (e.g. bail on N panics)

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 fixed and added a todo to elevate the helper method to pkg.

Comment thread pkg/sources/github/feedlet.go Outdated
}
webhookID := feedContext.Context[webhookIDKey].(string)

ctx := context.Background()
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.

Not something to fix in this PR, but this again makes me wonder if base libraries should own the root context.Context. Why isn't there a timeout for example?

Comment thread pkg/sources/github/feedlet.go Outdated
return nil
}
}
glog.Errorf("gailed to delete the webhook: %#v", err)
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.

s/gailed/failed

Also, %#v will ignore the error interface format rules. You'll also get pointer addresses instead of actually following anything. https://play.golang.org/p/bNajvEDPpv5

Comment thread pkg/sources/github/feedlet.go Outdated
hook := ghclient.Hook{
Name: &name,
URL: &domain,
Events: []string{"pull_request"},
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.

This should be dynamic. We're going to need a map from our CloudEvents types to their native types. Feel free to do a TODO for now I guess or use the trigger.EventType.

// odd that you have to also pass context around for the
// calls even after giving it to client. But, whatever.
ctx := context.Background()
//ts := oauth2.StaticTokenSource(
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.

Please yank commented out code

hook := github.New(&github.Config{Secret: credentials.SecretToken})
hook.RegisterEvents(h.HandlePullRequest, github.PullRequestEvent)

err = webhooks.Run(hook, ":8080", "/")
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.

Should we be using fmt.Sprintf(":%s", os.Getevn("PORT"))?

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.

left a TODO. not sure if it matters because this is not the port that is exposed

Comment thread sample/github/flow.yaml Outdated
target:
kind: Route
apiVersion: serving.knative.dev/v1alpha1
name: legit No newline at end of file
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.

nit: trailing newline

Comment thread sample/github/githubsecret.yaml Outdated
"accessToken": "<YOUR PERSONAL TOKEN FROM GITHUB>",
"secretToken": "<YOUR RANDOM STRING>"
}
} No newline at end of file
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.

nit: another trailing newline missing

@vaikas
Copy link
Copy Markdown
Contributor

vaikas commented Jul 27, 2018

@inlined re: using Service to implement github handler seems totally reasonable to me. It's an implementation detail of a particular receive adapter and not a hard dependency on eventing itself. I'd for example expect these sources to move out of this repo into somewhere else and not be part of the pkg/sources in eventing.

@inlined
Copy link
Copy Markdown
Contributor

inlined commented Jul 27, 2018

@vaikas-google Yeah, I assumed that this would leave the core repo which helps us meet the goal of breaking dependencies. It's hard to not want to use knative/serving; it's just too good a product!

@vaikas
Copy link
Copy Markdown
Contributor

vaikas commented Jul 27, 2018 via email

@inlined
Copy link
Copy Markdown
Contributor

inlined commented Aug 1, 2018

FYI I'm headed on vacation tonight. I don't want to leave you stuck with an AWOL reviewer.

/assign @vaikas-google

Copy link
Copy Markdown
Contributor Author

@n3wscott n3wscott 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 the great review @inlined !! Updated.

Comment thread pkg/sources/github/feedlet.go Outdated
// watchTimeout is the timeout that the feedlet will wait for the Receiver Adapter to get a domain name.
watchTimeout int64 = 60 * 5 // 5 minutes?

//// secretName is the name of the secret that contains the GitHub credentials.
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.

copy pasta

Comment thread pkg/sources/github/feedlet.go Outdated
glog.Error("no Webhook ID Found, bailing...")
return nil
}
webhookID := feedContext.Context[webhookIDKey].(string)
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 fixed and added a todo to elevate the helper method to pkg.

Comment thread pkg/sources/github/feedlet.go Outdated
return nil, err
}

glog.Infof("created Service: %+v", service)
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.

TODO added.

func receiveAdapterName(resource string) string {
serviceName := fmt.Sprintf("%s-%s-%s", "github", resource, postfixReceiveAdapter) // TODO: this needs more UUID on the end of it.
serviceName = strings.Replace(serviceName, "/", "-", -1)
serviceName = strings.Replace(serviceName, ".", "-", -1)
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.

resources can but there are limitations on knative service I think. I was getting errors for "." because I think it turns the name into a domain. and k8s service has some limitations in addition to k8s resources.

Comment thread pkg/sources/github/feedlet.go Outdated
return nil, nil
}

glog.Infof("secretName %s ; secretKey: %s", trigger.Parameters[secretName].(string), trigger.Parameters[secretKey].(string))
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.

That is not the secret value, but the k8s secret resource name and internal key to find the secret. But yes, I need to remove this.

hook := github.New(&github.Config{Secret: credentials.SecretToken})
hook.RegisterEvents(h.HandlePullRequest, github.PullRequestEvent)

err = webhooks.Run(hook, ":8080", "/")
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.

left a TODO. not sure if it matters because this is not the port that is exposed

@n3wscott
Copy link
Copy Markdown
Contributor Author

n3wscott commented Aug 1, 2018

/unassign @vaikas-google

Ville is on vacation for a couple weeks.

/assign @mattmoor

@google-prow-robot google-prow-robot assigned mattmoor and unassigned vaikas Aug 1, 2018
@n3wscott
Copy link
Copy Markdown
Contributor Author

n3wscott commented Aug 2, 2018

/test pull-knative-eventing-integration-tests

Comment thread sample/github/README.md Outdated

The `Flow` will accept the Webhook calls from GitHub and pass them to the _legit_ service.

The `Flow` will configure a Receive Adapter pod from the `
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.

Looks like there should be a link/name at the end of this sentence.

Comment thread sample/github/README.md Outdated
```

Then create a PR for the repo you configured the webhook for, and you'll see that the Title
will be modified with the suffix '(I buy it)'
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 buy it)' should be replaced with '(looks pretty legit)'.

@n3wscott n3wscott force-pushed the github_channel_service branch from d731ced to aa06033 Compare August 3, 2018 17:39
@n3wscott
Copy link
Copy Markdown
Contributor Author

n3wscott commented Aug 3, 2018

/assign @evankanderson

@inlined is on vacation for a bit

@n3wscott
Copy link
Copy Markdown
Contributor Author

n3wscott commented Aug 3, 2018

/test pull-knative-eventing-integration-tests

@n3wscott n3wscott force-pushed the github_channel_service branch from 8a1a833 to c8a5a6c Compare August 9, 2018 17:56
Copy link
Copy Markdown
Member

@evankanderson evankanderson left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

APIVersion: "v1alpha1",
},
FieldSelector: fmt.Sprintf("metadata.name=%s", serviceName),
LabelSelector: "receive-adapter=github",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we want to ever "adopt" an existing service if it's for another Flow? It seems like checking an OwnerReference would be the right way to avoid that. It would also make the cleanup easier.

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: evankanderson, grantr, 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 Aug 9, 2018
@n3wscott
Copy link
Copy Markdown
Contributor Author

/retest

@mattmoor
Copy link
Copy Markdown
Member

(I'm playing tide since it's gone fishing)

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. 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.

10 participants