Skip to content

Proof of concept GCP Pub Sub using a Receive Adapter#57

Merged
google-prow-robot merged 8 commits into
knative:masterfrom
vaikas:master
May 23, 2018
Merged

Proof of concept GCP Pub Sub using a Receive Adapter#57
google-prow-robot merged 8 commits into
knative:masterfrom
vaikas:master

Conversation

@vaikas
Copy link
Copy Markdown
Contributor

@vaikas vaikas commented May 22, 2018

Fixes Issue #

Proposed Changes

This is a checkpoint to provide a proof of concept for unbind and handling more complex receivers. Follow on work will be to yank out the inproc event sources and move them into containers.

  • Introduce a notion of a Receive Adapter (still in proc creation)
  • Add Unbind + Context is stashed in the Bind.Status.BindContext so we have enough context to perform unbind and clean up (remove the github webhook, gcp pubsub subscription for example)
  • Fix the route target resolve so the examples work
  • Add a function handler that receives GCP PubSub events as a target

@google-prow-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vaikas-google

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

@google-prow-robot google-prow-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels May 22, 2018
@vaikas vaikas requested review from grantr and mattmoor May 22, 2018 21:07
Comment thread sample/gcp_pubsub/receive_adapter.go Outdated
if err != nil {
log.Printf("Failed to post message: %s", err)
}
m.Ack()
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 it Nack on postMessage error? If route was down (cold start takes too long) that event would never be processed.

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.

yep, good call.

ctx := context.Background()

// Creates a client.
client, err := pubsub.NewClient(ctx, projectID)
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 the client creation assume the GOOGLE_APPLICATION_CREDENTIALS env var is defined with the gloabal service account here?

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.

currently it uses whatever the GKE has, added a TODO for it.

Copy link
Copy Markdown
Member

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

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

I'm not really sure how picky I should be on this repo, especially given the "PoC" in the PR title. :)

I did a pass with some comments, will do another later.

Comment thread sample/gcp_pubsub/receive_adapter.go Outdated
m.Ack()
})
if err != nil {
// Handle error.
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.

log.Fatalf?

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


URL := fmt.Sprintf("http://%s/", target)
log.Printf("Posting to %q", URL)
req, err := http.NewRequest("POST", URL, bytes.NewBuffer(jsonStr))
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.

You don't check err

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

elafros.dev/type: container
spec:
container:
image: gcp_pubsub_function:latest
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.

image: github.com/elafros/eventing/sample/gcp_pubsub_function (The BUILD file will also need this change)

Comment thread sample/gcp_pubsub/receive_adapter.go Outdated
URL := fmt.Sprintf("http://%s/", target)
log.Printf("Posting to %q", URL)
req, err := http.NewRequest("POST", URL, bytes.NewBuffer(jsonStr))
req.Header.Set("X-Ela-Header", "foovalue")
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.

What is this?

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.

removed.


type BindContext struct {
Context map[string]interface{}
}
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.

Why the extra level? Why not: type BindContext map[string]interface{}?

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 am under the impression that there might be some other context that controller will need that is in addition to the context that needs to be given to the event source (what it needs to unbind), but I think there's especially in the containerized workflow things like, what namespace the container running is. If you're ok with that reasoning, I'd like to leave it for now.

Comment thread pkg/sources/gcp_pubsub.go Outdated
}

// TODO: Create ownerref to the binding so when the binding goes away deployment
// gets removed. Currently we manually do this.
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 this" meaning delete the deployment?

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

if err != nil {
return nil, err
}
finalizers := sets.NewString(accessor.GetFinalizers()...)
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.

Will this roundtrip change ordering? IIUC initializers are ordered, so I'd guess the same is true for finalizers.


// Set the finalizer since the bind succeeded, we need to clean up...
// TODO: we should do this in the webhook instead...
bind.Finalizers = append(bind.ObjectMeta.Finalizers, controllerAgentName)
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.

Won't the use of finalizers make it harder to move this out-of-process? Why use finalizers in place of DELETE-sensitive webhooks?

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 don't think it will make it any harder. The controller should try to 'unbind' until it succeeds, then it will remove the finalizer. Why would the use of finalizers make it harder?

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.

When we explored initializers for Build the problem was that doing long operations synchronously with delete was problematic. If the expectation is that this will ultimately launch a container to perform this, then doing it on finalization may become problematic. Not sure if finalizers are a perfect mirror of initializers here.

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 don't think it applies here. We used the same pattern for Service Catalog, where deletion of resources can take awhile. Point of the finalizers is that we are telling k8s to not delete the real resources until we're done cleaning up (and then remove the finalizer), I think this is precisely what the finalizers are for?

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.

@vaikas
Copy link
Copy Markdown
Contributor Author

vaikas commented May 23, 2018

Thanks for the reviews, PTAL.

@mattmoor
Copy link
Copy Markdown
Member

/lgtm

I'm a little squeamish about PoCing in one of the main repos, but this one's young enough that it's a judgement call. I expect most of the code in this repo to turn over a handful more times before we call it good. :)

