Skip to content

Commit

Permalink
Merge the operator and faas-netes
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
alexellis committed Apr 10, 2020
1 parent be9dec1 commit a18c035
Show file tree
Hide file tree
Showing 482 changed files with 68,392 additions and 9,834 deletions.
15 changes: 9 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ go:
- 1.13.x

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

services:
- docker
Expand All @@ -19,12 +18,16 @@ before_script:

script:
- make build
- ./contrib/get_tools.sh
- ./contrib/lint_chart.sh
- ./contrib/get_kind.sh
- ./contrib/create_kind_cluster.sh
- ./contrib/deploy.sh
- ./contrib/get_faas.sh
- ./contrib/create_cluster.sh
- OPERATOR=0 ./contrib/deploy.sh
- ./contrib/run_function.sh
- ./contrib/stop_dev.sh
- ./contrib/create_cluster.sh
- OPERATOR=1 ./contrib/deploy.sh
- OPERATOR=1 ./contrib/run_function.sh
- ./contrib/stop_dev.sh

after_success:
- if [ -z $DOCKER_NS ] ; then
Expand Down
2 changes: 1 addition & 1 deletion chart/openfaas/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Ease of use through UI portal and *one-click* install
* Write functions in any language for Linux or Windows and package in Docker/OCI image format
* Portable - runs on existing hardware or public/private cloud. Native [Kubernetes](https://github.com/openfaas/faas-netes) support, Docker Swarm also available
* [Operator / CRD option available](https://github.com/openfaas/openfaas-operator/)
* [Operator / CRD option available](https://github.com/openfaas/faas-netes/)
* [faas-cli](http://github.com/openfaas/faas-cli) available with stack.yml for creating and managing functions
* Auto-scales according to metrics from Prometheus
* Scales to zero and back again and can be tuned at a per-function level
Expand Down
3 changes: 2 additions & 1 deletion chart/openfaas/templates/gateway-dep.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ spec:
image: {{ .Values.operator.image }}
imagePullPolicy: {{ .Values.openfaasImagePullPolicy }}
command:
- ./openfaas-operator
- ./faas-netes
- -operator=true
env:
- name: port
value: "8081"
Expand Down
4 changes: 2 additions & 2 deletions chart/openfaas/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ oauth2Plugin:
securityContext: true

faasnetes:
image: openfaas/faas-netes:0.10.1
image: openfaas/faas-netes:0.10.2-rc1
readTimeout : "60s"
writeTimeout : "60s"
imagePullPolicy : "Always" # Image pull policy for deployed functions
Expand All @@ -94,7 +94,7 @@ faasnetes:

# replaces faas-netes with openfaas-operator
operator:
image: openfaas/openfaas-operator:0.14.3
image: openfaas/faas-netes:0.10.2-rc1
create: false
# set this to false when creating multiple releases in the same cluster
# must be true for the first one only
Expand Down
8 changes: 8 additions & 0 deletions contrib/alpine-fn.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: openfaas.com/v1
kind: Function
metadata:
name: nodeinfo
namespace: openfaas-fn
spec:
name: nodeinfo
image: functions/nodeinfo:latest
12 changes: 12 additions & 0 deletions contrib/create_cluster.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

DEVENV=${OF_DEV_ENV:-kind}
KUBE_VERSION=v1.17.0

echo ">>> Creating Kubernetes ${KUBE_VERSION} cluster"
kind create cluster --wait 5m --image kindest/node:${KUBE_VERSION} --name "$DEVENV"

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

echo ">>> Waiting for CoreDNS"
kubectl -n kube-system rollout status deployment/coredns
2 changes: 1 addition & 1 deletion contrib/create_dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

# Creates an installation of OpenFaaS in kind for development

contrib/create_kind_cluster.sh
contrib/create_cluster.sh
contrib/deploy.sh
contrib/run_function.sh
10 changes: 0 additions & 10 deletions contrib/create_kind_cluster.sh

This file was deleted.

19 changes: 18 additions & 1 deletion contrib/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env bash

set -e

DEVENV=${OF_DEV_ENV:-kind}
OPERATOR=${OPERATOR:-0}

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

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

CREATE_OPERATOR=false
if [ "${OPERATOR}" == "1" ]; then
CREATE_OPERATOR="true"
fi

echo "Waiting for helm install to complete."

helm upgrade \
Expand All @@ -32,4 +40,13 @@ helm upgrade \
--namespace openfaas \
--set basic_auth=true \
--set functionNamespace=openfaas-fn \
--wait
--set operator.create=$CREATE_OPERATOR

if [ "${OPERATOR}" == "1" ]; then

kubectl patch -n openfaas deploy/gateway \
-p='[{"op": "add", "path": "/spec/template/spec/containers/1/command", "value": ["./faas-netes", "-operator=true"]} ]' --type=json
fi

kubectl rollout status deploy/prometheus -n openfaas
kubectl rollout status deploy/gateway -n openfaas
5 changes: 0 additions & 5 deletions contrib/get_faas.sh

This file was deleted.

17 changes: 0 additions & 17 deletions contrib/get_kind.sh

This file was deleted.

30 changes: 30 additions & 0 deletions contrib/get_tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

set -e

KIND_VERSION="v0.7.0"
HELM_VERSION=v3.0.3
KUBE_VERSION=v0.7.0

if [[ "$1" ]]; then
KUBE_VERSION=$1
fi

echo ">>> Installing kind $KIND_VERSION"
curl -sSLfO kind "https://github.com/kubernetes-sigs/kind/releases/download/$KIND_VERSION/kind-linux-amd64"
chmod +x kind
sudo mv kind /usr/local/bin/kind

echo ">>> Installing kubectl"
curl -sSLfO 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/

echo ">>> Installing Helm v3"
curl -sSLf https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz | tar xz && \
sudo mv linux-amd64/helm /usr/local/bin/ && \
rm -rf linux-amd64

echo ">>> Installing faas-cli"
curl -sSLf https://cli.openfaas.com | sudo sh
faas-cli version
21 changes: 21 additions & 0 deletions contrib/operator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

OPERATOR=${OPERATOR:-0}

CREATE_OPERATOR=false

if [ "${OPERATOR}" == "1" ]; then
CREATE_OPERATOR="true"
fi

echo "Waiting for helm install to complete."

echo helm upgrade \
--install \
openfaas \
./chart/openfaas \
--namespace openfaas \
--set basic_auth=true \
--set functionNamespace=openfaas-fn \
--set operator.create=$CREATE_OPERATOR \
--wait
23 changes: 21 additions & 2 deletions contrib/run_function.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env bash

set -e

DEVENV=${OF_DEV_ENV:-kind}
OPERATOR=${OPERATOR:-0}

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

Expand All @@ -11,7 +14,6 @@ then
exit 1
fi


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

# Login in OpenFaas
export OPENFAAS_URL=http://127.0.0.1:31112

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

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

# Call echo function
Expand All @@ -42,4 +45,20 @@ do
sleep 1
done

# Apply a CRD to test the operator

if [ "${OPERATOR}" == "1" ]; then
kubectl apply ./alpine-fn.yaml

for i in {1..180};
do
Ready="$(faas-cli describe nodeinfo | awk '{ if($1 ~ /Status:/) print $2 }')"
if [[ $Ready == "Ready" ]];
then
exit 0
fi
sleep 1
done
fi

exit 1
1 change: 0 additions & 1 deletion contrib/stop_dev.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env bash


DEVENV=${OF_DEV_ENV:-kind}

if [ -f "of_${DEVENV}_portforward.pid" ]; then
Expand Down
36 changes: 36 additions & 0 deletions e2e/setup-cluster.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash

set -o errexit

HELM_VERSION=v3.0.3
KIND_VERSION=v0.7.0
KUBE_VERSION=v1.17.0

if [[ "$1" ]]; then
KUBE_VERSION=$1
fi

echo ">>> Installing 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/

echo ">>> Installing kind $VER"

curl -sSLo kind "https://github.com/kubernetes-sigs/kind/releases/download/$KIND_VERSION/kind-linux-amd64"
chmod +x kind
sudo mv kind /usr/local/bin/kind

echo ">>> Creating Kubernetes ${KUBE_VERSION} cluster"
kind create cluster --wait 5m --image kindest/node:${KUBE_VERSION}

echo ">>> Waiting for CoreDNS"
kubectl -n kube-system rollout status deployment/coredns

echo ">>> Installing Helm v3"
curl -sSL https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz | tar xz && \
sudo mv linux-amd64/helm /usr/local/bin/ && \
rm -rf linux-amd64

echo ">>> Add OpenFaaS Helm repo"
helm repo add openfaas https://openfaas.github.io/faas-netes/
61 changes: 61 additions & 0 deletions e2e/setup-openfaas.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env bash

set -o errexit

REPO_ROOT=$(git rev-parse --show-toplevel)

logs() {
kubectl -n openfaas get all
kubectl -n openfaas describe deployment/gateway
kubectl -n openfaas logs deployment/gateway -c operator
}
trap "logs" EXIT SIGINT

echo ">>> Load OpenFaaS operator local image onto the cluster"
docker tag openfaas/openfaas-operator:latest test/openfaas-operator:latest
kind load docker-image test/openfaas-operator:latest

echo ">>> Create OpenFaaS namespaces"
kubectl apply -f https://raw.githubusercontent.com/openfaas/faas-netes/master/namespaces.yml

echo ">>> Create OpenFaaS CRD"
kubectl apply -f ${REPO_ROOT}/artifacts/operator-crd.yaml

echo ">>> Install OpenFaaS with Helm"
# the pull policy must be set to IfNotPresent for Kubernetes
# to load the locally built image
# we disable NATS and faasIdler as they slow down the startup
# and have no impact on the operator testing
helm upgrade -i openfaas openfaas/openfaas \
--namespace openfaas \
--set openfaasImagePullPolicy=IfNotPresent \
--set functionNamespace=openfaas-fn \
--set basic_auth=false \
--set async=false \
--set faasIdler.create=false \
--set operator.create=true \
--set operator.createCRD=false \
--set operator.image=test/openfaas-operator:latest

echo ">>> Patch operator deployment"
# we patch the operator deployment to make it
# compatible with the current build
TEMP_DIR=$(mktemp -d)
cat > ${TEMP_DIR}/patch.yaml << EOL
spec:
template:
spec:
containers:
- name: operator
command:
- ./openfaas-operator
EOL
kubectl -n openfaas patch deployment gateway --patch "$(cat ${TEMP_DIR}/patch.yaml)"

echo ">>> Wait for operator deployment to be ready"
kubectl -n openfaas rollout status deployment/gateway --timeout=60s





Loading

0 comments on commit a18c035

Please sign in to comment.