@@ -41,13 +41,109 @@ success() { printf "\033[0;32m%s\033[0m\n" "$*"; }
4141need_cmd () {
4242 if ! command -v " $1 " > /dev/null 2>&1 ; then
4343 err " Missing required command: $1 "
44+ case " $1 " in
45+ crc)
46+ err " Install CRC:"
47+ err " macOS: brew install crc"
48+ err " Linux: https://crc.dev/crc/getting_started/getting_started/installing/"
49+ ;;
50+ jq)
51+ err " Install jq:"
52+ err " macOS: brew install jq"
53+ err " Linux: sudo apt install jq # or yum install jq"
54+ ;;
55+ esac
4456 exit 1
4557 fi
4658}
4759
60+ check_system_resources () {
61+ log " Checking system resources..."
62+
63+ # Check OS compatibility
64+ local os_name=" $( uname -s) "
65+ case " $os_name " in
66+ Darwin|Linux)
67+ log " OS detected: $os_name ✓"
68+ ;;
69+ * )
70+ err " Unsupported OS: $os_name "
71+ err " CRC requires macOS or Linux. For Windows, use WSL2."
72+ exit 1
73+ ;;
74+ esac
75+
76+ # Check available memory (basic check)
77+ if [[ -f /proc/meminfo ]]; then
78+ local available_mem_kb
79+ available_mem_kb=$( grep MemAvailable /proc/meminfo | awk ' {print $2}' )
80+ local required_mem_kb=$(( CRC_MEMORY * 1024 ))
81+ if [[ " $available_mem_kb " -lt " $required_mem_kb " ]]; then
82+ warn " Available memory (${available_mem_kb} KB) may be insufficient for CRC (${required_mem_kb} KB)"
83+ warn " Consider reducing: CRC_MEMORY=6144 make dev-start"
84+ fi
85+ fi
86+
87+ # Check disk space in home directory
88+ local available_space_gb
89+ if command -v df > /dev/null 2>&1 ; then
90+ available_space_gb=$( df -h " $HOME " | awk ' NR==2 {print $4}' | sed ' s/G//' )
91+ if [[ " $available_space_gb " -lt " $CRC_DISK " ]] 2> /dev/null; then
92+ warn " Available disk space (~${available_space_gb} GB) may be insufficient for CRC (${CRC_DISK} GB)"
93+ warn " Consider reducing: CRC_DISK=30 make dev-start"
94+ fi
95+ fi
96+
97+ # Check virtualization (basic check for Linux)
98+ if [[ -f /proc/cpuinfo ]] && ! grep -q -E ' (vmx|svm)' /proc/cpuinfo; then
99+ warn " Virtualization may not be enabled. CRC requires VT-x/AMD-V."
100+ warn " Enable virtualization in BIOS/UEFI settings."
101+ fi
102+
103+ # Check if ports might be in use (basic check)
104+ if command -v lsof > /dev/null 2>&1 ; then
105+ for port in 6443 443 80; do
106+ if lsof -iTCP:$port -sTCP:LISTEN > /dev/null 2>&1 ; then
107+ warn " Port $port appears to be in use - may conflict with CRC"
108+ fi
109+ done
110+ fi
111+ }
112+
48113# ########################
49114# CRC Setup (from original)
50115# ########################
116+ check_crc_setup () {
117+ # Check if CRC has been set up
118+ if ! crc version > /dev/null 2>&1 ; then
119+ err " CRC not properly installed or not in PATH"
120+ exit 1
121+ fi
122+
123+ # Check if pull secret is configured
124+ local pull_secret_path=" $HOME /.crc/pull-secret.json"
125+ if [[ ! -f " $pull_secret_path " ]]; then
126+ err " Pull secret not found. You need to:"
127+ err " 1. Get your pull secret from https://console.redhat.com/openshift/create/local"
128+ err " 2. Save it to $pull_secret_path "
129+ exit 1
130+ fi
131+
132+ # Configure CRC if not already done
133+ if ! crc config get enable-cluster-monitoring > /dev/null 2>&1 ; then
134+ log " Running initial CRC setup..."
135+ crc setup
136+ fi
137+
138+ # Apply resource configuration
139+ log " Configuring CRC resources (${CRC_CPUS} CPUs, ${CRC_MEMORY} MB RAM, ${CRC_DISK} GB disk)..."
140+ crc config set cpus " $CRC_CPUS " > /dev/null
141+ crc config set memory " $CRC_MEMORY " > /dev/null
142+ crc config set disk-size " $CRC_DISK " > /dev/null
143+ crc config set pull-secret-file " $pull_secret_path " > /dev/null
144+ crc config set enable-cluster-monitoring false > /dev/null
145+ }
146+
51147ensure_crc_cluster () {
52148 local crc_status
53149 crc_status=$( crc status -o json 2> /dev/null | jq -r ' .crcStatus // "Stopped"' 2> /dev/null || echo " Stopped" )
@@ -171,10 +267,17 @@ EOF
171267log " Checking prerequisites..."
172268need_cmd crc
173269need_cmd jq
174- need_cmd oc
270+
271+ # Optional tools with warnings
272+ if ! command -v git > /dev/null 2>&1 ; then
273+ warn " Git not found - needed if you haven't cloned the repo yet"
274+ fi
275+
276+ check_system_resources
175277
176278log " Starting CRC-based local development environment..."
177279
280+ check_crc_setup
178281ensure_crc_cluster
179282configure_oc_context
180283ensure_project
0 commit comments