@google-prow-robot google-prow-robot added the lgtm Indicates that a PR is ready to be merged. label May 23, 2018
@google-prow-robot google-prow-robot merged commit e018ffd into knative:master May 23, 2018
dprotaso added a commit to dprotaso/eventing that referenced this pull request Sep 12, 2018
Includes the following changes
1e7c2e7 Update static_watcher.go
d688349 Include note about embedding the ManualWatcher in the InformedWatcher
767d6a5 Few changes to the configmap package
0122abd The test logger will now log the correct caller (knative#63)
e7a4b0d Dont call flag.parse in pkg/test (knative#62)
b213523 Update test-infra dependency (knative#61)
382a2bf Make kube_checks generic so that it can be used in serving (knative#58)
760afb6 cleanup (knative#57)
eedc0a9 Make verify-codegen.sh compatible with OS X (knative#54)
6eff182 Remove docker repo from e2e flags (knative#53)
4be5c07 Vendor the test-infra scripts (knative#52)
8c687df Update WaitForEndpointState to return response (knative#51)
8f6a3be Update knative/pkg/test (knative#50)
3ca4270 Add a logkey for the reconcile key. (knative#49)
62d2560 Add Istio DestinationRule and Policy into Istio apis and clients (knative#43)
f4a77d7 Add a common test clients file (knative#46)
450739d Add common test logging module (knative#45)
dprotaso added a commit to dprotaso/eventing that referenced this pull request Sep 12, 2018
Includes the following changes:
8fc80de Few changes to the configmap package (knative#59)
0122abd The test logger will now log the correct caller (knative#63)
e7a4b0d Dont call flag.parse in pkg/test (knative#62)
b213523 Update test-infra dependency (knative#61)
382a2bf Make kube_checks generic so that it can be used in serving (knative#58)
760afb6 cleanup (knative#57)
eedc0a9 Make verify-codegen.sh compatible with OS X (knative#54)
6eff182 Remove docker repo from e2e flags (knative#53)
4be5c07 Vendor the test-infra scripts (knative#52)
8c687df Update WaitForEndpointState to return response (knative#51)
8f6a3be Update knative/pkg/test (knative#50)
3ca4270 Add a logkey for the reconcile key. (knative#49)
62d2560 Add Istio DestinationRule and Policy into Istio apis and clients (knative#43)
f4a77d7 Add a common test clients file (knative#46)
450739d Add common test logging module (knative#45
knative-prow-robot pushed a commit that referenced this pull request Sep 17, 2018
* bump knative/pkg to 8fc80de

Includes the following changes:
8fc80de Few changes to the configmap package (#59)
0122abd The test logger will now log the correct caller (#63)
e7a4b0d Dont call flag.parse in pkg/test (#62)
b213523 Update test-infra dependency (#61)
382a2bf Make kube_checks generic so that it can be used in serving (#58)
760afb6 cleanup (#57)
eedc0a9 Make verify-codegen.sh compatible with OS X (#54)
6eff182 Remove docker repo from e2e flags (#53)
4be5c07 Vendor the test-infra scripts (#52)
8c687df Update WaitForEndpointState to return response (#51)
8f6a3be Update knative/pkg/test (#50)
3ca4270 Add a logkey for the reconcile key. (#49)
62d2560 Add Istio DestinationRule and Policy into Istio apis and clients (#43)
f4a77d7 Add a common test clients file (#46)
450739d Add common test logging module (#45

* Use updated methods that indicate that the configmap.Watcher is using an informer
matzew added a commit to matzew/eventing that referenced this pull request Apr 13, 2019
grantr added a commit to grantr/eventing that referenced this pull request Apr 23, 2019
These were originally added for the PubSub receive adapter in knative#57, but
it's been a while and we probably don't need them anymore.
knative-prow-robot pushed a commit that referenced this pull request Apr 23, 2019
* Remove cobra and pflag overrides

These overrides are very old, and cobra isn't imported anymore. This
cleanup has already happened in serving.

* Update pflag to 1.0.3

Tracking the serving bump in #2124.

* Remove very old GCP PubSub-related overrides

These were originally added for the PubSub receive adapter in #57, but
it's been a while and we probably don't need them anymore.
creydr added a commit to creydr/knative-eventing that referenced this pull request Jan 24, 2023
* [main] Patches to make OCP 48 -> OCP 4.11 work (knative#1928)

* Adding HPA patch

Signed-off-by: Matthias Wessendorf <mwessend@redhat.com>

* Adding SeccompProfile patch

Signed-off-by: Matthias Wessendorf <mwessend@redhat.com>

Signed-off-by: Matthias Wessendorf <mwessend@redhat.com>
(cherry picked from commit 181f37b)

* Apply HPA and SeccompProfile patch

Signed-off-by: Christoph Stäbler <cstabler@redhat.com>

Signed-off-by: Christoph Stäbler <cstabler@redhat.com>
Co-authored-by: Matthias Wessendorf <mwessend@redhat.com>
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.

4 participants