Skip to content

Commit 6399866

Browse files
committed
Merge branch 'fix/local-collector-env-override' into dockerify
2 parents ced51fd + df18216 commit 6399866

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

collector_test.sh

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,38 @@ for host in "${hosts[@]}"; do
5252
fi
5353
done
5454

55-
# Test container status
55+
# Test container status - prioritize existing namespace containers
5656
container_name="snapshotter-lite-local-collector-${FULL_NAMESPACE}"
5757
if ! docker ps | grep -q "$container_name"; then
5858
echo "❌ Collector container not found: $container_name"
59+
test_namespace=false
5960
else
60-
echo "✅ Collector container running: $container_name"
61+
echo "✅ Collector container already running for namespace ${FULL_NAMESPACE}: $container_name"
6162
test_namespace=true
63+
64+
# If namespace container exists, use it regardless of port configuration
65+
if [ "$test_ping" = false ]; then
66+
echo "ℹ️ Existing collector container found for namespace ${FULL_NAMESPACE} but not reachable on configured port ${LOCAL_COLLECTOR_PORT}"
67+
echo "ℹ️ Detecting actual port used by running collector $container_name..."
68+
69+
# Get all port mappings from the running container to find the actual port
70+
actual_port=$(docker port "$container_name" 2>/dev/null | grep '/tcp' | head -1 | cut -d':' -f2)
71+
72+
if [ -n "$actual_port" ] && [ "$actual_port" != "$LOCAL_COLLECTOR_PORT" ]; then
73+
echo "ℹ️ Collector $container_name is running on port $actual_port, updating env file"
74+
sed -i".backup" "s/^LOCAL_COLLECTOR_PORT=.*/LOCAL_COLLECTOR_PORT=${actual_port}/" "${ENV_FILE}"
75+
export LOCAL_COLLECTOR_PORT="$actual_port"
76+
elif [ -z "$actual_port" ]; then
77+
echo "❌ FATAL: Could not detect port for existing collector container ${container_name}"
78+
echo "❌ Cannot proceed: snapshotter won't know which port to connect to, and spawning a new collector will cause container name conflicts"
79+
echo "❌ Please manually stop the existing collector or fix its port configuration"
80+
exit 1
81+
else
82+
echo "ℹ️ Collector $container_name confirmed running on configured port ${LOCAL_COLLECTOR_PORT}"
83+
fi
84+
fi
85+
echo "✅ Using existing collector container for namespace ${FULL_NAMESPACE} on port ${LOCAL_COLLECTOR_PORT}"
86+
exit 100
6287
fi
6388

6489
# Final status check

0 commit comments

Comments
 (0)