Skip to content

Commit

Permalink
doc: add greeting example
Browse files Browse the repository at this point in the history
  • Loading branch information
lionelvillard committed Dec 6, 2018
1 parent bb1977f commit a312a4c
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -31,7 +31,7 @@ jobs:
- INSTALL_MINIKUBE=1 INSTALL_K8S_TOOLS=1
- script: test/e2e/test.sh
env:
- REMOTE_OPENWHISK=1 INSTALL_IBMCLOUD=1 INSTALL_K8S_TOOLS=1 INSTALL_MINIKUBE=1 RUN_DEP=1
- REMOTE_OPENWHISK=1 INSTALL_IBMCLOUD=1 INSTALL_K8S_TOOLS=1 INSTALL_MINIKUBE=1 RUN_DEP=1 KUBE_ENV=local
- stage: deploy
script: bash tools/travis/docker.sh
env:
Expand Down
49 changes: 37 additions & 12 deletions README.md
@@ -1,6 +1,6 @@
# Apache OpenWhisk Operators

[![Build Status](https://travis-ci.org/IBM/openwhisk-operator.svg?branch=master)](https://travis-ci.org/IBM/openwhisk-operator)
[![Build Status](https://travis-ci.com/IBM/openwhisk-operator.svg?branch=master)](https://travis-ci.com/IBM/openwhisk-operator)
[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0)

This project provides a collection of Kubernetes operators for managing [Apache OpenWhisk](https://openwhisk.apache.org/) resources namely actions, packages, rules and triggers.
Expand All @@ -12,9 +12,9 @@ This project provides a collection of Kubernetes operators for managing [Apache
- [Quick start](#quick-start)
- [Prerequisites](#prerequisites)
- [Installing the operators](#installing-the-operators)
- [Using the operators](#using-the-operators)
- [Setting up OpenWhisk credentials](#setting-up-openwhisk-credentials)
- [Deploying function](#deploying-function)
- [Using the operators](#using-the-operators)
- [Setting up OpenWhisk credentials](#setting-up-openwhisk-credentials)
- [Deploying your first function](#deploying-your-first-function)
- [Learn more](#learn-more)

<!-- /TOC -->
Expand Down Expand Up @@ -43,12 +43,26 @@ $ kustomize build github.com/IBM/openwhisk-operator//config/default | kubectl ap

By default the operators are installed in the `openwhisk-system` namespace and are granted [clustor-wide](./config/rbac/rbac_role_binding.yaml) [permissions](./config/rbac/rbac_role.yaml).

# Using the operators
## Using the operators

## Setting up OpenWhisk credentials
### Setting up OpenWhisk credentials

By default, all operators look for OpenWhisk credentials in the `seed-default-owprops` secret:

[//]: #embed-code(test/e2e/wskprops-secrets.sh)
```sh
# Extract properties from .wskprops
AUTH=$(cat ~/.wskprops | grep 'AUTH' | awk -F= '{print $2}')
APIHOST=$(cat ~/.wskprops | grep 'APIHOST' | awk -F= '{print $2}')

# And create secret
kubectl create secret generic seed-defaults-owprops \
--from-literal=apihost=$APIHOST \
--from-literal=auth=$AUTH
```

Alternativalely, you can directly create a k8s secret

[//]: #embed-code(samples/credentials-guest.yaml)
```yaml
apiVersion: v1
Expand All @@ -63,23 +77,34 @@ stringData:

**NOTE**: be aware that all operators update OpenWhisk entities and can potentially override existing entitites.

## Deploying function
### Deploying your first function

You can use the `Function` operator to deploy actions:
The `Function` resource kind allows the deployement of actions:

[//]: #embed-code(samples/function.yaml)
[//]: #embed-code(test/e2e/greetings.yaml)
```yaml
apiVersion: openwhisk.seed.ibm.com/v1beta1
kind: Function
metadata:
name: myfunction
namespace: default
name: greetings
spec:
codeURI: https://raw.githubusercontent.com/apache/incubator-openwhisk-catalog/master/packages/utils/echo.js
runtime: nodejs:6
parameters:
- name: message
value: "Hello"
value: Bonjour
```

Deploy it:

```sh
$ kubectl apply -f sample.yaml
```

wait a little bit and run:

```sh
$ wsk action invoke greetings -br
```

# Learn more
Expand Down
5 changes: 2 additions & 3 deletions samples/function.yaml → test/e2e/greetings.yaml
@@ -1,11 +1,10 @@
apiVersion: openwhisk.seed.ibm.com/v1beta1
kind: Function
metadata:
name: myfunction
namespace: default
name: greetings
spec:
codeURI: https://raw.githubusercontent.com/apache/incubator-openwhisk-catalog/master/packages/utils/echo.js
runtime: nodejs:6
parameters:
- name: message
value: "Hello"
value: Bonjour
16 changes: 16 additions & 0 deletions test/e2e/test-doc.sh
@@ -0,0 +1,16 @@

function td::run() {
u::begin_testcase "should deploy documentation examples"

kubectl apply -f greetings.yaml
object::wait_function_online greetings 10

result=$(ibmcloud wsk action invoke greetings -br)
u::assert_equal '{ "message": "Bonjour"}' "$result"

u::end_testcase
}

function td::cleanup() {
kubectl delete -f greetings.yaml
}
14 changes: 8 additions & 6 deletions test/e2e/test-hello.sh
Expand Up @@ -15,12 +15,14 @@
# limitations under the License.
#

u::begin_testcase "should deploy the action hello in a package"
function th::run() {
u::begin_testcase "should deploy the action hello in a package"

kubectl apply -f hello.yaml >> /dev/null
object::wait_function_online hello-world 10
kubectl apply -f hello.yaml >> /dev/null
object::wait_function_online hello-world 10

result=$(ibmcloud wsk action invoke -br hello-world-package/hello-world -p name John -p place Yorktown)
u::assert_equal '{ "greeting": "Hello, John from Yorktown"}' "$result"
result=$(ibmcloud wsk action invoke -br hello-world-package/hello-world -p name John -p place Yorktown)
u::assert_equal '{ "greeting": "Hello, John from Yorktown"}' "$result"

u::end_testcase
u::end_testcase
}
35 changes: 25 additions & 10 deletions test/e2e/test.sh
Expand Up @@ -17,29 +17,44 @@

set -e


ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd)
cd $ROOT

KUBE_ENV=${KUBE_ENV:=default}

source hack/lib/object.sh
source hack/lib/utils.sh

u::header "building docker image"
docker build . -t local/openwhisk-operator

if [ "${KUBE_ENV}" = "local" ]; then
u::header "building docker image"
docker build . -t local/openwhisk-operator
fi

u::header "installing CRDs, operators and secrets"

kustomize build config/crds | kubectl apply -f -
kustomize build config/local | kubectl apply -f -
kustomize build config/${KUBE_ENV} | kubectl apply -f -

AUTH=$(cat ~/.wskprops | grep 'AUTH' | awk -F= '{print $2}')
APIHOST=$(cat ~/.wskprops | grep 'APIHOST' | awk -F= '{print $2}')
cd $ROOT/test/e2e

kubectl create secret generic seed-defaults-owprops --from-literal=apihost=$APIHOST --from-literal=auth=$AUTH
source ./test-hello.sh
source ./test-doc.sh

u::header "running tests"
function cleanup() {
set +e
u::header "cleaning up..."

cd $ROOT/test/e2e
# td::cleanup
kubectl delete secret seed-defaults-owprops
}
trap cleanup EXIT

. ./wskprops-secrets.sh

u::header "running tests"

. ./test-hello.sh
td::run
th::run

u::report_and_exit
8 changes: 8 additions & 0 deletions test/e2e/wskprops-secrets.sh
@@ -0,0 +1,8 @@
# Extract properties from .wskprops
AUTH=$(cat ~/.wskprops | grep 'AUTH' | awk -F= '{print $2}')
APIHOST=$(cat ~/.wskprops | grep 'APIHOST' | awk -F= '{print $2}')

# And create secret
kubectl create secret generic seed-defaults-owprops \
--from-literal=apihost=$APIHOST \
--from-literal=auth=$AUTH

0 comments on commit a312a4c

Please sign in to comment.