Skip to content

Commit a18c035

Browse files
committed
Merge the operator and faas-netes
This commit merges the code of the operator into the faas-netes repo, so that the two controllers can be worked on together and kept in sync. * Consolidate CI to run both sets of e2e tests for the two controllers. * Update helm to use RC controller release Tested with faas-netes and operator switched in place using instructions in the PR. Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent be9dec1 commit a18c035

File tree

482 files changed

+68392
-9834
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

482 files changed

+68392
-9834
lines changed

.travis.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ go:
66
- 1.13.x
77

88
install:
9-
- curl -sSLf https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
10-
- helm version -c
9+
- "echo helm now installed via scripts."
1110

1211
services:
1312
- docker
@@ -19,12 +18,16 @@ before_script:
1918

2019
script:
2120
- make build
21+
- ./contrib/get_tools.sh
2222
- ./contrib/lint_chart.sh
23-
- ./contrib/get_kind.sh
24-
- ./contrib/create_kind_cluster.sh
25-
- ./contrib/deploy.sh
26-
- ./contrib/get_faas.sh
23+
- ./contrib/create_cluster.sh
24+
- OPERATOR=0 ./contrib/deploy.sh
2725
- ./contrib/run_function.sh
26+
- ./contrib/stop_dev.sh
27+
- ./contrib/create_cluster.sh
28+
- OPERATOR=1 ./contrib/deploy.sh
29+
- OPERATOR=1 ./contrib/run_function.sh
30+
- ./contrib/stop_dev.sh
2831

2932
after_success:
3033
- if [ -z $DOCKER_NS ] ; then

