Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update kind make targets for local & CI use #4704

Merged
merged 8 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/actions/smoke-tests/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}}"
Expand All @@ -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
Expand All @@ -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 \
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,6 @@ coverage.out
node_modules
package-lock.json
package.json

# kind kube-config
kube-local
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
66 changes: 38 additions & 28 deletions tests/Makefile
Original file line number Diff line number Diff line change
@@ -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<target>\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
Expand All @@ -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' <Dockerfile | awk -F'[ ]' '{print $$2}'))
kind create cluster --image $(KIND_IMAGE) --config=<(sed 's/dual/${IP_FAMILY}/' ./ci-files/ci-kind-config.yaml)
kind export kubeconfig --kubeconfig $(KIND_KUBE_CONFIG_FOLDER)/config
create-kind-cluster: $(KIND_KUBE_CONFIG_FOLDER) ## Create a Kind K8S cluster
@kind create cluster \
--name $(K8S_CLUSTER_NAME) \
--image=kindest/node:v$(K8S_CLUSTER_VERSION) \
--config=<(sed 's/dual/${IP_FAMILY}/' $(ROOT_DIR)/tests/ci-files/ci-kind-config.yaml) \
--kubeconfig $(KIND_KUBE_CONFIG_FOLDER)/config \
--wait $(K8S_TIMEOUT)


.PHONY: delete-kind-cluster
delete-kind-cluster: ## Delete Kind cluster
kind delete cluster
delete-kind-cluster: ## Delete a Kind K8S cluster
@kind delete cluster --name $(K8S_CLUSTER_NAME)
@rm -f $(KIND_KUBE_CONFIG_FOLDER)/config


.PHONY: image-load
image-load: ## Load the image into the Kind K8S cluster
@kind load docker-image docker.io/$(strip $(PREFIX)):$(strip $(TAG)) --name $(K8S_CLUSTER_NAME)


.PHONY: test-lint
test-lint: ## Run Python linting tools
Expand Down
Loading