Refactor scripts to run e2e tests
This commit is contained in:
parent
7be1dccea7
commit
be2792c5f9
6 changed files with 68 additions and 129 deletions
108
Makefile
108
Makefile
|
@ -12,6 +12,11 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
ifeq (run-in-docker,$(firstword $(MAKECMDGOALS)))
|
||||
RUN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
|
||||
$(eval $(RUN_ARGS):;@:)
|
||||
endif
|
||||
|
||||
.PHONY: all
|
||||
all: all-container
|
||||
|
||||
|
@ -34,27 +39,31 @@ ifeq ($(GOHOSTOS),darwin)
|
|||
SED_I=sed -i ''
|
||||
endif
|
||||
|
||||
REPO_INFO=$(shell git config --get remote.origin.url)
|
||||
|
||||
ifndef GIT_COMMIT
|
||||
GIT_COMMIT := git-$(shell git rev-parse --short HEAD)
|
||||
endif
|
||||
REPO_INFO ?= $(shell git config --get remote.origin.url)
|
||||
GIT_COMMIT ?= git-$(shell git rev-parse --short HEAD)
|
||||
|
||||
PKG = k8s.io/ingress-nginx
|
||||
|
||||
ARCH ?= $(shell go env GOARCH)
|
||||
GOARCH = ${ARCH}
|
||||
DUMB_ARCH = ${ARCH}
|
||||
KUBECTL_CONTEXT = $(shell kubectl config current-context)
|
||||
|
||||
GOBUILD_FLAGS :=
|
||||
GOBUILD_FLAGS := -v
|
||||
|
||||
ALL_ARCH = amd64 arm64
|
||||
|
||||
QEMUVERSION = v3.0.0
|
||||
QEMUVERSION = v4.0.0
|
||||
|
||||
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
|
||||
IMAGE = $(REGISTRY)/$(IMGNAME)
|
||||
MULTI_ARCH_IMG = $(IMAGE)-$(ARCH)
|
||||
|
@ -68,20 +77,8 @@ endif
|
|||
|
||||
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
|
||||
|
||||
.PHONY: image-info
|
||||
image-info:
|
||||
echo -n '{"image":"$(IMAGE)","tag":"$(TAG)"}'
|
||||
|
||||
.PHONY: sub-container-%
|
||||
sub-container-%:
|
||||
$(MAKE) ARCH=$* build container
|
||||
|
@ -101,11 +98,10 @@ container: clean-container .container-$(ARCH)
|
|||
|
||||
.PHONY: .container-$(ARCH)
|
||||
.container-$(ARCH):
|
||||
@echo "+ Copying artifact to temporary directory"
|
||||
mkdir -p $(TEMP_DIR)/rootfs
|
||||
cp bin/$(ARCH)/nginx-ingress-controller $(TEMP_DIR)/rootfs/nginx-ingress-controller
|
||||
cp bin/$(ARCH)/dbg $(TEMP_DIR)/rootfs/dbg
|
||||
@echo "+ Building container image $(MULTI_ARCH_IMG):$(TAG)"
|
||||
|
||||
cp -RP ./* $(TEMP_DIR)
|
||||
$(SED_I) "s|BASEIMAGE|$(BASEIMAGE)|g" $(DOCKERFILE)
|
||||
$(SED_I) "s|QEMUARCH|$(QEMUARCH)|g" $(DOCKERFILE)
|
||||
|
@ -129,7 +125,6 @@ endif
|
|||
|
||||
.PHONY: clean-container
|
||||
clean-container:
|
||||
@echo "+ Deleting container image $(MULTI_ARCH_IMG):$(TAG)"
|
||||
$(DOCKER) rmi -f $(MULTI_ARCH_IMG):$(TAG) || true
|
||||
|
||||
.PHONY: register-qemu
|
||||
|
@ -149,16 +144,11 @@ endif
|
|||
|
||||
.PHONY: build
|
||||
build:
|
||||
@echo "+ Building bin/$(ARCH)/nginx-ingress-controller"
|
||||
@$(DEF_VARS) \
|
||||
GOBUILD_FLAGS="$(GOBUILD_FLAGS)" \
|
||||
build/go-in-docker.sh build/build.sh
|
||||
build/build.sh
|
||||
|
||||
.PHONY: build-plugin
|
||||
build-plugin:
|
||||
@$(DEF_VARS) \
|
||||
GOBUILD_FLAGS="$(GOBUILD_FLAGS)" \
|
||||
build/go-in-docker.sh build/build-plugin.sh
|
||||
build/build-plugin.sh
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
|
@ -166,32 +156,18 @@ clean:
|
|||
|
||||
.PHONY: static-check
|
||||
static-check:
|
||||
@$(DEF_VARS) \
|
||||
build/go-in-docker.sh build/static-check.sh
|
||||
build/static-check.sh
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
@$(DEF_VARS) \
|
||||
DOCKER_OPTS="-i --net=host" \
|
||||
build/go-in-docker.sh build/test.sh
|
||||
build/test.sh
|
||||
|
||||
.PHONY: lua-test
|
||||
lua-test:
|
||||
@$(DEF_VARS) \
|
||||
BUSTED_ARGS="$(BUSTED_ARGS)" \
|
||||
build/go-in-docker.sh build/test-lua.sh
|
||||
build/test-lua.sh
|
||||
|
||||
.PHONY: 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..."
|
||||
kubectl create serviceaccount ingress-nginx-e2e || true
|
||||
kubectl create clusterrolebinding permissive-binding \
|
||||
|
@ -205,7 +181,7 @@ e2e-test:
|
|||
sleep 3; \
|
||||
done
|
||||
|
||||
kubectl run --rm -i --tty \
|
||||
kubectl run --rm \
|
||||
--attach \
|
||||
--restart=Never \
|
||||
--generator=run-pod/v1 \
|
||||
|
@ -216,27 +192,22 @@ e2e-test:
|
|||
e2e --image=nginx-ingress-controller:e2e
|
||||
|
||||
.PHONY: e2e-test-image
|
||||
e2e-test-image:
|
||||
e2e-test-image: e2e-test-binary
|
||||
make -C test/e2e-image
|
||||
|
||||
.PHONY: e2e-test-binary
|
||||
e2e-test-binary:
|
||||
@$(DEF_VARS) \
|
||||
DOCKER_OPTS="-i --net=host" \
|
||||
build/go-in-docker.sh build/build-e2e.sh
|
||||
ginkgo build ./test/e2e
|
||||
|
||||
.PHONY: cover
|
||||
cover:
|
||||
@$(DEF_VARS) \
|
||||
DOCKER_OPTS="-i --net=host" \
|
||||
build/go-in-docker.sh build/cover.sh
|
||||
|
||||
build/cover.sh
|
||||
echo "Uploading coverage results..."
|
||||
@curl -s https://codecov.io/bash | bash
|
||||
curl -s https://codecov.io/bash | bash
|
||||
|
||||
.PHONY: vet
|
||||
vet:
|
||||
@go vet $(shell go list ${PKG}/... | grep -v vendor)
|
||||
go vet $(shell go list ${PKG}/... | grep -v vendor)
|
||||
|
||||
.PHONY: release
|
||||
release: all-container all-push
|
||||
|
@ -256,22 +227,31 @@ dep-ensure:
|
|||
|
||||
.PHONY: dev-env
|
||||
dev-env:
|
||||
@build/dev-env.sh
|
||||
build/dev-env.sh
|
||||
|
||||
.PHONY: live-docs
|
||||
live-docs:
|
||||
@docker build --pull -t ingress-nginx/mkdocs build/mkdocs
|
||||
@docker run --rm -it -p 3000:3000 -v ${PWD}:/docs ingress-nginx/mkdocs
|
||||
docker build --pull -t ingress-nginx/mkdocs build/mkdocs
|
||||
docker run --rm -it -p 3000:3000 -v ${PWD}:/docs ingress-nginx/mkdocs
|
||||
|
||||
.PHONY: build-docs
|
||||
build-docs:
|
||||
@docker build --pull -t ingress-nginx/mkdocs build/mkdocs
|
||||
@docker run --rm -it -v ${PWD}:/docs ingress-nginx/mkdocs build
|
||||
docker build --pull -t ingress-nginx/mkdocs build/mkdocs
|
||||
docker run --rm -v ${PWD}:/docs ingress-nginx/mkdocs build
|
||||
|
||||
.PHONY: misspell
|
||||
misspell:
|
||||
@go get github.com/client9/misspell/cmd/misspell
|
||||
go get github.com/client9/misspell/cmd/misspell
|
||||
misspell \
|
||||
-locale US \
|
||||
-error \
|
||||
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
|
||||
|
||||
|
|
|
@ -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
|
|
@ -14,33 +14,15 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
if ! [ -z $DEBUG ]; then
|
||||
set -x
|
||||
fi
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
declare -a mandatory
|
||||
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
|
||||
E2E_IMAGE=quay.io/kubernetes-ingress-controller/e2e:v05122019-7b3f69a3ba
|
||||
|
||||
DOCKER_OPTS=${DOCKER_OPTS:-""}
|
||||
|
||||
|
@ -51,8 +33,7 @@ PKG=${PKG:-""}
|
|||
ARCH=${ARCH:-""}
|
||||
GIT_COMMIT=${GIT_COMMIT:-""}
|
||||
TAG=${TAG:-"0.0"}
|
||||
HOME=${HOME:-/root}
|
||||
GOARCH=${GOARCH}
|
||||
GOARCH=${GOARCH:-""}
|
||||
GOBUILD_FLAGS=${GOBUILD_FLAGS:-"-v"}
|
||||
PWD=${PWD}
|
||||
BUSTED_ARGS=${BUSTED_ARGS:-""}
|
||||
|
@ -74,6 +55,7 @@ docker run \
|
|||
-v ${PWD}:/go/src/${PKG} \
|
||||
-v ${PWD}/.gocache:${HOME}/.cache/go-build \
|
||||
-v ${PWD}/bin/${ARCH}:/go/bin/linux_${ARCH} \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
${MINIKUBE_VOLUME} \
|
||||
-w /go/src/${PKG} \
|
||||
--env-file .env \
|
||||
|
|
|
@ -119,7 +119,8 @@ def file_passes(filename, refs, regexs):
|
|||
|
||||
# if we don't match the reference at this point, fail
|
||||
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:
|
||||
print(file=verbose_out)
|
||||
for line in difflib.unified_diff(ref, data, 'reference', filename, lineterm=''):
|
||||
|
@ -138,8 +139,6 @@ skipped_dirs = [
|
|||
'.git',
|
||||
"vendor",
|
||||
"test/e2e/framework/framework.go",
|
||||
"hack/boilerplate/test",
|
||||
"test/e2e/dind-cluster-v1.11.sh"
|
||||
]
|
||||
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ set -o nounset
|
|||
set -o pipefail
|
||||
|
||||
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:
|
||||
# --output-base because this script should also be able to run inside the vendor dir of
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Copyright 2017 The Kubernetes Authors.
|
||||
# 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.
|
||||
|
@ -14,42 +14,41 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# 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 )"
|
||||
|
||||
export TAG=dev
|
||||
export ARCH=amd64
|
||||
export REGISTRY=${REGISTRY:-ingress-controller}
|
||||
export 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}
|
||||
echo "[dev-env] copying docker images to cluster..."
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue