Skip to content
Open
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
86 changes: 86 additions & 0 deletions local-setup/scripts/check-environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,85 @@ check_kcp_plugin() {
return 0
}

check_hosts_entry() {
local hostname="$1"
local expected_ip="127.0.0.1"

# Detect OS and use appropriate resolution method
case "$(uname -s)" in
Darwin)
# macOS: Use dscacheutil
local result=$(dscacheutil -q host -a name "$hostname" 2>/dev/null | grep "ip_address:" | grep -v "ipv6" | awk '{print $2}' | head -1)
;;
Linux)
# Linux: Check if getent is available (most distros)
if command -v getent &> /dev/null; then
local result=$(getent hosts "$hostname" 2>/dev/null | awk '{print $1}' | head -1)
else
# Fallback: Direct /etc/hosts parsing
local result=$(grep -E "^[^#]*\s+$hostname(\s|$)" /etc/hosts 2>/dev/null | awk '{print $1}' | head -1)
fi
;;
*)
# Fallback for unknown systems
local result=$(grep -E "^[^#]*\s+$hostname(\s|$)" /etc/hosts 2>/dev/null | awk '{print $1}' | head -1)
;;
esac

# Check if we got the expected IP
if [ "$result" = "$expected_ip" ]; then
return 0
else
return 1
fi
}

check_hosts_entries() {
local check_failed=0
local missing_hosts=()

# Required hostnames for local setup
local required_hosts=("portal.dev.local" "kcp.api.portal.dev.local")

# Check each required hostname
for hostname in "${required_hosts[@]}"; do
if ! check_hosts_entry "$hostname"; then
missing_hosts+=("$hostname")
check_failed=1
fi
done

if [ $check_failed -eq 1 ]; then
echo -e "${RED}❌ Error: Required DNS entries are not configured${COL_RES}"
echo -e "${COL}🌐 The following hostnames must resolve to 127.0.0.1:${COL_RES}"
for host in "${missing_hosts[@]}"; do
echo -e "${COL} - $host${COL_RES}"
done
echo ""
echo -e "${COL}📝 Add the following line to your /etc/hosts file:${COL_RES}"
echo -e "${COL} 127.0.0.1 portal.dev.local kcp.api.portal.dev.local${COL_RES}"
echo ""

# WSL-specific guidance
if grep -qi microsoft /proc/version 2>/dev/null; then
echo -e "${COL}💡 WSL Note: You may also need to add this entry to the Windows hosts file:${COL_RES}"
echo -e "${COL} C:\\Windows\\System32\\drivers\\etc\\hosts${COL_RES}"
echo -e "${COL} (This requires Administrator privileges on Windows)${COL_RES}"
echo ""
fi

echo -e "${COL}⚠️ Without these entries:${COL_RES}"
echo -e "${COL} - The setup script will fail when accessing KCP API${COL_RES}"
echo -e "${COL} - You won't be able to access the portal at https://portal.dev.local:8443${COL_RES}"
echo ""

return 1
fi

echo -e "${COL}[$(date '+%H:%M:%S')] ✅ Required DNS entries are configured${COL_RES}"
return 0
}

# Run all environment checks
run_environment_checks() {
echo -e "${COL}🔍 Checking environment dependencies...${COL_RES}"
Expand Down Expand Up @@ -181,6 +260,11 @@ run_environment_checks() {
echo -e "${COL}[$(date '+%H:%M:%S')] ✅ Architecture: $ARCH${COL_RES}"
fi

# Check hosts entries (always run - KCP is always deployed)
if ! check_hosts_entries; then
checks_failed=$((checks_failed + 1))
fi

# Check KCP plugin if example-data mode is enabled
if [ "$EXAMPLE_DATA" = true ]; then
if ! check_kcp_plugin; then
Expand All @@ -206,4 +290,6 @@ export -f check_container_runtime_dependency
export -f setup_mkcert_command
export -f check_architecture
export -f check_kcp_plugin
export -f check_hosts_entry
export -f check_hosts_entries
export -f run_environment_checks
6 changes: 2 additions & 4 deletions local-setup/scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,10 @@ if [ "$EXAMPLE_DATA" = true ]; then

fi

echo -e "${COL}Please create an entry in your /etc/hosts with the following line: \"127.0.0.1 default.portal.dev.local portal.dev.local kcp.api.portal.dev.local\" ${COL_RES}"
show_wsl_hosts_guidance

echo -e "${YELLOW}⚠️ WARNING: You need to add a hosts entry for every organization that is onboarded!${COL_RES}"
echo -e "${YELLOW}⚠️ REMINDER: You need to add a hosts entry for every organization that is onboarded!${COL_RES}"
echo -e "${YELLOW} Each organization will require its own subdomain entry in /etc/hosts${COL_RES}"
echo -e "${YELLOW} Example: 127.0.0.1 <organization-name>.portal.dev.local${COL_RES}"
show_wsl_hosts_guidance

echo -e "${COL}Once kcp is up and running, run '\033[0;32mexport KUBECONFIG=$(pwd)/.secret/kcp/admin.kubeconfig\033[0m' to gain access to the root workspace.${COL_RES}"

Expand Down
Loading