Skip to content
This repository has been archived by the owner on Mar 13, 2021. It is now read-only.

projectriff/dev-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Developer Tools

This repository provides tools for riff users to develop and debug functions. These tools are bundled in a container image that is meant to be run in the development cluster.

Using the tools

These tools can be used by running a pod in the k8s cluster with a configuration like this:

# create a service account to run with
kubectl create serviceaccount riff-dev --namespace=${NAMESPACE}
# grant that service account edit access to resources in the namespace
kubectl create rolebinding riff-dev-edit --namespace=${NAMESPACE} --clusterrole=edit --serviceaccount=${NAMESPACE}:riff-dev
# run the utils using the service account as a pod
kubectl run riff-dev --namespace=${NAMESPACE} --image=projectriff/dev-utils --serviceaccount=riff-dev --generator=run-pod/v1

As pods do not survive node failures, over time the riff-dev pod may stop running. When this happens create a new pod using the same service account.

Included tools

  1. publish: To publish an event to the given stream. The command takes the form:

    publish <stream-name> -n <namespace> --payload <payload-as-string> --content-type <content-type> --header "<header-name>: <header-value>"
    

    where stream-name, payload and content-type are mandatory and header can be used multiple times.

  2. subscribe: To subscribe for events from the given stream. The command takes the form:

    subscribe <stream-name> --from-beginning
    

    If the --from-beginning option is present, display all the events in the stream, otherwise only new events are displayed in the following json format:

    {"payload": "base64 encoded user payload","content-type": "the content type of the message","headers": {"user provided header": "while publishing"}}
    
  3. jq: To process JSON.

  4. base64: Encode and decode base64 strings.

  5. curl: To make HTTP requests.

  6. kafkacat: To interact with kafka

The namespace parameter is optional for all the commands. If not specified, the namespace of the riff-dev pod will be assumed.

Examples

These tools can be invoked using kubectl exec. some examples follow:

kubectl exec riff-dev --namespace ${NAMESPACE} -it -- publish letters --content-type text/plain --payload foo
kubectl exec riff-dev --namespace ${NAMESPACE} -it -- subscribe letters --from-beginning
kubectl exec riff-dev --namespace ${NAMESPACE} -it -- curl http://hello.default.svc.cluster.local/ -H 'Content-Type: text/plain' -H 'Accept: text/plain' -d '<insert your name>'
kubectl exec riff-dev --namespace ${NAMESPACE} -it -- bash
kafkacat -C -b YOUR_BROKER -t TOPIC

Running locally

You can run the publish and subscribe cli locally by:

  1. Building them using
    go build cmd/publish/publish.go
    go build cmd/subscribe/subscribe.go
  2. Install kubefwd and expose the gateway service to localhost
    sudo -E kubefwd svc -n NAMESPACE
  3. Run the built publish and subscribe cli locally.