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

Commit

Permalink
test scripts, Makefile, docker file etc
Browse files Browse the repository at this point in the history
  • Loading branch information
murali-reddy committed Jul 3, 2018
1 parent 57648e6 commit 2853400
Show file tree
Hide file tree
Showing 32 changed files with 2,024 additions and 0 deletions.
98 changes: 98 additions & 0 deletions Makefile
@@ -0,0 +1,98 @@
GO = go
GO_FLAGS =
GOFMT = gofmt
KUBECFG = kubecfg
DOCKER = docker
CONTROLLER_IMAGE = kubeless-controller-manager:latest
NATS_CONTROLLER_IMAGE = nats-trigger-controller:latest
OS = linux
ARCH = amd64
BUNDLES = bundles
GO_PACKAGES = ./cmd/... ./pkg/...
GO_FILES := $(shell find $(shell $(GO) list -f '{{.Dir}}' $(GO_PACKAGES)) -name \*.go)

export KUBECFG_JPATH := $(CURDIR)/ksonnet-lib
export PATH := $(PATH):$(CURDIR)/bats/bin

.PHONY: all

KUBELESS_ENVS := \
-e OS_PLATFORM_ARG \
-e OS_ARCH_ARG \

default: binary

all:
CGO_ENABLED=1 ./script/make.sh

binary:
CGO_ENABLED=1 ./script/binary

binary-cross:
./script/binary-cli


%.yaml: %.jsonnet
$(KUBECFG) show -o yaml $< > $@.tmp
mv $@.tmp $@

all-yaml: nats.yaml

nats.yaml: nats.jsonnet

nats-controller-build:
./script/binary-controller -os=$(OS) -arch=$(ARCH) nats-controller github.com/kubeless/nats-trigger/cmd/nats-trigger-controller

nats-controller-image: docker/nats-controller
$(DOCKER) build -t $(NATS_CONTROLLER_IMAGE) $<

docker/nats-controller: nats-controller-build
cp $(BUNDLES)/kubeless_$(OS)-$(ARCH)/nats-controller $@

update:
./hack/update-codegen.sh

test:
$(GO) test $(GO_FLAGS) $(GO_PACKAGES)

validation:
./script/validate-vet
./script/validate-lint
./script/validate-gofmt
./script/validate-git-marks

integration-tests:
./script/integration-tests minikube deployment
./script/integration-tests minikube basic

minikube-rbac-test:
./script/integration-test-rbac minikube

fmt:
$(GOFMT) -s -w $(GO_FILES)

bats:
git clone --depth=1 https://github.com/sstephenson/bats.git

ksonnet-lib:
git clone --depth=1 https://github.com/ksonnet/ksonnet-lib.git

.PHONY: bootstrap
bootstrap: bats ksonnet-lib

go get github.com/mitchellh/gox
go get github.com/golang/lint/golint

@if ! which kubecfg >/dev/null; then \
sudo wget -q -O /usr/local/bin/kubecfg https://github.com/ksonnet/kubecfg/releases/download/v0.6.0/kubecfg-$$(go env GOOS)-$$(go env GOARCH); \
sudo chmod +x /usr/local/bin/kubecfg; \
fi

