Skip to content

Commit 42dd0f6

Browse files
authored
Add minikube as option for running tests (#7018)
1 parent 001bed9 commit 42dd0f6

File tree

1 file changed

+69
-25
lines changed

1 file changed

+69
-25
lines changed

tests/Makefile

Lines changed: 69 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
1-
SHELL = /bin/bash
2-
ROOT_DIR = $(shell git rev-parse --show-toplevel)
3-
CONTEXT =
4-
PULL_POLICY = IfNotPresent
5-
DEPLOYMENT_TYPE = deployment
6-
SERVICE = nodeport
7-
NODE_IP =
8-
TEST_PREFIX = test-runner
9-
KUBE_CONFIG_FOLDER = ${HOME}/.kube
10-
KIND_KUBE_CONFIG_FOLDER = $(KUBE_CONFIG_FOLDER)/kind
11-
DOCKERFILEPATH := ${ROOT_DIR}/tests/Dockerfile
12-
IP_FAMILY = dual
13-
IC_TYPE ?= nginx-ingress ## The Ingress Controller type to use, "nginx-ingress" or "nginx-plus-ingress". Defaults to "nginx-ingress"
14-
SHOW_IC_LOGS ?= no ## Should the tests show the Ingress Controller logs on failure, "yes" or "no". Defaults to "no"
15-
TEST_TAG ?= latest ## The Tag to use for the test image. e.g. commitsha
16-
REGISTRY ?= docker.io ## The registry where the image is located. For example, docker.io
17-
PREFIX ?= nginx/nginx-ingress ## The name of the image. For example, nginx/nginx-ingress
18-
TAG ?= edge ## The tag of the image. For example, edge
19-
K8S_CLUSTER_NAME ?= local ## The name used when creating/using a Kind Kubernetes cluster
20-
K8S_CLUSTER_VERSION ?= $(shell grep -m1 'FROM kindest/node' < ${DOCKERFILEPATH} | cut -d ':' -f 2 | sed -e 's/^v//' | cut -d '@' -f 1) ## The version used when creating a Kind Kubernetes cluster
21-
K8S_TIMEOUT ?= 75s ## The timeout used when creating a Kind Kubernetes cluster
22-
AD_SECRET ?=
23-
PYTEST_ARGS ?=
1+
SHELL = /bin/bash
2+
ROOT_DIR = $(shell git rev-parse --show-toplevel)
3+
CONTEXT =
4+
PULL_POLICY = IfNotPresent
5+
DEPLOYMENT_TYPE = deployment
6+
SERVICE = nodeport
7+
NODE_IP =
8+
TEST_PREFIX = test-runner
9+
KUBE_CONFIG_FOLDER = ${HOME}/.kube
10+
KIND_KUBE_CONFIG_FOLDER = $(KUBE_CONFIG_FOLDER)/kind
11+
MINIKUBE_KUBE_CONFIG_FOLDER = $(KUBE_CONFIG_FOLDER)/minikube
12+
DOCKERFILEPATH := ${ROOT_DIR}/tests/Dockerfile
13+
IP_FAMILY = dual
14+
IC_TYPE ?= nginx-ingress ## The Ingress Controller type to use, "nginx-ingress" or "nginx-plus-ingress". Defaults to "nginx-ingress"
15+
SHOW_IC_LOGS ?= no ## Should the tests show the Ingress Controller logs on failure, "yes" or "no". Defaults to "no"
16+
TEST_TAG ?= latest ## The Tag to use for the test image. e.g. commitsha
17+
REGISTRY ?= docker.io ## The registry where the image is located. For example, docker.io
18+
PREFIX ?= nginx/nginx-ingress ## The name of the image. For example, nginx/nginx-ingress
19+
TAG ?= edge ## The tag of the image. For example, edge
20+
K8S_CLUSTER_NAME ?= local ## The name used when creating/using a Kind Kubernetes cluster
21+
K8S_CLUSTER_VERSION ?= $(shell grep -m1 'FROM kindest/node' < ${DOCKERFILEPATH} | cut -d ':' -f 2 | sed -e 's/^v//' | cut -d '@' -f 1) ## The version used when creating a Kind Kubernetes cluster
22+
K8S_TIMEOUT ?= 75s ## The timeout used when creating a Kind Kubernetes cluster
23+
AD_SECRET ?=
24+
PYTEST_ARGS ?=
2425
ifeq (${REGISTRY},)
25-
BUILD_IMAGE := $(strip $(PREFIX)):$(strip $(TAG))
26+
BUILD_IMAGE := $(strip $(PREFIX)):$(strip $(TAG))
2627
else
27-
BUILD_IMAGE := $(strip $(REGISTRY))/$(strip $(PREFIX)):$(strip $(TAG))
28+
BUILD_IMAGE := $(strip $(REGISTRY))/$(strip $(PREFIX)):$(strip $(TAG))
2829
endif
2930

3031
.PHONY: help ## Show this help
@@ -45,6 +46,10 @@ $(KIND_KUBE_CONFIG_FOLDER): $(KUBE_CONFIG_FOLDER)
4546
@mkdir -p $@
4647

4748

49+
$(MINIKUBE_KUBE_CONFIG_FOLDER): $(KUBE_CONFIG_FOLDER)
50+
@mkdir -p $@
51+
52+
4853
.PHONY: run-tests
4954
run-tests: ## Run tests
5055
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)
@@ -91,6 +96,45 @@ image-load: ## Load the image into the Kind K8S cluster
9196
@kind load docker-image $(BUILD_IMAGE) --name $(K8S_CLUSTER_NAME)
9297

