Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions tools/hack/manage-mac-net-connect.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash
set -euo pipefail

MODE="${1:-setup}" # setup | cleanup
DOCKER_MAC_NET_CONNECT=${DOCKER_MAC_NET_CONNECT:-}
HOMEBREW_GOPROXY=${HOMEBREW_GOPROXY:-}

is_macos() {
[[ "$(uname -s)" == "Darwin" ]]
}

is_installed() {
[[ "$(brew list --formula | grep -Fx "docker-mac-net-connect")" == "docker-mac-net-connect" ]]
}

is_running() {
brew services info docker-mac-net-connect --json 2>/dev/null | \
jq -e '.[] | .user != null' >/dev/null
}
Comment on lines +16 to +19
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

brew services info docker-mac-net-connect --json provides following output while my testing.

[
  {
    "name": "docker-mac-net-connect",
    "service_name": "homebrew.mxcl.docker-mac-net-connect",
    "running": false,
    "loaded": false,
    "schedulable": false,
    "pid": null,
    "exit_code": null,
    "user": "root",
    "status": "none",
    "file": "/Users/sudiptobaral/Library/LaunchAgents/homebrew.mxcl.docker-mac-net-connect.plist",
    "registered": true,
    "loaded_file": null,
    "command": "/opt/homebrew/opt/docker-mac-net-connect/bin/docker-mac-net-connect",
    "working_dir": null,
    "root_dir": null,
    "log_path": "/opt/homebrew/var/log/docker-mac-net-connect/std_out.log",
    "error_log_path": "/opt/homebrew/var/log/docker-mac-net-connect/std_error.log",
    "interval": null,
    "cron": null
  }
]

During testing, I noticed that "running": false was returned even when docker-mac-net-connect was clearly running. The only reliable indicator I found was the user field:

  • If the service is stopped, the user field is null.
  • If the service is running, the user field is always populated (e.g., "root").


setup() {
if ! is_macos || [[ "$DOCKER_MAC_NET_CONNECT" == "false" ]]; then
return
fi

if is_installed && is_running; then
echo "Docker Mac Net Connect is already installed and running."
return
fi

echo "Docker Mac Net Connect is recommended on macOS to ensure Docker networking works properly."
read -rp "Install and start Docker Mac Net Connect? [y/N]: " input
case "$(echo "$input" | tr '[:upper:]' '[:lower:]')" in
y|yes) ;;
*) return ;;
esac

if ! is_installed; then
[ -n "$HOMEBREW_GOPROXY" ] && export HOMEBREW_GOPROXY="$HOMEBREW_GOPROXY"
brew install chipmk/tap/docker-mac-net-connect
fi

if ! is_running; then
sudo brew services start chipmk/tap/docker-mac-net-connect
sleep 5
fi
}

case "$MODE" in
setup) setup ;;
cleanup) cleanup ;;
*) echo "Usage: $0 [setup]"; exit 1 ;;
esac
10 changes: 9 additions & 1 deletion tools/make/kube.mk
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ E2E_TIMEOUT ?= 20m
E2E_REDIRECT ?=
E2E_TEST_ARGS ?= -v -tags e2e -timeout $(E2E_TIMEOUT)

DOCKER_MAC_NET_CONNECT ?= true
HOMEBREW_GOPROXY ?=

KUBE_DEPLOY_PROFILE ?= default
KUBE_DEPLOY_HELM_VALUES_FILE = $(ROOT_DIR)/test/config/helm/$(KUBE_DEPLOY_PROFILE).yaml
KUBE_DEPLOY_EG_CONFIG_FILE = $(ROOT_DIR)/test/config/envoy-gateaway-config/$(KUBE_DEPLOY_PROFILE).yaml
Expand Down Expand Up @@ -190,7 +193,7 @@ resilience: create-cluster kube-install-image kube-install-examples-image kube-d
.PHONY: e2e
e2e: create-cluster kube-install-image kube-deploy \
install-ratelimit install-eg-addons kube-install-examples-image \
e2e-prepare run-e2e delete-cluster
e2e-prepare setup-mac-net-connect run-e2e delete-cluster

.PHONY: install-ratelimit
install-ratelimit:
Expand All @@ -215,6 +218,11 @@ e2e-prepare: prepare-ip-family ## Prepare the environment for running e2e tests
kubectl apply -f $(KUBE_DEPLOY_EG_CONFIG_FILE)
kubectl apply -f test/config/gatewayclass.yaml

.PHONY: setup-mac-net-connect
setup-mac-net-connect:
@$(LOG_TARGET)
DOCKER_MAC_NET_CONNECT=$(DOCKER_MAC_NET_CONNECT) HOMEBREW_GOPROXY=$(HOMEBREW_GOPROXY) tools/hack/manage-mac-net-connect.sh setup

.PHONY: run-e2e
run-e2e: ## Run e2e tests
@$(LOG_TARGET)
Expand Down