@if ! which kubectl >/dev/null; then \
KUBECTL_VERSION=$$(wget -qO- https://storage.googleapis.com/kubernetes-release/release/stable.txt); \
sudo wget -q -O /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/$$KUBECTL_VERSION/bin/$$(go env GOOS)/$$(go env GOARCH)/kubectl; \
sudo chmod +x /usr/local/bin/kubectl; \
fi

build_and_test:
./script/start-test-environment.sh "make binary && make controller-image CONTROLLER_IMAGE=bitnami/kubeless-controller-manager:latest && make integration-tests"
5 changes: 5 additions & 0 deletions docker/nats-controller/Dockerfile
@@ -0,0 +1,5 @@
FROM bitnami/minideb:jessie

ADD nats-controller /nats-controller

ENTRYPOINT ["/nats-controller"]
148 changes: 148 additions & 0 deletions examples/Makefile
@@ -0,0 +1,148 @@
python-nats:
kubeless function deploy python-nats --runtime python2.7 --handler pubsub.handler --from-file python/hellowithdata.py
kubeless trigger nats create python-nats --function-selector created-by=kubeless,function=python-nats --trigger-topic test

python-nats-verify:
$(eval DATA := $(shell mktemp -u -t XXXXXXXX))
$(eval NODEPORT := $(shell kubectl get svc nats -n nats-io -o jsonpath="{.spec.ports[0].nodePort}"))
$(eval MINIKUBE_IP := $(shell minikube ip))
kubeless trigger nats publish --url nats://$(MINIKUBE_IP):$(NODEPORT) --topic test --message '{"payload":"$(DATA)"}'
number="1"; \
timeout="60"; \
found=false; \
while [ $$number -le $$timeout ] ; do \
pod=`kubectl get po -oname -l function=python-nats`; \
logs=`kubectl logs $$pod | grep $(DATA)`; \
if [ "$$logs" != "" ]; then \
found=true; \
break; \
fi; \
sleep 1; \
number=`expr $$number + 1`; \
done; \
$$found
# Verify event context
logs=`kubectl logs -l function=python-nats`; \
echo $$logs | grep -q "event-time.*UTC" && \
echo $$logs | grep -q "event-type.*application/json" && \
echo $$logs | grep -q "event-namespace.*natstriggers.kubeless.io" && \
echo $$logs | grep -q "event-id.*"

nats-python-func1-topic-test:
kubeless function deploy nats-python-func1-topic-test --runtime python2.7 --handler pubsub.handler --from-file python/hellowithdata.py --label topic=nats-topic-test

nats-python-func2-topic-test:
kubeless function deploy nats-python-func2-topic-test --runtime python2.7 --handler pubsub.handler --from-file python/hellowithdata.py --label topic=nats-topic-test

nats-python-func-multi-topic:
kubeless function deploy nats-python-func-multi-topic --runtime python2.7 --handler pubsub.handler --from-file python/hellowithdata.py --label func=nats-python-func-multi-topic

nats-python-trigger-topic-test:
kubeless trigger nats create nats-python-trigger-topic-test --function-selector created-by=kubeless,topic=nats-topic-test --trigger-topic topic-test

nats-python-trigger-topic1:
kubeless trigger nats create nats-python-trigger-topic1 --function-selector created-by=kubeless,func=nats-python-func-multi-topic --trigger-topic topic1

nats-python-trigger-topic2:
kubeless trigger nats create nats-python-trigger-topic2 --function-selector created-by=kubeless,func=nats-python-func-multi-topic --trigger-topic topic2

nats-python-func1-topic-test-verify:
$(eval DATA := $(shell mktemp -u -t XXXXXXXX))
$(eval NODEPORT := $(shell kubectl get svc nats -n nats-io -o jsonpath="{.spec.ports[0].nodePort}"))
$(eval MINIKUBE_IP := $(shell minikube ip))
kubeless trigger nats publish --url nats://$(MINIKUBE_IP):$(NODEPORT) --topic topic-test --message '{"payload":"$(DATA)"}'
number="1"; \
timeout="60"; \
found=false; \
while [ $$number -le $$timeout ] ; do \
pod=`kubectl get po -oname -l function=nats-python-func1-topic-test`; \
logs=`kubectl logs $$pod | grep $(DATA)`; \
if [ "$$logs" != "" ]; then \
found=true; \
break; \
fi; \
sleep 1; \
number=`expr $$number + 1`; \
done; \
$$found
# Verify event context
logs=`kubectl logs -l function=nats-python-func1-topic-test`; \
echo $$logs | grep -q "event-time.*UTC" && \
echo $$logs | grep -q "event-type.*application/json" && \
echo $$logs | grep -q "event-namespace.*natstriggers.kubeless.io" && \
echo $$logs | grep -q "event-id.*"

nats-python-func2-topic-test-verify:
$(eval DATA := $(shell mktemp -u -t XXXXXXXX))
$(eval NODEPORT := $(shell kubectl get svc nats -n nats-io -o jsonpath="{.spec.ports[0].nodePort}"))
$(eval MINIKUBE_IP := $(shell minikube ip))
kubeless trigger nats publish --url nats://$(MINIKUBE_IP):$(NODEPORT) --topic topic-test --message '{"payload":"$(DATA)"}'
number="1"; \
timeout="60"; \
found=false; \
while [ $$number -le $$timeout ] ; do \
pod=`kubectl get po -oname -l function=nats-python-func2-topic-test`; \
logs=`kubectl logs $$pod | grep $(DATA)`; \
if [ "$$logs" != "" ]; then \
found=true; \
break; \
fi; \
sleep 1; \
number=`expr $$number + 1`; \
done; \
$$found
# Verify event context
logs=`kubectl logs -l function=nats-python-func2-topic-test`; \
echo $$logs | grep -q "event-time.*UTC" && \
echo $$logs | grep -q "event-type.*application/json" && \
echo $$logs | grep -q "event-namespace.*natstriggers.kubeless.io" && \
echo $$logs | grep -q "event-id.*"

nats-python-func-multi-topic-verify:
$(eval DATA := $(shell mktemp -u -t XXXXXXXX))
$(eval NODEPORT := $(shell kubectl get svc nats -n nats-io -o jsonpath="{.spec.ports[0].nodePort}"))
$(eval MINIKUBE_IP := $(shell minikube ip))
kubeless trigger nats publish --url nats://$(MINIKUBE_IP):$(NODEPORT) --topic topic1 --message '{"payload":"$(DATA)"}'
number="1"; \
timeout="60"; \
found=false; \
while [ $$number -le $$timeout ] ; do \
pod=`kubectl get po -oname -l function=nats-python-func-multi-topic`; \
logs=`kubectl logs $$pod | grep $(DATA)`; \
if [ "$$logs" != "" ]; then \
found=true; \
break; \
fi; \
sleep 1; \
number=`expr $$number + 1`; \
done; \
$$found
# Verify event context
logs=`kubectl logs -l function=nats-python-func-multi-topic`; \
echo $$logs | grep -q "event-time.*UTC" && \
echo $$logs | grep -q "event-type.*application/json" && \
echo $$logs | grep -q "event-namespace.*natstriggers.kubeless.io" && \
echo $$logs | grep -q "event-id.*"

kubeless trigger nats publish --url nats://$(MINIKUBE_IP):$(NODEPORT) --topic topic2 --message '{"payload":"$(DATA)"}'
number="1"; \
timeout="60"; \
found=false; \
while [ $$number -le $$timeout ] ; do \
pod=`kubectl get po -oname -l function=nats-python-func-multi-topic`; \
logs=`kubectl logs $$pod | grep $(DATA)`; \
if [ "$$logs" != "" ]; then \
found=true; \
break; \
fi; \
sleep 1; \
number=`expr $$number + 1`; \
done; \
$$found
# Verify event context
logs=`kubectl logs -l function=nats-python-func-multi-topic`; \
echo $$logs | grep -q "event-time.*UTC" && \
echo $$logs | grep -q "event-type.*application/json" && \
echo $$logs | grep -q "event-namespace.*natstriggers.kubeless.io" && \
echo $$logs | grep -q "event-id.*"

29 changes: 29 additions & 0 deletions examples/README.md
@@ -0,0 +1,29 @@
# Examples

This directory contains basic examples for kubeless.

Specifically it contains examples that we can test quickly using the `Makefile`. Some of these examples are run during our integration tests.

Check the [Makefile](Makefile)

Then run some of the examples like so:

```
make post-python
```

Or a different runtime:

```
make post-dotnetcore
```

Or a PubSub example:

```
make pubsub-python
```

# Looking for more function examples?

You can find more examples at [https://github.com/kubeless/functions](https://github.com/kubeless/functions)
3 changes: 3 additions & 0 deletions examples/python/hellowithdata.py
@@ -0,0 +1,3 @@
def handler(event, context):
print event
return event['data']
3 changes: 3 additions & 0 deletions examples/python/hellowithdata34.py
@@ -0,0 +1,3 @@
def handler(event, context):
print (event)
return event['data']
15 changes: 15 additions & 0 deletions hack/boilerplate.go.txt
@@ -0,0 +1,15 @@
/*
Copyright (c) 2016-2017 Bitnami

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.
*/
35 changes: 35 additions & 0 deletions hack/update-codegen.sh
@@ -0,0 +1,35 @@
#!/bin/bash

# Copyright 2017 The Kubernetes Authors.
#
# 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.

set -o errexit
set -o nounset
set -o pipefail

SCRIPT_ROOT=$(dirname ${BASH_SOURCE})/..
CODEGEN_PKG=${CODEGEN_PKG:-$(cd ${SCRIPT_ROOT}; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../code-generator)}

# generate the code with:
# --output-base because this script should also be able to run inside the vendor dir of
# k8s.io/kubernetes. The output-base is needed for the generators to output into the vendor dir
# instead of the $GOPATH directly. For normal projects this can be dropped.

### Workaround for issue: https://github.com/kubernetes/code-generator/issues/6
mkdir -p ${GOPATH}/src/k8s.io/kubernetes/hack/boilerplate
cp ${SCRIPT_ROOT}/hack/boilerplate.go.txt ${GOPATH}/src/k8s.io/kubernetes/hack/boilerplate/

${CODEGEN_PKG}/generate-groups.sh "deepcopy,client,informer,lister" \
github.com/kubeless/nats-trigger/pkg/client github.com/kubeless/nats-trigger/pkg/apis \
kubeless:v1beta1
7 changes: 7 additions & 0 deletions manifests/nats/nats-cluster.yaml
@@ -0,0 +1,7 @@
apiVersion: "nats.io/v1alpha2"
kind: "NatsCluster"
metadata:
name: "nats"
spec:
size: 2
version: "1.1.0"

0 comments on commit 2853400

Please sign in to comment.