Skip to content

Commit

Permalink
ci(k8s): don't ignore errors on docker network create (#11945)
Browse files Browse the repository at this point in the history
We weren't exiting with an error if `docker network create` failed.
Avoid repeating the network handling logic by using a Makefile variable.

Signed-off-by: Mike Beaumont <[email protected]>
  • Loading branch information
michaelbeaumont authored Oct 31, 2024
1 parent 0f742bd commit f070582
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions mk/k3d.mk
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,23 @@ ifdef K3D_HELM_DEPLOY_ADDITIONAL_OPTS
K3D_HELM_DEPLOY_OPTS += $(K3D_HELM_DEPLOY_ADDITIONAL_OPTS)
endif

define maybe_with_flock
if which flock >/dev/null 2>&1; then \
SHELL=bash flock -x $(BUILD_DIR)/k3d_network.lock -c $(1); \
else \
bash -c $(1); \
fi
endef

.PHONY: k3d/network/create
k3d/network/create:
@touch $(BUILD_DIR)/k3d_network.lock && \
if [ `which flock` ]; then flock -x $(BUILD_DIR)/k3d_network.lock -c 'docker network create -d=bridge $(KIND_NETWORK_OPTS) kind || true'; \
else docker network create -d=bridge $(KIND_NETWORK_OPTS) kind || true; fi && \
rm -f $(BUILD_DIR)/k3d_network.lock
$(call maybe_with_flock,"if ! docker network inspect kind >/dev/null 2>&1; then \
docker network create -d=bridge $(KIND_NETWORK_OPTS) kind >/dev/null; \
fi; \
echo 'Using docker network: '; \
docker network inspect kind --format='{{ .Id }}'")
@rm -f $(BUILD_DIR)/k3d_network.lock

DOCKERHUB_PULL_CREDENTIAL ?=
.PHONY: k3d/setup-docker-credentials
Expand Down

0 comments on commit f070582

Please sign in to comment.