From f0d831c107e43a52b36e70d3ec9cc20921a1ea9a Mon Sep 17 00:00:00 2001 From: Paul Abel <128620221+pdabelf5@users.noreply.github.com> Date: Mon, 27 Nov 2023 14:02:13 +0000 Subject: [PATCH] update kind make targets for local & CI use (#4704) --- .github/actions/smoke-tests/action.yaml | 8 +-- .gitignore | 3 ++ Makefile | 2 +- tests/Makefile | 66 ++++++++++++++----------- 4 files changed, 46 insertions(+), 33 deletions(-) diff --git a/.github/actions/smoke-tests/action.yaml b/.github/actions/smoke-tests/action.yaml index aa29e4822d..5497ef8788 100644 --- a/.github/actions/smoke-tests/action.yaml +++ b/.github/actions/smoke-tests/action.yaml @@ -84,8 +84,8 @@ runs: - name: Deploy Kubernetes id: k8s run: | - kind create cluster --name ${{ github.run_id }} --image=kindest/node:v${{ inputs.k8s-version }} --config ${{ github.workspace }}/tests/ci-files/ci-kind-config.yaml --kubeconfig kube-${{ github.run_id }} --wait ${{ inputs.k8s-timeout }} - kind load docker-image docker.io/nginx/${{ steps.ingress-type.outputs.name }}:${{ steps.ingress-type.outputs.tag }} --name ${{ github.run_id }} + make -f tests/Makefile create-kind-cluster K8S_CLUSTER_NAME=${{ github.run_id }} K8S_CLUSTER_VERSION=${{ inputs.k8s-version }} K8S_TIMEOUT=${{ inputs.k8s-timeout }} + make -f tests/Makefile image-load PREFIX=nginx/${{ steps.ingress-type.outputs.name }} TAG=${{ steps.ingress-type.outputs.tag }} K8S_CLUSTER_NAME=${{ github.run_id }} marker="${{ inputs.marker }}" sanitized_marker="${marker// /_}" name="${sanitized_marker:-${{ inputs.k8s-version }}}" @@ -95,7 +95,7 @@ runs: - name: Setup Kubeconfig run: | - sed -i 's|server:.*|server: https://${{ steps.k8s.outputs.cluster_ip }}:6443|' kube-${{ github.run_id }} + sed -i 's|server:.*|server: https://${{ steps.k8s.outputs.cluster_ip }}:6443|' ~/.kube/kind/config shell: bash - name: Run Smoke Tests @@ -105,7 +105,7 @@ runs: --name test-runner-${{ github.run_id }} \ --network=kind \ -v ${{ github.workspace }}/tests/tests-${{ steps.k8s.outputs.cluster }}.html:/workspace/tests/tests-${{ steps.k8s.outputs.cluster }}.html \ - -v ${{ github.workspace }}/kube-${{ github.run_id }}:/root/.kube/config test-runner:${{ github.sha }} \ + -v ~/.kube/kind/config:/root/.kube/config test-runner:${{ github.sha }} \ --context=kind-${{ github.run_id }} \ --image=docker.io/nginx/${{ steps.ingress-type.outputs.name }}:${{ steps.ingress-type.outputs.tag }} \ --image-pull-policy=Never \ diff --git a/.gitignore b/.gitignore index 1c9fa19f8d..711d23caac 100644 --- a/.gitignore +++ b/.gitignore @@ -67,3 +67,6 @@ coverage.out node_modules package-lock.json package.json + +# kind kube-config +kube-local diff --git a/Makefile b/Makefile index db58dd2cda..17c7598ee2 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,7 @@ staticcheck: ## Run staticcheck linter staticcheck ./... .PHONY: test -test: ## Run tests +test: ## Run GoLang tests go test -tags=aws -shuffle=on -race ./... cover: ## Generate coverage report diff --git a/tests/Makefile b/tests/Makefile index fbcc56ceff..81a8d42531 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,42 +1,42 @@ SHELL=/bin/bash +ROOT_DIR = $(shell git rev-parse --show-toplevel) CONTEXT = -BUILD_IMAGE = nginx/nginx-ingress:edge PULL_POLICY = IfNotPresent DEPLOYMENT_TYPE = deployment IC_TYPE = nginx-ingress SERVICE = nodeport NODE_IP = -TAG = latest -PREFIX = test-runner -KUBE_CONFIG_FOLDER = $${HOME}/.kube -KIND_KUBE_CONFIG_FOLDER = $${HOME}/.kube/kind +TEST_TAG = latest +TEST_PREFIX = test-runner +KUBE_CONFIG_FOLDER = ${HOME}/.kube +KIND_KUBE_CONFIG_FOLDER = $(KUBE_CONFIG_FOLDER)/kind SHOW_IC_LOGS = no PYTEST_ARGS = -DOCKERFILEPATH = Dockerfile +DOCKERFILEPATH := ${ROOT_DIR}/tests/Dockerfile IP_FAMILY=dual - - -define PRINT_HELP_PYSCRIPT -import re, sys - -for line in sys.stdin: - match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line) - if match: - target, help = match.groups() - print("%-20s %s" % (target, help)) -endef -export PRINT_HELP_PYSCRIPT - -default: help +PREFIX ?= nginx/nginx-ingress ## The name of the image. For example, nginx/nginx-ingress +TAG ?= edge ## The tag of the image. For example, edge +K8S_CLUSTER_NAME ?= "local" ## The name used when creating/using a Kind Kubernetes cluster +K8S_CLUSTER_VERSION ?= $(shell grep -m1 'FROM kindest/node' < ${DOCKERFILEPATH} | cut -d ':' -f 2 | sed -e 's/^v//') ## The version used when creating a Kind Kubernetes cluster +K8S_TIMEOUT ?= 75s ## The timeout used when creating a Kind Kubernetes cluster +BUILD_IMAGE := $(PREFIX):$(TAG) .PHONY: help ## Show this help help: ## Show available make targets - @python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST) + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "; printf "Usage:\n\n make \033[36m\033[0m [VARIABLE=value...]\n\nTargets:\n\n"}; {printf " \033[36m%-30s\033[0m %s\n", $$1, $$2}' .PHONY: build build: ## Run build - docker build -t $(PREFIX):$(TAG) -f $(DOCKERFILEPATH) .. + docker build -t $(TEST_PREFIX):$(TEST_TAG) -f $(DOCKERFILEPATH) .. + + +$(KUBE_CONFIG_FOLDER): + @mkdir -p $@ + + +$(KIND_KUBE_CONFIG_FOLDER): $(KUBE_CONFIG_FOLDER) + @mkdir -p $@ .PHONY: run-tests @@ -63,15 +63,25 @@ run-tests-in-kind: update-test-kind-config ## Run tests in Kind .PHONY: create-kind-cluster -create-kind-cluster: ## Create Kind cluster - $(eval KIND_IMAGE=$(shell grep -m1 'FROM kindest/node'