From 0134680d5c2ea2c10d02c8bb5a016e4816e0925f Mon Sep 17 00:00:00 2001 From: Sean McGinnis Date: Mon, 24 Jan 2022 13:58:36 -0600 Subject: [PATCH] Local registry: only attach network if missing The example script for creating a kind cluster with a local registry will connect the container to the "kind" network. The first time the local registry is created, this is fine and is what is needed. On subsequent runs to create new clusters, if the local registry container has already been set up, the command to attach to the "kind" network will emit an error message to the create output that can be confusing. This updates the example script to do a basic check of the registry containers network configuration. If the kind network appears to be already connected, then the script will not attempt to connect it again. Signed-off-by: Sean McGinnis --- site/static/examples/kind-with-registry.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/site/static/examples/kind-with-registry.sh b/site/static/examples/kind-with-registry.sh index b6a8e71a7b..280922b0d1 100755 --- a/site/static/examples/kind-with-registry.sh +++ b/site/static/examples/kind-with-registry.sh @@ -23,7 +23,11 @@ EOF # connect the registry to the cluster network # (the network may already be connected) -docker network connect "kind" "${reg_name}" || true +networks=$(docker inspect --format='{{.NetworkSettings.Networks}}' "$reg_name") +kindnetwork=$(echo "${networks}" | grep 'kind:') +if [ "${networks}" != "${kindnetwork}" ]; then + docker network connect "kind" "${reg_name}" || true +fi # Document the local registry # https://github.com/kubernetes/enhancements/tree/master/keps/sig-cluster-lifecycle/generic/1755-communicating-a-local-registry