Skip to content

Commit

Permalink
Adding helm chart and end2end test (#12)
Browse files Browse the repository at this point in the history
* Adding helm chart

Signed-off-by: Rishabh Gupta <[email protected]>

* Moved to cron-connector folder

Signed-off-by: Rishabh Gupta <[email protected]>

* Fixed _helpers.tpl

Signed-off-by: Rishabh Gupta <[email protected]>

* Updated helm chart to v0.2.2

Signed-off-by: Rishabh Gupta <[email protected]>

* Added e2e test

Signed-off-by: Rishabh Gupta <[email protected]>
  • Loading branch information
zeerorg authored Jun 9, 2019
1 parent 3867806 commit 298aea2
Show file tree
Hide file tree
Showing 9 changed files with 250 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ install: true

script:
- bash ./travis/build.sh
- bash ./travis/test.sh

deploy:
provider: script
Expand Down
22 changes: 22 additions & 0 deletions chart/cron-connector/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
15 changes: 15 additions & 0 deletions chart/cron-connector/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
description: Trigger OpenFaas Functions with cron
name: cron-connector
version: 0.2.1
sources:
- https://github.com/zeerorg/cron-connector
home: https://www.openfaas.com
icon: https://raw.githubusercontent.com/openfaas/media/master/OpenFaaS_logo_stacked_opaque.png
keywords:
- functions
- timer
- cron
maintainers:
- name: zeerorg
email: [email protected]
5 changes: 5 additions & 0 deletions chart/cron-connector/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Please follow the instructions below to get you started.

You can watch the Connector logs to see it invoke your functions:

$ kubectl logs -n {{ .Release.Namespace }} deploy/cron-connector -f
32 changes: 32 additions & 0 deletions chart/cron-connector/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "connector.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "connector.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "connector.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
69 changes: 69 additions & 0 deletions chart/cron-connector/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
# Original Helm labels v
app: {{ template "connector.name" . }}
component: cron-connector
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
# Helm/k8s recommended label names v
app.kubernetes.io/name: {{ template "connector.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion }}
app.kubernetes.io/component: cron-connector
app.kubernetes.io/part-of: openfaas
app.kubernetes.io/managed-by: {{ .Release.Service }}
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
name: {{ template "connector.fullname" . }}
namespace: {{ .Release.Namespace | quote }}

spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: {{ template "connector.name" . }}
app.kubernetes.io/component: cron-connector
template:
metadata:
labels:
app.kubernetes.io/name: {{ template "connector.name" . }}
app.kubernetes.io/component: cron-connector
spec:
containers:
- name: cron-connector
image: {{ .Values.image }}
env:
- name: gateway_url
value: {{ .Values.gateway_url | quote }}
{{- if .Values.basic_auth }}
- name: basic_auth
value: "true"
- name: secret_mount_path
value: "/var/secrets"
{{- end }}
{{- if .Values.basic_auth }}
volumeMounts:
- name: auth
readOnly: true
mountPath: "/var/secrets/"
{{- end }}
{{- if .Values.basic_auth }}
volumes:
- name: auth
secret:
secretName: basic-auth
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{ toYaml . | indent 8 }}
{{- end }}
9 changes: 9 additions & 0 deletions chart/cron-connector/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
image: zeerorg/cron-connector:v0.2.2
gateway_url: http://gateway.openfaas:8080
basic_auth: true

nodeSelector: {}

tolerations: []

affinity: {}
21 changes: 21 additions & 0 deletions travis/test-func.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
provider:
name: openfaas
gateway: http://127.0.0.1:8080
functions:
nodeinfo-1:
image: functions/nodeinfo:latest
annotations:
topic: cron-function
schedule: "* * * * *"
nodeinfo-2:
image: functions/nodeinfo:latest
annotations:
topic: cron-function
schedule: "* * * * *"
nodeinfo-3:
image: functions/nodeinfo:latest
annotations:
topic: cron-function
schedule: "* * * * *"
nodeinfo-4:
image: functions/nodeinfo:latest
76 changes: 76 additions & 0 deletions travis/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Install kubectl
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl

# install helm
curl -s https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get | sudo bash

# install k3d
curl -s https://raw.githubusercontent.com/rancher/k3d/master/install.sh | sudo bash

# Get faas-cli
curl -sSL https://cli.openfaas.com | sudo sh

# Start test cluster
k3d create --wait 0
sleep 20
export KUBECONFIG="$(k3d get-kubeconfig)"

# Prepare installation
kubectl -n kube-system create sa tiller \
&& kubectl create clusterrolebinding tiller \
--clusterrole cluster-admin \
--serviceaccount=kube-system:tiller

helm init --skip-refresh --upgrade --wait --service-account tiller

# create namesapce
kubectl apply -f https://raw.githubusercontent.com/openfaas/faas-netes/master/namespaces.yml

# add repo
helm repo add openfaas https://openfaas.github.io/faas-netes/

# set password
PASSWORD="something"

kubectl -n openfaas create secret generic basic-auth \
--from-literal=basic-auth-user=admin \
--from-literal=basic-auth-password="$PASSWORD"

helm repo update \
&& helm upgrade openfaas --install openfaas/openfaas \
--namespace openfaas \
--set basic_auth=true \
--set functionNamespace=openfaas-fn \
--wait

kubectl port-forward svc/gateway-external 31112:8080 -n openfaas &

sleep 2

export OPENFAAS_URL=http://localhost:31112
echo -n $PASSWORD | faas-cli login -g $OPENFAAS_URL -u admin --password-stdin

faas-cli deploy -f ./travis/test-func.yml

kubectl rollout status --namespace openfaas-fn deployment/nodeinfo-1
kubectl rollout status --namespace openfaas-fn deployment/nodeinfo-2
kubectl rollout status --namespace openfaas-fn deployment/nodeinfo-3
kubectl rollout status --namespace openfaas-fn deployment/nodeinfo-4

helm upgrade --install --namespace openfaas --wait cron-connector ./chart/cron-connector --set image=zeerorg/cron-connector:test-build

sleep 70

Invokes1=$(faas-cli list | grep nodeinfo-1 | awk -F '\t' '{print $2}')
Invokes2=$(faas-cli list | grep nodeinfo-2 | awk -F '\t' '{print $2}')
Invokes3=$(faas-cli list | grep nodeinfo-3 | awk -F '\t' '{print $2}')

faas-cli list
kubectl logs --namespace openfaas deployment/cron-connector

if [ \( $Invokes1 -lt 1 \) -o \( $Invokes2 -ne $Invokes2 \) -o \( $Invokes2 -ne $Invokes3 \) ]
then
exit 1
fi

0 comments on commit 298aea2

Please sign in to comment.