Skip to content

Commit

Permalink
simple wait function
Browse files Browse the repository at this point in the history
  • Loading branch information
lionelvillard committed Nov 20, 2019
1 parent 09cb008 commit 58c66d3
Show file tree
Hide file tree
Showing 39 changed files with 1,210 additions and 1,013 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
.history
32 changes: 32 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
language: go
go:
- 1.12.x
sudo: required
dist: xenial
addons:
snaps:
- name: kubectl
confinement: classic
- name: helm
confinement: classic
- name: node
channel: "8/stable"
confinement: classic

branches:
only:
- "master"

install: skip

before_script:
- sudo mv bin/linux/amd64/kind /usr/local/bin
- go get github.com/ibm/kone/cmd/kone

jobs:
include:
- install: skip
name: "Serving 0.10.0 / Eventing 0.10.0"
script:
- test/e2e.sh 0.10.0 0.10.0

92 changes: 37 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,53 @@
# Knative Eventing Functions
[![Build Status](https://travis-ci.org/lionelvillard/knative-functions.svg?branch=master)](https://travis-ci.org/lionelvillard/knative-functions)

This project provides a collection of functions manipulating [Cloud Events](https://cloudevents.io).

There are two categories of functions:
- the ones accepting only one set of parameters (standalone function), and
- the ones accepting multiple sets of parameters (dispatch function).

The functions accepting multiple sets of parameters are compatible with the [Knative function controller](https://github.com/lionelvillard/knative-functions-controller).

All functions are currently only _callable_ (synchronous). We are planning to add _composable_ (asynchronous) functions
the near future.

Function parameters are statically bound, either through environment variables for standalone functions or
through custom objects for dispatch functions. We are planning to also support dynamic variable bindings.

## Installation

You first need to install the [Knative Eventing Function Controller](https://github.com/lionelvillard/knative-functions-controller):

```sh
kubectl apply -f https://github.com/lionelvillard/knative-functions-controller/releases/download/v0.1.2/function.yaml
```

Then install the function library:

```sh
kubectl apply -f https://github.com/lionelvillard/knative-functions/releases/download/v0.1.0/functions.yaml
```

## Functions

The functions are:

- [Wait](#wait)
<!--
- [Filter](#filter) (both [standalone](#standalone) and [dispatch](#dispatch) modes)
- [Transformer](#transformer)
- [Switch](#switch) (both [standalone](#standalone-1) and [dispatch](#dispatch-1) modes)
- [Wait](#wait) (both [standalone](#standalone-2) and [dispatch](#dispatch-2) modes)
-->

### Wait

The `Wait` function forward events after X seconds.

#### Example

```yaml
apiVersion: functions.knative.dev/v1alpha1
kind: Wait
metadata:
name: wait-5
spec:
seconds: 5
```
<!--
## Filter
A filter takes a cloud event as input, evaluates a predicate against it and returns the
Expand Down Expand Up @@ -182,49 +209,4 @@ spec:
- true
- false
```

## Wait

The Wait function is the identity function waiting X seconds.

### Standalone

#### Environment Variables

- `SECONDS`: number of seconds to wait

#### Knative Serving Example

```yaml
apiVersion: serving.knative.dev/v1alpha1
kind: Service
metadata:
name: wait
spec:
template:
spec:
containers:
- image: villardl/waiter-nodejs
env:
- name: SECONDS
value: "15"
```

### Dispatch

#### Installation

```sh
kone apply -f ./wait-dispatcher/config/
```

#### Example

```yaml
apiVersion: function.knative.dev/v1alpha1
kind: Wait
metadata:
name: wait-5
spec:
seconds: 5
```
-->
Binary file added bin/linux/amd64/kind
Binary file not shown.
2 changes: 1 addition & 1 deletion filter-dispatcher/config/300-filter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: filters.function.knative.dev
name: filters.functions.knative.dev
labels:
knative.dev/crd-install: "true"
spec:
Expand Down
9 changes: 9 additions & 0 deletions hack/kind-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
kind: Cluster
apiVersion: kind.sigs.k8s.io/v1alpha3
nodes:
- role: control-plane
- role: worker
extraPortMappings:
- containerPort: 31380 # istio-ingressgateway
hostPort: 8080
listenAddress: "127.0.0.1"
48 changes: 48 additions & 0 deletions hack/lib/couchdb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash

# Copyright 2019 IBM Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


function couchdb::get_document() {
local url=$1
local database=$2
local id=$3
curl -s "$url/$database/$id"
}

function couchdb::create_document() {
local url=$1
local database=$2
local data=$3

curl "$url/$database" \
-H "Content-Type: application/json" \
-d "$data"

return 0
}

function couchdb::delete_document() {
local url=$1
local database=$2
local id=$3

local doc=$(couchdb::get_document "$url" "$database" "$id")
local rev=$(echo $doc | jq -r "._rev")


curl -X DELETE -s "$url/$database/$id?rev=$rev"
return 0
}
71 changes: 71 additions & 0 deletions hack/lib/ic.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env bash

# Copyright 2019 IBM Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

function ic::install_seed_operators() {
local cloudversion=$1

if [[ $cloudversion == "" ]]; then
echo "install seed latest"
cloud_base=https://raw.githubusercontent.com/IBM/cloud-operators/master/releases/v0.1.2/
fi

kubectl apply -f ${cloud_base}/000_namespace.yaml
kubectl apply -f ${cloud_base}/001_ibmcloud_v1alpha1_binding.yaml
kubectl apply -f ${cloud_base}/002_ibmcloud_v1alpha1_service.yaml
kubectl apply -f ${cloud_base}/003_serviceaccount.yaml
kubectl apply -f ${cloud_base}/004_manager_role.yaml
kubectl apply -f ${cloud_base}/005_rbac_role_binding.yaml
kubectl apply -f ${cloud_base}/006_deployment.yaml

k8s::wait_until_pods_running ibmcloud-operators

return 0
}

function ic::configure_operators() {
local apikey=$1
local region=$2

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Secret
metadata:
name: seed-secret
labels:
seed.ibm.com/ibmcloud-token: "apikey"
app.kubernetes.io/name: ibmcloud-operator
type: Opaque
stringData:
api-key: ${apikey}
region: ${region}
EOF

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ConfigMap
metadata:
name: seed-defaults
labels:
app.kubernetes.io/name: ibmcloud-operator
data:
org: org
region: ${region}
resourceGroup: default
space: space
EOF

return 0
}
97 changes: 97 additions & 0 deletions hack/lib/istio.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/usr/bin/env bash

# Copyright 2019 IBM Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

function istio::install_lean() {
local ISTIO_VERSION=$1

if [[ "$ISTIO_VERSION" == "" ]]; then
u::fatal "usage istio::install <istio_version>: missing argument"
fi

u::header "installing istio"
ISTIO_DIR=$(mktemp -d)
pushd $ISTIO_DIR

export ISTIO_VERSION
curl -L https://git.io/getLatestIstio | sh -
cd istio-${ISTIO_VERSION}

for i in install/kubernetes/helm/istio-init/files/crd*yaml; do
kubectl apply -f $i;
done

sleep 2

set +e
kubectl create ns istio-system
kubectl label ns istio-system istio-injection=disabled
set -e

helm template --namespace=istio-system \
--set prometheus.enabled=false \
--set mixer.enabled=false \
--set mixer.policy.enabled=false \
--set mixer.telemetry.enabled=false \
`# Pilot doesn't need a sidecar.` \
--set pilot.sidecar=false \
--set pilot.resources.requests.memory=128Mi \
--set pilot.resources.requests.cpu=100m \
`# Disable galley (and things requiring galley).` \
--set galley.enabled=false \
--set global.useMCP=false \
`# Disable security / policy.` \
--set security.enabled=false \
--set global.disablePolicyChecks=true \
`# Disable sidecar injection.` \
--set sidecarInjectorWebhook.enabled=false \
--set global.proxy.autoInject=disabled \
--set global.omitSidecarInjectorConfigMap=true \
`# Set gateway pods to 1 to sidestep eventual consistency / readiness problems.` \
--set gateways.istio-ingressgateway.autoscaleMin=1 \
--set gateways.istio-ingressgateway.autoscaleMax=1 \
`# Set pilot trace sampling to 100%` \
--set pilot.traceSampling=100 \
install/kubernetes/helm/istio \
> ./istio-lean.yaml

kubectl apply -f istio-lean.yaml
# kubectl patch -n istio-system deployments.apps istio-pilot -p '{"spec": {"template": {"spec": {"containers": [{"name": "discovery", "resources": {"requests": {"cpu":"100m"}}}]}}}}'

echo "install local cluster gateway"

helm template --namespace=istio-system \
--set gateways.custom-gateway.autoscaleMin=1 \
--set gateways.custom-gateway.autoscaleMax=1 \
--set gateways.custom-gateway.cpu.targetAverageUtilization=60 \
--set gateways.custom-gateway.labels.app='cluster-local-gateway' \
--set gateways.custom-gateway.labels.istio='cluster-local-gateway' \
--set gateways.custom-gateway.type='ClusterIP' \
--set gateways.istio-ingressgateway.enabled=false \
--set gateways.istio-egressgateway.enabled=false \
--set gateways.istio-ilbgateway.enabled=false \
install/kubernetes/helm/istio \
-f install/kubernetes/helm/istio/example-values/values-istio-gateways.yaml \
| sed -e "s/custom-gateway/cluster-local-gateway/g" -e "s/customgateway/clusterlocalgateway/g" \
> ./istio-local-gateway.yaml

kubectl apply -f istio-local-gateway.yaml

popd

k8s::wait_until_pods_running istio-system

return 0
}
Loading

0 comments on commit 58c66d3

Please sign in to comment.