Skip to content

Commit

Permalink
fix(build): move kind variables into dedicated make file (#271)
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian authored Feb 14, 2025
1 parent bd40c0a commit b5a075e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 27 deletions.
30 changes: 30 additions & 0 deletions _run/common-kind-vars.mk
Original file line number Diff line number Diff line change
@@ -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)
27 changes: 1 addition & 26 deletions _run/common-kind.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,14 @@
# 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)
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)
Expand Down
2 changes: 1 addition & 1 deletion make/test-integration.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)"

Expand Down

0 comments on commit b5a075e

Please sign in to comment.