-
Notifications
You must be signed in to change notification settings - Fork 753
Conversation
if err != nil { | ||
return err | ||
} | ||
if res.StatusCode != 200 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should do something like defer resp.Body.Close()
here to close response body and avoid leaking file descriptors ;)
func main() { | ||
logrus.Infof("Running NATS controller version: %v", version.Version) | ||
if err := rootCmd.Execute(); err != nil { | ||
fmt.Println(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor thing but log.Fatalf
would print the timestamp of the hypothetical crash
if oldNatsTriggerObj.ResourceVersion == newNatsTriggerObj.ResourceVersion { | ||
return false | ||
} | ||
if !reflect.DeepEqual(oldNatsTriggerObj.Spec.FunctionSelector, newNatsTriggerObj.Spec.FunctionSelector) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use apiequality
to compare the whole Spec
object (see the function_controller)
return req, nil | ||
} | ||
|
||
func sendMessage(req *http.Request) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should move isJSON
getHTTPReq
and this sendMessage
to a common package (since it is reused for Kafka)
req.Header.Add("event-time", timestamp.String()) | ||
req.Header.Add("event-namespace", "natstriggers.kubeless.io") | ||
if isJSON(body) { | ||
logrus.Infof("TRUE %v", body) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a debug message
req.Header.Add("Content-Type", "application/json") | ||
req.Header.Add("event-type", "application/json") | ||
} else { | ||
logrus.Infof("FLASE %v", body) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
debug message
}, | ||
} | ||
|
||
func publishTopic(topic, message, url string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice solution :)
make nats-controller-image NATS_CONTROLLER_IMAGE=$NATS_CONTROLLER_IMAGE | ||
./script/integration-tests minikube deployment | ||
./script/integration-tests minikube nats | ||
;; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the image should be done in the GKE
scenario as well since it is the scenario that pushes the images and test everything
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also retag the image with the TRAVIS_TAG in the after_success
hook, rename the file in the before_deploy
and finally add the file in the deploy.file
list
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -75,6 +75,9 @@ basic) | |||
kafka) | |||
bats tests/integration-tests-kafka.bats | |||
;; | |||
nats) | |||
bats tests/integration-tests-nats.bats |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add this tests as well in the *
case (for GKE)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will do it in a seperate PR. Intergration tests for NATS are running as part of Minikube which should be sufficient for now.
script/nats-controller.sh
Outdated
@@ -0,0 +1,44 @@ | |||
#!/usr/bin/env bash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should be able to reuse the binary-controller
script instead of adding a new one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated but we have release notes for Kafka in script/upload_release_notes
. I think we should modify them to just point to this tutorial for Kafka and NATS
docs/quick-start.md
Outdated
@@ -133,7 +133,11 @@ Kubeless also supports [ingress](https://kubernetes.io/docs/concepts/services-ne | |||
|
|||
## PubSub function | |||
|
|||
We provide several [PubSub runtimes](https://hub.docker.com/r/kubeless/), which has suffix `event-consumer`, which help you to quickly deploy your function with PubSub mechanism. The PubSub function will expect to consume input messages from a predefined Kafka topic which means Kafka is required. In Kubeless [release page](https://github.com/kubeless/kubeless/releases), you can find the manifest to quickly deploy a collection of Kafka and Zookeeper statefulsets. If you have a Kafka cluster already running in the same Kubernetes environment, you can also deploy PubSub function with it. Check out [this tutorial](/docs/use-existing-kafka) for more details how to do that. | |||
We provide several [PubSub runtimes](https://hub.docker.com/r/kubeless/), which has suffix `event-consumer`, which help you to quickly deploy your function with PubSub mechanism. The PubSub function will expect to consume input messages from a predefined topic from a messaging system. Kubeless supports using events from Kafka and NATS messaging systems as Triggers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We provide several PubSub runtimes, which has suffix
event-consumer
, which help you to quickly deploy your function with PubSub mechanism
that is no longer correct. I would say something like "all the available runtimes can be triggered with a PubSub mechanism..."
|
||
Above command will create NATS cluster IP service `nats.nats-io.svc.cluster.local:4222` which is the default URL Kubeless NATS trigger contoller expects. | ||
|
||
At this point you are all set try Kubeless NATS triggers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would continue the tutorial a little bit more and deploy a function using a NATS topic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expanded the quick start guide for NATS.
We should also add an additional flag to the |
var ( | ||
stopM map[string](chan struct{}) | ||
stoppedM map[string](chan struct{}) | ||
consumerM map[string]bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering but is this map ok in terms of concurrent access? It seems would be used when either syncNATSTrigger
and FunctionAddedDeletedUpdated
are called but not sure if they would both happen concurrently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added locking there is a remote chance of race condition.
@andresmgot I have removed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Changes LGTM. Great work :)
thanks for the review @andresmgot @wallyqs @wallyqs you should be able to use the functionality by building image from the master. Ping me on slack if you run into any issue. Would be nice to get your feedback and possible future enhacements. |
Issue Ref: #669
Description:
Add NATS support into Kubeless.
[PR Description]
This PR adds a first-cut integration of NATS into Kubeless. NATS provides wide variety of messaging options, this PR adds suport for https://nats.io/documentation/concepts/nats-queueing/
Please see the documentation included in the PR on how to use the functionality.
To the reviewer:
Commits are logically organised to make easier to follow.
TODOs:
Planning to add some more IT tests, but PR is good to get started with review.