diff --git a/_run/common-kind-vars.mk b/_run/common-kind-vars.mk new file mode 100644 index 00000000..8db49482 --- /dev/null +++ b/_run/common-kind-vars.mk @@ -0,0 +1,30 @@ +# KIND_NAME NOTE: 'kind' string literal is default for the GH actions +# KinD, it's fine to use other names locally, however in GH container name +# is configured by engineerd/setup-kind. `kind-control-plane` is the docker +# image's name in GH Actions. +KIND_NAME ?= $(shell basename $$PWD) + +export KIND_NAME + +ifeq (, $(KINDEST_VERSION)) +$(error "KINDEST_VERSION is not set") +endif + +KIND_HTTP_PORT = $(shell docker inspect \ + --type container "$(KIND_NAME)-control-plane" \ + --format '{{index .NetworkSettings.Ports "80/tcp" 0 "HostPort"}}') + +KIND_HTTP_IP = $(shell docker inspect \ + --type container "$(KIND_NAME)-control-plane" \ + --format '{{index .NetworkSettings.Ports "80/tcp" 0 "HostIp"}}') + +KIND_K8S_IP = $(shell docker inspect \ + --type container "$(KIND_NAME)-control-plane" \ + --format '{{index .NetworkSettings.Ports "6443/tcp" 0 "HostIp"}}') + +# KIND_PORT_BINDINGS deliberately redirects stderr to /dev/null +# in order to suppress message Error: No such object: kube-control-plane +# during cluster setup +# it is a bit doggy way but seems to do the job +KIND_PORT_BINDINGS = $(shell docker inspect "$(KIND_NAME)-control-plane" \ + --format '{{index .NetworkSettings.Ports "80/tcp" 0 "HostPort"}}' 2> /dev/null) diff --git a/_run/common-kind.mk b/_run/common-kind.mk index ff3adc8f..9dcfd9d6 100644 --- a/_run/common-kind.mk +++ b/_run/common-kind.mk @@ -2,13 +2,7 @@ # KinD, it's fine to use other names locally, however in GH container name # is configured by engineerd/setup-kind. `kind-control-plane` is the docker # image's name in GH Actions. -KIND_NAME ?= $(shell basename $$PWD) - -export KIND_NAME - -ifeq (, $(KINDEST_VERSION)) -$(error "KINDEST_VERSION is not set") -endif +include $(AP_ROOT)/_run/common-kind-vars.mk KIND_IMG ?= kindest/node:$(KINDEST_VERSION) K8S_CONTEXT ?= $(shell kubectl config current-context) @@ -16,25 +10,6 @@ SETUP_KIND := $(AP_ROOT)/script/setup-kind.sh KIND_CONFIG ?= default KIND_CONFIG_FILE := $(shell "$(SETUP_KIND)" config-file $$PWD $(KIND_CONFIG)) -KIND_HTTP_PORT = $(shell docker inspect \ - --type container "$(KIND_NAME)-control-plane" \ - --format '{{index .NetworkSettings.Ports "80/tcp" 0 "HostPort"}}') - -KIND_HTTP_IP = $(shell docker inspect \ - --type container "$(KIND_NAME)-control-plane" \ - --format '{{index .NetworkSettings.Ports "80/tcp" 0 "HostIp"}}') - -KIND_K8S_IP = $(shell docker inspect \ - --type container "$(KIND_NAME)-control-plane" \ - --format '{{index .NetworkSettings.Ports "6443/tcp" 0 "HostIp"}}') - -# KIND_PORT_BINDINGS deliberately redirects stderr to /dev/null -# in order to suppress message Error: No such object: kube-control-plane -# during cluster setup -# it is a bit doggy way but seems to do the job -KIND_PORT_BINDINGS = $(shell docker inspect "$(KIND_NAME)-control-plane" \ - --format '{{index .NetworkSettings.Ports "80/tcp" 0 "HostPort"}}' 2> /dev/null) - .PHONY: app-http-port app-http-port: @echo $(KIND_HTTP_PORT) diff --git a/make/test-integration.mk b/make/test-integration.mk index 643ec4a3..442a8768 100644 --- a/make/test-integration.mk +++ b/make/test-integration.mk @@ -6,7 +6,7 @@ TEST_MODULES ?= $(shell $(GO) list ./... | grep -v '/mocks\|/kubernetes_mock\|/p KIND_NAME := kube -include _run/common-kind.mk +include _run/common-kind-vars.mk KIND_VARS ?= KUBE_INGRESS_IP="$(KIND_K8S_IP)" KUBE_INGRESS_PORT="$(KIND_HTTP_PORT)"