Refactor scripts to run e2e tests

This commit is contained in:
Manuel Alejandro de Brito Fontes 2019-05-13 22:31:30 -04:00
parent 7be1dccea7
commit be2792c5f9
No known key found for this signature in database
GPG key ID: 786136016A8BA02A
6 changed files with 68 additions and 129 deletions

108
Makefile
View file

@ -12,6 +12,11 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
ifeq (run-in-docker,$(firstword $(MAKECMDGOALS)))
RUN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
$(eval $(RUN_ARGS):;@:)
endif
.PHONY: all .PHONY: all
all: all-container all: all-container
@ -34,27 +39,31 @@ ifeq ($(GOHOSTOS),darwin)
SED_I=sed -i '' SED_I=sed -i ''
endif endif
REPO_INFO=$(shell git config --get remote.origin.url) REPO_INFO ?= $(shell git config --get remote.origin.url)
GIT_COMMIT ?= git-$(shell git rev-parse --short HEAD)
ifndef GIT_COMMIT
GIT_COMMIT := git-$(shell git rev-parse --short HEAD)
endif
PKG = k8s.io/ingress-nginx PKG = k8s.io/ingress-nginx
ARCH ?= $(shell go env GOARCH) ARCH ?= $(shell go env GOARCH)
GOARCH = ${ARCH} GOARCH = ${ARCH}
DUMB_ARCH = ${ARCH} DUMB_ARCH = ${ARCH}
KUBECTL_CONTEXT = $(shell kubectl config current-context)
GOBUILD_FLAGS := GOBUILD_FLAGS := -v
ALL_ARCH = amd64 arm64 ALL_ARCH = amd64 arm64
QEMUVERSION = v3.0.0 QEMUVERSION = v4.0.0
BUSTED_ARGS =-v --pattern=_test BUSTED_ARGS =-v --pattern=_test
export ARCH
export TAG
export PKG
export GOARCH
export GIT_COMMIT
export GOBUILD_FLAGS
export REPO_INFO
IMGNAME = nginx-ingress-controller IMGNAME = nginx-ingress-controller
IMAGE = $(REGISTRY)/$(IMGNAME) IMAGE = $(REGISTRY)/$(IMGNAME)
MULTI_ARCH_IMG = $(IMAGE)-$(ARCH) MULTI_ARCH_IMG = $(IMAGE)-$(ARCH)
@ -68,20 +77,8 @@ endif
TEMP_DIR := $(shell mktemp -d) TEMP_DIR := $(shell mktemp -d)
DEF_VARS:=ARCH=$(ARCH) \
TAG=$(TAG) \
PKG=$(PKG) \
GOARCH=$(GOARCH) \
GIT_COMMIT=$(GIT_COMMIT) \
REPO_INFO=$(REPO_INFO) \
PWD=$(PWD)
DOCKERFILE := $(TEMP_DIR)/rootfs/Dockerfile DOCKERFILE := $(TEMP_DIR)/rootfs/Dockerfile
.PHONY: image-info
image-info:
echo -n '{"image":"$(IMAGE)","tag":"$(TAG)"}'
.PHONY: sub-container-% .PHONY: sub-container-%
sub-container-%: sub-container-%:
$(MAKE) ARCH=$* build container $(MAKE) ARCH=$* build container
@ -101,11 +98,10 @@ container: clean-container .container-$(ARCH)
.PHONY: .container-$(ARCH) .PHONY: .container-$(ARCH)
.container-$(ARCH): .container-$(ARCH):
@echo "+ Copying artifact to temporary directory"
mkdir -p $(TEMP_DIR)/rootfs mkdir -p $(TEMP_DIR)/rootfs
cp bin/$(ARCH)/nginx-ingress-controller $(TEMP_DIR)/rootfs/nginx-ingress-controller cp bin/$(ARCH)/nginx-ingress-controller $(TEMP_DIR)/rootfs/nginx-ingress-controller
cp bin/$(ARCH)/dbg $(TEMP_DIR)/rootfs/dbg cp bin/$(ARCH)/dbg $(TEMP_DIR)/rootfs/dbg
@echo "+ Building container image $(MULTI_ARCH_IMG):$(TAG)"
cp -RP ./* $(TEMP_DIR) cp -RP ./* $(TEMP_DIR)
$(SED_I) "s|BASEIMAGE|$(BASEIMAGE)|g" $(DOCKERFILE) $(SED_I) "s|BASEIMAGE|$(BASEIMAGE)|g" $(DOCKERFILE)
$(SED_I) "s|QEMUARCH|$(QEMUARCH)|g" $(DOCKERFILE) $(SED_I) "s|QEMUARCH|$(QEMUARCH)|g" $(DOCKERFILE)
@ -129,7 +125,6 @@ endif
.PHONY: clean-container .PHONY: clean-container
clean-container: clean-container:
@echo "+ Deleting container image $(MULTI_ARCH_IMG):$(TAG)"
$(DOCKER) rmi -f $(MULTI_ARCH_IMG):$(TAG) || true $(DOCKER) rmi -f $(MULTI_ARCH_IMG):$(TAG) || true
.PHONY: register-qemu .PHONY: register-qemu
@ -149,16 +144,11 @@ endif
.PHONY: build .PHONY: build
build: build:
@echo "+ Building bin/$(ARCH)/nginx-ingress-controller" build/build.sh
@$(DEF_VARS) \
GOBUILD_FLAGS="$(GOBUILD_FLAGS)" \
build/go-in-docker.sh build/build.sh
.PHONY: build-plugin .PHONY: build-plugin
build-plugin: build-plugin:
@$(DEF_VARS) \ build/build-plugin.sh
GOBUILD_FLAGS="$(GOBUILD_FLAGS)" \
build/go-in-docker.sh build/build-plugin.sh
.PHONY: clean .PHONY: clean
clean: clean:
@ -166,32 +156,18 @@ clean:
.PHONY: static-check .PHONY: static-check
static-check: static-check:
@$(DEF_VARS) \ build/static-check.sh
build/go-in-docker.sh build/static-check.sh
.PHONY: test .PHONY: test
test: test:
@$(DEF_VARS) \ build/test.sh
DOCKER_OPTS="-i --net=host" \
build/go-in-docker.sh build/test.sh
.PHONY: lua-test .PHONY: lua-test
lua-test: lua-test:
@$(DEF_VARS) \ build/test-lua.sh
BUSTED_ARGS="$(BUSTED_ARGS)" \
build/go-in-docker.sh build/test-lua.sh
.PHONY: e2e-test .PHONY: e2e-test
e2e-test: e2e-test:
if [ "$(KUBECTL_CONTEXT)" != "minikube" ] && \
! echo $(KUBECTL_CONTEXT) | grep kind && \
! echo $(KUBECTL_CONTEXT) | grep ingress-nginx-dev && \
[ "$(KUBECTL_CONTEXT)" != "dind" ] && \
[ "$(KUBECTL_CONTEXT)" != "docker-for-desktop" ]; then \
echo "kubectl context is "$(KUBECTL_CONTEXT)", but must be one of [minikube, *kind*, *ingress-nginx-dev*, dind, docker-for-deskop]"; \
exit 1; \
fi
echo "Granting permissions to ingress-nginx e2e service account..." echo "Granting permissions to ingress-nginx e2e service account..."
kubectl create serviceaccount ingress-nginx-e2e || true kubectl create serviceaccount ingress-nginx-e2e || true
kubectl create clusterrolebinding permissive-binding \ kubectl create clusterrolebinding permissive-binding \
@ -205,7 +181,7 @@ e2e-test:
sleep 3; \ sleep 3; \
done done
kubectl run --rm -i --tty \ kubectl run --rm \
--attach \ --attach \
--restart=Never \ --restart=Never \
--generator=run-pod/v1 \ --generator=run-pod/v1 \
@ -216,27 +192,22 @@ e2e-test:
e2e --image=nginx-ingress-controller:e2e e2e --image=nginx-ingress-controller:e2e
.PHONY: e2e-test-image .PHONY: e2e-test-image
e2e-test-image: e2e-test-image: e2e-test-binary
make -C test/e2e-image make -C test/e2e-image
.PHONY: e2e-test-binary .PHONY: e2e-test-binary
e2e-test-binary: e2e-test-binary:
@$(DEF_VARS) \ ginkgo build ./test/e2e
DOCKER_OPTS="-i --net=host" \
build/go-in-docker.sh build/build-e2e.sh
.PHONY: cover .PHONY: cover
cover: cover:
@$(DEF_VARS) \ build/cover.sh
DOCKER_OPTS="-i --net=host" \
build/go-in-docker.sh build/cover.sh
echo "Uploading coverage results..." echo "Uploading coverage results..."
@curl -s https://codecov.io/bash | bash curl -s https://codecov.io/bash | bash
.PHONY: vet .PHONY: vet
vet: vet:
@go vet $(shell go list ${PKG}/... | grep -v vendor) go vet $(shell go list ${PKG}/... | grep -v vendor)
.PHONY: release .PHONY: release
release: all-container all-push release: all-container all-push
@ -256,22 +227,31 @@ dep-ensure:
.PHONY: dev-env .PHONY: dev-env
dev-env: dev-env:
@build/dev-env.sh build/dev-env.sh
.PHONY: live-docs .PHONY: live-docs
live-docs: live-docs:
@docker build --pull -t ingress-nginx/mkdocs build/mkdocs docker build --pull -t ingress-nginx/mkdocs build/mkdocs
@docker run --rm -it -p 3000:3000 -v ${PWD}:/docs ingress-nginx/mkdocs docker run --rm -it -p 3000:3000 -v ${PWD}:/docs ingress-nginx/mkdocs
.PHONY: build-docs .PHONY: build-docs
build-docs: build-docs:
@docker build --pull -t ingress-nginx/mkdocs build/mkdocs docker build --pull -t ingress-nginx/mkdocs build/mkdocs
@docker run --rm -it -v ${PWD}:/docs ingress-nginx/mkdocs build docker run --rm -v ${PWD}:/docs ingress-nginx/mkdocs build
.PHONY: misspell .PHONY: misspell
misspell: misspell:
@go get github.com/client9/misspell/cmd/misspell go get github.com/client9/misspell/cmd/misspell
misspell \ misspell \
-locale US \ -locale US \
-error \ -error \
cmd/* internal/* deploy/* docs/* design/* test/* README.md cmd/* internal/* deploy/* docs/* design/* test/* README.md
.PHONE: kind-e2e-test
kind-e2e-test:
test/e2e/run.sh
.PHONE: run-in-docker
run-in-docker:
# dummy target

View file

@ -1,21 +0,0 @@
#!/bin/bash
# Copyright 2019 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
ginkgo build ./test/e2e

View file

@ -14,33 +14,15 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
if ! [ -z $DEBUG ]; then
set -x
fi
set -o errexit set -o errexit
set -o nounset set -o nounset
set -o pipefail set -o pipefail
declare -a mandatory E2E_IMAGE=quay.io/kubernetes-ingress-controller/e2e:v05122019-7b3f69a3ba
mandatory=(
PKG
ARCH
GIT_COMMIT
REPO_INFO
TAG
HOME
)
missing=false
for var in ${mandatory[@]}; do
if [[ -z "${!var+x}" ]]; then
echo "Environment variable $var must be set"
missing=true
fi
done
if [ "$missing" = true ];then
exit 1
fi
E2E_IMAGE=quay.io/kubernetes-ingress-controller/e2e:v05062019-b4f2880ee
DOCKER_OPTS=${DOCKER_OPTS:-""} DOCKER_OPTS=${DOCKER_OPTS:-""}
@ -51,8 +33,7 @@ PKG=${PKG:-""}
ARCH=${ARCH:-""} ARCH=${ARCH:-""}
GIT_COMMIT=${GIT_COMMIT:-""} GIT_COMMIT=${GIT_COMMIT:-""}
TAG=${TAG:-"0.0"} TAG=${TAG:-"0.0"}
HOME=${HOME:-/root} GOARCH=${GOARCH:-""}
GOARCH=${GOARCH}
GOBUILD_FLAGS=${GOBUILD_FLAGS:-"-v"} GOBUILD_FLAGS=${GOBUILD_FLAGS:-"-v"}
PWD=${PWD} PWD=${PWD}
BUSTED_ARGS=${BUSTED_ARGS:-""} BUSTED_ARGS=${BUSTED_ARGS:-""}
@ -74,6 +55,7 @@ docker run \
-v ${PWD}:/go/src/${PKG} \ -v ${PWD}:/go/src/${PKG} \
-v ${PWD}/.gocache:${HOME}/.cache/go-build \ -v ${PWD}/.gocache:${HOME}/.cache/go-build \
-v ${PWD}/bin/${ARCH}:/go/bin/linux_${ARCH} \ -v ${PWD}/bin/${ARCH}:/go/bin/linux_${ARCH} \
-v /var/run/docker.sock:/var/run/docker.sock \
${MINIKUBE_VOLUME} \ ${MINIKUBE_VOLUME} \
-w /go/src/${PKG} \ -w /go/src/${PKG} \
--env-file .env \ --env-file .env \

View file

@ -119,7 +119,8 @@ def file_passes(filename, refs, regexs):
# if we don't match the reference at this point, fail # if we don't match the reference at this point, fail
if ref != data: if ref != data:
print("Header in %s does not match reference, diff:" % filename, file=verbose_out) print("Header in %s does not match reference, diff:" %
filename, file=verbose_out)
if args.verbose: if args.verbose:
print(file=verbose_out) print(file=verbose_out)
for line in difflib.unified_diff(ref, data, 'reference', filename, lineterm=''): for line in difflib.unified_diff(ref, data, 'reference', filename, lineterm=''):
@ -138,8 +139,6 @@ skipped_dirs = [
'.git', '.git',
"vendor", "vendor",
"test/e2e/framework/framework.go", "test/e2e/framework/framework.go",
"hack/boilerplate/test",
"test/e2e/dind-cluster-v1.11.sh"
] ]

View file

@ -19,7 +19,7 @@ set -o nounset
set -o pipefail set -o pipefail
SCRIPT_ROOT=$(dirname ${BASH_SOURCE})/.. 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)} 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: # generate the code with:
# --output-base because this script should also be able to run inside the vendor dir of # --output-base because this script should also be able to run inside the vendor dir of

View file

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
# Copyright 2017 The Kubernetes Authors. # Copyright 2019 The Kubernetes Authors.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
@ -14,42 +14,41 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
set -e if ! [ -z $DEBUG ]; then
set -x
fi
set -o errexit
set -o nounset
set -o pipefail
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export TAG=dev export TAG=dev
export ARCH=amd64 export ARCH=amd64
export REGISTRY=${REGISTRY:-ingress-controller} export REGISTRY=ingress-controller
KIND_CLUSTER_NAME="ingress-nginx-dev" KIND_CLUSTER_NAME="ingress-nginx-dev"
kind --version || $(echo "Please install kind before running e2e tests";exit 1) kind --version || $(echo "Please install kind before running e2e tests";exit 1)
SKIP_CLUSTER_CREATION=${SKIP_CLUSTER_CREATION:-} echo "[dev-env] creating Kubernetes cluster with kind"
if [ -z "${SKIP_CLUSTER_CREATION}" ]; then kind create cluster --name ${KIND_CLUSTER_NAME} --config ${DIR}/kind.yaml
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}")" export KUBECONFIG="$(kind get kubeconfig-path --name="${KIND_CLUSTER_NAME}")"
sleep 60
echo "Kubernetes cluster:" echo "Kubernetes cluster:"
kubectl get nodes -o wide 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} kubectl config set-context kubernetes-admin@${KIND_CLUSTER_NAME}
echo "[dev-env] building container" echo "[dev-env] building container"
make -C ${DIR}/../../ build container make -C ${DIR}/../../ build container
make -C ${DIR}/../../ e2e-test-image make -C ${DIR}/../../ e2e-test-image
echo "copying docker images to cluster..." echo "[dev-env] 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 kind load docker-image --name="${KIND_CLUSTER_NAME}" nginx-ingress-controller:e2e
kind load docker-image --name="${KIND_CLUSTER_NAME}" ${REGISTRY}/nginx-ingress-controller:${TAG}
echo "[dev-env] running e2e tests..."
make -C ${DIR}/../../ e2e-test make -C ${DIR}/../../ e2e-test