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

kind test make target to use cluster name #4706

Merged
merged 2 commits into from
Nov 28, 2023
Merged
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
54 changes: 28 additions & 26 deletions tests/Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
SHELL=/bin/bash
ROOT_DIR = $(shell git rev-parse --show-toplevel)
CONTEXT =
PULL_POLICY = IfNotPresent
DEPLOYMENT_TYPE = deployment
IC_TYPE = nginx-ingress
SERVICE = nodeport
NODE_IP =
TEST_TAG = latest
TEST_PREFIX = test-runner
KUBE_CONFIG_FOLDER = ${HOME}/.kube
SHELL = /bin/bash
ROOT_DIR = $(shell git rev-parse --show-toplevel)
CONTEXT =
PULL_POLICY = IfNotPresent
DEPLOYMENT_TYPE = deployment
IC_TYPE = nginx-ingress
SERVICE = nodeport
NODE_IP =
TEST_PREFIX = test-runner
KUBE_CONFIG_FOLDER = ${HOME}/.kube
KIND_KUBE_CONFIG_FOLDER = $(KUBE_CONFIG_FOLDER)/kind
SHOW_IC_LOGS = no
PYTEST_ARGS =
DOCKERFILEPATH := ${ROOT_DIR}/tests/Dockerfile
IP_FAMILY=dual
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)
SHOW_IC_LOGS = no
PYTEST_ARGS =
DOCKERFILEPATH := ${ROOT_DIR}/tests/Dockerfile
IP_FAMILY = dual
TEST_TAG ?= latest ## The Tag to use for the test image. e.g. commitsha
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
AD_SECRET ?=
PYTEST_ARGS ?=
BUILD_IMAGE := $(strip $(PREFIX)):$(strip $(TAG))

.PHONY: help ## Show this help
help: ## Show available make targets
Expand All @@ -41,23 +43,23 @@ $(KIND_KUBE_CONFIG_FOLDER): $(KUBE_CONFIG_FOLDER)

.PHONY: run-tests
run-tests: ## Run tests
docker run --rm -v $(KUBE_CONFIG_FOLDER):/root/.kube $(PREFIX):$(TAG) --context=$(CONTEXT) --image=$(BUILD_IMAGE) --image-pull-policy=$(PULL_POLICY) --deployment-type=$(DEPLOYMENT_TYPE) --ic-type=$(IC_TYPE) --service=$(SERVICE) --node-ip=$(NODE_IP) --show-ic-logs=$(SHOW_IC_LOGS) $(PYTEST_ARGS)
docker run --rm -v $(KUBE_CONFIG_FOLDER):/root/.kube $(TEST_PREFIX):$(TEST_TAG) --context=$(CONTEXT) --image=$(BUILD_IMAGE) --image-pull-policy=$(PULL_POLICY) --deployment-type=$(DEPLOYMENT_TYPE) --ic-type=$(IC_TYPE) --service=$(SERVICE) --node-ip=$(NODE_IP) --show-ic-logs=$(SHOW_IC_LOGS) $(PYTEST_ARGS)


.PHONY: update-test-kind-config ## Update Kind config
update-test-kind-config:
sed -ir "s|server:.*|server: https://kind-control-plane:6443|" $(KIND_KUBE_CONFIG_FOLDER)/config
sed -ir "s|server:.*|server: https://$(strip $(K8S_CLUSTER_NAME))-control-plane:6443|" $(KIND_KUBE_CONFIG_FOLDER)/config


.PHONY: run-tests-in-kind
run-tests-in-kind: update-test-kind-config ## Run tests in Kind
docker run --network=kind --rm -v $(KIND_KUBE_CONFIG_FOLDER):/root/.kube $(PREFIX):$(TAG) \
--context=kind-kind \
docker run --network=kind --rm -v $(KIND_KUBE_CONFIG_FOLDER):/root/.kube $(TEST_PREFIX):$(TEST_TAG) \
--context=kind-$(strip $(K8S_CLUSTER_NAME)) \
--image=$(BUILD_IMAGE) --image-pull-policy=$(PULL_POLICY) \
--deployment-type=$(DEPLOYMENT_TYPE) \
--ic-type=$(IC_TYPE) \
--service=nodeport \
--node-ip=kind-control-plane \
--node-ip=$(strip $(K8S_CLUSTER_NAME))-control-plane \
--show-ic-logs=$(SHOW_IC_LOGS) \
$(PYTEST_ARGS)

Expand Down
Loading