chart/openfaas/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Ease of use through UI portal and *one-click* install
1010
* Write functions in any language for Linux or Windows and package in Docker/OCI image format
1111
* Portable - runs on existing hardware or public/private cloud. Native [Kubernetes](https://github.com/openfaas/faas-netes) support, Docker Swarm also available
12-
* [Operator / CRD option available](https://github.com/openfaas/openfaas-operator/)
12+
* [Operator / CRD option available](https://github.com/openfaas/faas-netes/)
1313
* [faas-cli](http://github.com/openfaas/faas-cli) available with stack.yml for creating and managing functions
1414
* Auto-scales according to metrics from Prometheus
1515
* Scales to zero and back again and can be tuned at a per-function level

chart/openfaas/templates/gateway-dep.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ spec:
161161
image: {{ .Values.operator.image }}
162162
imagePullPolicy: {{ .Values.openfaasImagePullPolicy }}
163163
command:
164-
- ./openfaas-operator
164+
- ./faas-netes
165+
- -operator=true
165166
env:
166167
- name: port
167168
value: "8081"

chart/openfaas/values.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ oauth2Plugin:
7373
securityContext: true
7474

7575
faasnetes:
76-
image: openfaas/faas-netes:0.10.1
76+
image: openfaas/faas-netes:0.10.2-rc1
7777
readTimeout : "60s"
7878
writeTimeout : "60s"
7979
imagePullPolicy : "Always" # Image pull policy for deployed functions
@@ -94,7 +94,7 @@ faasnetes:
9494

9595
# replaces faas-netes with openfaas-operator
9696
operator:
97-
image: openfaas/openfaas-operator:0.14.3
97+
image: openfaas/faas-netes:0.10.2-rc1
9898
create: false
9999
# set this to false when creating multiple releases in the same cluster
100100
# must be true for the first one only

contrib/alpine-fn.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: openfaas.com/v1
2+
kind: Function
3+
metadata:
4+
name: nodeinfo
5+
namespace: openfaas-fn
6+
spec:
7+
name: nodeinfo
8+
image: functions/nodeinfo:latest

contrib/create_cluster.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
DEVENV=${OF_DEV_ENV:-kind}
4+
KUBE_VERSION=v1.17.0
5+
6+
echo ">>> Creating Kubernetes ${KUBE_VERSION} cluster"
7+
kind create cluster --wait 5m --image kindest/node:${KUBE_VERSION} --name "$DEVENV"
8+
9+
export KUBECONFIG="$(kind get kubeconfig-path --name="$DEVENV")"
10+
11+
echo ">>> Waiting for CoreDNS"
12+
kubectl -n kube-system rollout status deployment/coredns

contrib/create_dev.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
# Creates an installation of OpenFaaS in kind for development
44

5-
contrib/create_kind_cluster.sh
5+
contrib/create_cluster.sh
66
contrib/deploy.sh
77
contrib/run_function.sh

contrib/create_kind_cluster.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.

contrib/deploy.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/usr/bin/env bash
22

3+
set -e
4+
35
DEVENV=${OF_DEV_ENV:-kind}
6+
OPERATOR=${OPERATOR:-0}
47

58
export KUBECONFIG="$(kind get kubeconfig-path --name="$DEVENV")"
69

@@ -23,6 +26,11 @@ kubectl -n openfaas create secret generic basic-auth \
2326
--from-literal=basic-auth-user=admin \
2427
--from-literal=basic-auth-password="$PASSWORD"
2528

29+
CREATE_OPERATOR=false
30+
if [ "${OPERATOR}" == "1" ]; then
31+
CREATE_OPERATOR="true"
32+
fi
33+
2634
echo "Waiting for helm install to complete."
2735

2836
helm upgrade \
@@ -32,4 +40,13 @@ helm upgrade \
3240
--namespace openfaas \
3341
--set basic_auth=true \
3442
--set functionNamespace=openfaas-fn \
35-
--wait
43+
--set operator.create=$CREATE_OPERATOR
44+
45+
if [ "${OPERATOR}" == "1" ]; then
46+
47+
kubectl patch -n openfaas deploy/gateway \
48+
-p='[{"op": "add", "path": "/spec/template/spec/containers/1/command", "value": ["./faas-netes", "-operator=true"]} ]' --type=json
49+
fi
50+
51+
kubectl rollout status deploy/prometheus -n openfaas
52+
kubectl rollout status deploy/gateway -n openfaas

contrib/get_faas.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

contrib/get_kind.sh

Lines changed: 0 additions & 17 deletions
This file was deleted.

contrib/get_tools.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
KIND_VERSION="v0.7.0"
6+
HELM_VERSION=v3.0.3
7+
KUBE_VERSION=v0.7.0
8+
9+
if [[ "$1" ]]; then
10+
KUBE_VERSION=$1
11+
fi
12+
13+
echo ">>> Installing kind $KIND_VERSION"
14+
curl -sSLfO kind "https://github.com/kubernetes-sigs/kind/releases/download/$KIND_VERSION/kind-linux-amd64"
15+
chmod +x kind
16+
sudo mv kind /usr/local/bin/kind
17+
18+
echo ">>> Installing kubectl"
19+
curl -sSLfO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && \
20+
chmod +x kubectl && \
21+
sudo mv kubectl /usr/local/bin/
22+
23+
echo ">>> Installing Helm v3"
24+
curl -sSLf https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz | tar xz && \
25+
sudo mv linux-amd64/helm /usr/local/bin/ && \
26+
rm -rf linux-amd64
27+
28+
echo ">>> Installing faas-cli"
29+
curl -sSLf https://cli.openfaas.com | sudo sh
30+
faas-cli version

contrib/operator.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
OPERATOR=${OPERATOR:-0}
4+
5+
CREATE_OPERATOR=false
6+
7+
if [ "${OPERATOR}" == "1" ]; then
8+
CREATE_OPERATOR="true"
9+
fi
10+
11+
echo "Waiting for helm install to complete."
12+
13+
echo helm upgrade \
14+
--install \
15+
openfaas \
16+
./chart/openfaas \
17+
--namespace openfaas \
18+
--set basic_auth=true \
19+
--set functionNamespace=openfaas-fn \
20+
--set operator.create=$CREATE_OPERATOR \
21+
--wait

contrib/run_function.sh

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/usr/bin/env bash
22

3+
set -e
4+
35
DEVENV=${OF_DEV_ENV:-kind}
6+
OPERATOR=${OPERATOR:-0}
47

58
export KUBECONFIG="$(kind get kubeconfig-path --name="$DEVENV")"
69

@@ -11,7 +14,6 @@ then
1114
exit 1
1215
fi
1316

14-
1517
if [ -f "of_${DEVENV}_portforward.pid" ]; then
1618
kill $(<of_${DEVENV}_portforward.pid)
1719
fi
@@ -24,11 +26,12 @@ kubectl port-forward deploy/gateway -n openfaas 31112:8080 &>/dev/null & \
2426
# port-forward needs some time to start
2527
sleep 10
2628

27-
# Login in OpenFaas
2829
export OPENFAAS_URL=http://127.0.0.1:31112
2930

31+
# Login into the gateway
3032
cat ./password.txt | faas-cli login --username admin --password-stdin
3133

34+
# Deploy via the REST API which can test either the controller or operator
3235
faas-cli deploy --image=functions/alpine:latest --fprocess=cat --name "echo"
3336

3437
# Call echo function
@@ -42,4 +45,20 @@ do
4245
sleep 1
4346
done
4447

48+
# Apply a CRD to test the operator
49+
50+
if [ "${OPERATOR}" == "1" ]; then
51+
kubectl apply ./alpine-fn.yaml
52+
53+
for i in {1..180};
54+
do
55+
Ready="$(faas-cli describe nodeinfo | awk '{ if($1 ~ /Status:/) print $2 }')"
56+
if [[ $Ready == "Ready" ]];
57+
then
58+
exit 0
59+
fi
60+
sleep 1
61+
done
62+
fi
63+
4564
exit 1

contrib/stop_dev.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env bash
22

3-
43
DEVENV=${OF_DEV_ENV:-kind}
54

65
if [ -f "of_${DEVENV}_portforward.pid" ]; then

e2e/setup-cluster.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
5+
HELM_VERSION=v3.0.3
6+
KIND_VERSION=v0.7.0
7+
KUBE_VERSION=v1.17.0
8+
9+
if [[ "$1" ]]; then
10+
KUBE_VERSION=$1
11+
fi
12+
13+
echo ">>> Installing kubectl"
14+
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && \
15+
chmod +x kubectl && \
16+
sudo mv kubectl /usr/local/bin/
17+
18+
echo ">>> Installing kind $VER"
19+
20+
curl -sSLo kind "https://github.com/kubernetes-sigs/kind/releases/download/$KIND_VERSION/kind-linux-amd64"
21+
chmod +x kind
22+
sudo mv kind /usr/local/bin/kind
23+
24+
echo ">>> Creating Kubernetes ${KUBE_VERSION} cluster"
25+
kind create cluster --wait 5m --image kindest/node:${KUBE_VERSION}
26+
27+
echo ">>> Waiting for CoreDNS"
28+
kubectl -n kube-system rollout status deployment/coredns
29+
30+
echo ">>> Installing Helm v3"
31+
curl -sSL https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz | tar xz && \
32+
sudo mv linux-amd64/helm /usr/local/bin/ && \
33+
rm -rf linux-amd64
34+
35+
echo ">>> Add OpenFaaS Helm repo"
36+
helm repo add openfaas https://openfaas.github.io/faas-netes/

e2e/setup-openfaas.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
5+
REPO_ROOT=$(git rev-parse --show-toplevel)
6+
7+
logs() {
8+
kubectl -n openfaas get all
9+
kubectl -n openfaas describe deployment/gateway
10+
kubectl -n openfaas logs deployment/gateway -c operator
11+
}
12+
trap "logs" EXIT SIGINT
13+
14+
echo ">>> Load OpenFaaS operator local image onto the cluster"
15+
docker tag openfaas/openfaas-operator:latest test/openfaas-operator:latest
16+
kind load docker-image test/openfaas-operator:latest
17+
18+
echo ">>> Create OpenFaaS namespaces"
19+
kubectl apply -f https://raw.githubusercontent.com/openfaas/faas-netes/master/namespaces.yml
20+
21+
echo ">>> Create OpenFaaS CRD"
22+
kubectl apply -f ${REPO_ROOT}/artifacts/operator-crd.yaml
23+
24+
echo ">>> Install OpenFaaS with Helm"
25+
# the pull policy must be set to IfNotPresent for Kubernetes
26+
# to load the locally built image
27+
# we disable NATS and faasIdler as they slow down the startup
28+
# and have no impact on the operator testing
29+
helm upgrade -i openfaas openfaas/openfaas \
30+
--namespace openfaas \
31+
--set openfaasImagePullPolicy=IfNotPresent \
32+
--set functionNamespace=openfaas-fn \
33+
--set basic_auth=false \
34+
--set async=false \
35+
--set faasIdler.create=false \
36+
--set operator.create=true \
37+
--set operator.createCRD=false \
38+
--set operator.image=test/openfaas-operator:latest
39+
40+
echo ">>> Patch operator deployment"
41+
# we patch the operator deployment to make it
42+
# compatible with the current build
43+
TEMP_DIR=$(mktemp -d)
44+
cat > ${TEMP_DIR}/patch.yaml << EOL
45+
spec:
46+
template:
47+
spec:
48+
containers:
49+
- name: operator
50+
command:
51+
- ./openfaas-operator
52+
EOL
53+
kubectl -n openfaas patch deployment gateway --patch "$(cat ${TEMP_DIR}/patch.yaml)"
54+
55+
echo ">>> Wait for operator deployment to be ready"
56+
kubectl -n openfaas rollout status deployment/gateway --timeout=60s
57+
58+
59+
60+
61+

0 commit comments

Comments
 (0)