Skip to content

Commit

Permalink
kind test make target to use cluster name (#4706)
Browse files Browse the repository at this point in the history
  • Loading branch information
pdabelf5 authored Nov 28, 2023
1 parent 8da5cf3 commit f63c8f7
Showing 1 changed file with 28 additions and 26 deletions.
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

0 comments on commit f63c8f7

Please sign in to comment.