Skip to content

Commit

Permalink
simple filtering function
Browse files Browse the repository at this point in the history
  • Loading branch information
lionelvillard committed Nov 20, 2019
1 parent 46b364f commit e9878f7
Show file tree
Hide file tree
Showing 19 changed files with 119 additions and 678 deletions.
58 changes: 7 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ kubectl apply -f https://github.com/lionelvillard/knative-functions/releases/dow
The functions are:

- [Wait](#wait)
- [Filter](#filter)
<!--
- [Filter](#filter) (both [standalone](#standalone) and [dispatch](#dispatch) modes)
- [Transformer](#transformer)
- [Switch](#switch) (both [standalone](#standalone-1) and [dispatch](#dispatch-1) modes)
-->
Expand All @@ -47,69 +47,25 @@ spec:
seconds: 5
```
<!--
## Filter
### Filter
A filter takes a cloud event as input, evaluates a predicate against it and returns the
unmodified event when the predicate return true, otherwise returns an empty response
Supported predicate languages:
- nodejs
### Standalone
#### Environment Variables
- `FILTER`: an expression evaluating to a boolean
- all environment variables are made available to the `FILTER` expression

##### Knative Serving Example (node.js)

```yaml
apiVersion: serving.knative.dev/v1alpha1
kind: Service
metadata:
name: filter
spec:
template:
spec:
containers:
- image: villardl/filter-nodejs
env:
- name: FILTER
value: event.data.assigned
```

`FILTER` must be a valid node.js expression.

### Dispatch
unmodified event when the predicate return true, otherwise returns an empty response.
#### Installation

```sh
kone apply -f ./filter-dispatcher/config/
```
The predicate must be a Javascript expression. It is evaluated in a sandbox with the variable [`event`](https://github.com/cloudevents/spec/blob/v1.0/json-format.md)

#### Example
### Example

```yaml
apiVersion: function.knative.dev/v1alpha1
apiVersion: functions.knative.dev/v1alpha1
kind: Filter
metadata:
name: filter
spec:
language: nodejs
expression: event.data.assigned
```

After applying this configuration, check the status:

```sh
kubectl get filters.function.knative.dev
NAME READY REASON URL AGE
filter True http://filter-filter.knative-functions.svc.cluster.local 13h
```
<!--

## Transformer

Expand Down
19 changes: 0 additions & 19 deletions filter-dispatcher/config/500-ksvc.yaml

This file was deleted.

99 changes: 0 additions & 99 deletions filter-dispatcher/nodejs/main.js

This file was deleted.

10 changes: 0 additions & 10 deletions filter-dispatcher/nodejs/package.json

This file was deleted.

7 changes: 0 additions & 7 deletions filter-dispatcher/samples/filter.yaml

This file was deleted.

14 changes: 0 additions & 14 deletions filter-dispatcher/samples/sendevent.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ kind: CustomResourceDefinition
metadata:
name: filters.functions.knative.dev
labels:
knative.dev/crd-install: "true"
functions.knative.dev/crd: "true"
annotations:
functions.knative.dev/image: ../src
spec:
group: function.knative.dev
group: functions.knative.dev
version: v1alpha1
names:
kind: Filter
Expand All @@ -28,8 +30,7 @@ spec:
- all
- knative
- eventing
- messaging
- function
- functions
scope: Namespaced
subresources:
status: {}
Expand All @@ -51,12 +52,7 @@ spec:
properties:
spec:
required:
- language
- expression
properties:
language:
type: string
enum:
- nodejs
expression:
type: string
5 changes: 0 additions & 5 deletions filter/nodejs/Dockerfile

This file was deleted.

71 changes: 0 additions & 71 deletions filter/nodejs/main.js

This file was deleted.

Loading

0 comments on commit e9878f7

Please sign in to comment.