9398

99+
.PHONY: run-tests-in-minikube
100+
run-tests-in-minikube: ## Run tests in Minikube
101+
docker run --network=minikube --rm \
102+
-v $(MINIKUBE_KUBE_CONFIG_FOLDER):/root/.kube \
103+
-v $(ROOT_DIR)/tests:/workspace/tests \
104+
-v $$HOME/.minikube:$$HOME/.minikube \
105+
-v $(ROOT_DIR)/examples/common-secrets:/workspace/examples/common-secrets \
106+
-v $(ROOT_DIR)/deployments:/workspace/deployments \
107+
-v $(ROOT_DIR)/config:/workspace/config \
108+
-v $(ROOT_DIR)/pyproject.toml:/workspace/pyproject.toml \
109+
$(TEST_PREFIX):$(TEST_TAG) \
110+
--context=minikube \
111+
--image=$(BUILD_IMAGE) --image-pull-policy=Never \
112+
--deployment-type=$(DEPLOYMENT_TYPE) \
113+
--ic-type=$(IC_TYPE) \
114+
--service=nodeport \
115+
--node-ip=minikube \
116+
--show-ic-logs=$(SHOW_IC_LOGS) \
117+
$(PYTEST_ARGS)
118+
119+
120+
.PHONY: create-mini-cluster
121+
create-mini-cluster: $(MINIKUBE_KUBE_CONFIG_FOLDER) ## Create a Minikube K8S cluster
122+
@minikube start --kubernetes-version=v$(K8S_CLUSTER_VERSION) \
123+
&& KUBECONFIG=$(MINIKUBE_KUBE_CONFIG_FOLDER)/config minikube update-context \
124+
&& KUBECONFIG=$(MINIKUBE_KUBE_CONFIG_FOLDER)/config kubectl config set-cluster minikube --server=https://minikube:8443
125+
126+
127+
.PHONY: delete-mini-cluster
128+
delete-mini-cluster: ## Delete a Minikube K8S cluster
129+
@minikube delete
130+
@rm -f $(MINIKUBE_KUBE_CONFIG_FOLDER)/config
131+
132+
133+
.PHONY: mini-image-load
134+
mini-image-load: ## Load the image into the Minikube K8S cluster
135+
@minikube image load $(BUILD_IMAGE)
136+
137+
94138
.PHONY: test-lint
95139
test-lint: ## Run Python linting tools
96140
isort .

0 commit comments

Comments
 (0)