diff --git a/.gitignore b/.gitignore index 5c602f897b..6b187ddf7d 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,5 @@ gh-pages /.env /.gocache/ /bin/ + +test/e2e-image/wait-for-nginx\.sh diff --git a/.travis.yml b/.travis.yml index 9dfad7dfb4..8b8425507a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,10 +44,12 @@ jobs: - stage: e2e if: (branch = master AND env(COMPONENT) != "docs") OR (type = pull_request AND commit_message !~ /(skip-e2e)/) before_script: + - sudo mkdir -p /home/travis/.kube/ && sudo chmod 777 /home/travis/.kube/ + - curl -sSL -o kubectl https://storage.googleapis.com/kubernetes-release/release/v1.13.4/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/ + - curl -sSL -o kind https://github.com/kubernetes-sigs/kind/releases/download/0.2.0/kind-linux-amd64 && chmod +x kind && sudo mv kind /usr/local/bin/ - make e2e-test-image - - test/e2e/up.sh script: - - KUBECONFIG=$(cat /tmp/kubeconfig) make e2e-test + - test/e2e/run.sh # split builds to avoid job timeouts - stage: publish amd64 if: type = api AND branch = master AND repo = kubernetes/ingress-nginx AND env(COMPONENT) = "ingress-controller" diff --git a/Makefile b/Makefile index 1e43d01238..d98b5ad34f 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ GOHOSTOS ?= $(shell go env GOHOSTOS) # Allow limiting the scope of the e2e tests. By default run everything FOCUS ?= .* # number of parallel test -E2E_NODES ?= 8 +E2E_NODES ?= 10 # slow test only if takes > 50s SLOW_E2E_THRESHOLD ?= 50 @@ -184,10 +184,10 @@ lua-test: .PHONY: e2e-test e2e-test: if [ "$(KUBECTL_CONTEXT)" != "minikube" ] && \ - [ "$(KUBECTL_CONTEXT)" != "kind" ] && \ + [ "$(KUBECTL_CONTEXT)" =~ .*kind* ] && \ [ "$(KUBECTL_CONTEXT)" != "dind" ] && \ [ "$(KUBECTL_CONTEXT)" != "docker-for-desktop" ]; then \ - echo "kubectl context is "$(KUBECTL_CONTEXT)", but must be one of [minikube, kind, dind, docker-for-deskop]"; \ + echo "kubectl context is "$(KUBECTL_CONTEXT)", but must be one of [minikube, *kind*, dind, docker-for-deskop]"; \ exit 1; \ fi diff --git a/test/e2e/kind.yaml b/test/e2e/kind.yaml new file mode 100644 index 0000000000..b6a4d5dbe2 --- /dev/null +++ b/test/e2e/kind.yaml @@ -0,0 +1,6 @@ +kind: Config +apiVersion: kind.sigs.k8s.io/v1alpha2 +nodes: + - role: control-plane + - role: worker + replicas: 3 diff --git a/test/e2e/run.sh b/test/e2e/run.sh new file mode 100755 index 0000000000..7849e906e4 --- /dev/null +++ b/test/e2e/run.sh @@ -0,0 +1,55 @@ +#!/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 -e + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +export TAG=dev +export ARCH=amd64 +export REGISTRY=${REGISTRY:-ingress-controller} + +KIND_CLUSTER_NAME="ingress-nginx-dev" + +kind --version || $(echo "Please install kind before running e2e tests";exit 1) + +SKIP_CLUSTER_CREATION=${SKIP_CLUSTER_CREATION:-} +if [ -z "${SKIP_CLUSTER_CREATION}" ]; then + echo "[dev-env] creating Kubernetes cluster with kind" + kind create cluster --name ${KIND_CLUSTER_NAME} --config ${DIR}/kind.yaml +fi + +export KUBECONFIG="$(kind get kubeconfig-path --name="${KIND_CLUSTER_NAME}")" + +sleep 60 + +echo "Kubernetes cluster:" +kubectl get nodes -o wide + +echo "[dev-env] installing kubectl" +kubectl version || $(echo "Please install kubectl before running e2e tests";exit 1) + +kubectl config set-context kubernetes-admin@${KIND_CLUSTER_NAME} + +echo "[dev-env] building container" +make -C ${DIR}/../../ build container +make -C ${DIR}/../../ e2e-test-image + +echo "copying docker images to cluster..." +kind load docker-image --name="${KIND_CLUSTER_NAME}" ${REGISTRY}/nginx-ingress-controller:${TAG} +kind load docker-image --name="${KIND_CLUSTER_NAME}" nginx-ingress-controller:e2e + +make -C ${DIR}/../../ e2e-test diff --git a/test/e2e/up.sh b/test/e2e/up.sh deleted file mode 100755 index 3914cb2c0b..0000000000 --- a/test/e2e/up.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/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 -e - -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -if test -e kubectl; then - echo "skipping download of kubectl" -else - echo "downloading kubectl..." - curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.13.3/bin/linux/amd64/kubectl \ - && chmod +x kubectl && sudo mv kubectl /usr/local/bin/ -fi - -export KUBECONFIG="$(mktemp)" -echo -n ${KUBECONFIG} > /tmp/kubeconfig - -echo "starting Kubernetes cluster..." -K8S_VERSION=v1.11 -KDC_SHA=e505612125948bab5a415ec3e5c1f9f26324488f28286e005fd1f3a0a6292c49 -curl -Lo $DIR/dind-cluster-$K8S_VERSION.sh https://github.com/kubernetes-sigs/kubeadm-dind-cluster/releases/download/v0.1.0/dind-cluster-$K8S_VERSION.sh && \ - chmod +x $DIR/dind-cluster-$K8S_VERSION.sh - -echo "$KDC_SHA $DIR/dind-cluster-$K8S_VERSION.sh" | sha256sum -c - || exit 10 -$DIR/dind-cluster-$K8S_VERSION.sh up - -kubectl config use-context dind - -echo "Kubernetes cluster:" -kubectl get nodes -o wide - -export TAG=dev -export ARCH=amd64 -export REGISTRY=${REGISTRY:-ingress-controller} - -echo "building container..." -make -C ${DIR}/../../ build container - -echo "copying docker image to cluster..." -DEV_IMAGE=${REGISTRY}/nginx-ingress-controller:${TAG} -${DIR}/dind-cluster-v1.11.sh copy-image ${DEV_IMAGE} - -echo "copying e2e docker image to cluster..." -${DIR}/dind-cluster-v1.11.sh copy-image nginx-ingress-controller:e2e