@@ -533,6 +533,16 @@ function util::get_docker_host_ip_port(){
533
533
docker inspect --format=' {{range $key, $value := index .NetworkSettings.Ports "6443/tcp"}}{{if eq $key 0}}{{$value.HostIp}}:{{$value.HostPort}}{{end}}{{end}}' " ${container_name} "
534
534
}
535
535
536
+ # util::is_wsl2 checks if the current environment is WSL2.
537
+ # Returns:
538
+ # 0 if running in WSL2, 1 otherwise.
539
+ # Usage:
540
+ # util::is_wsl2 && echo "WSL2 detected" || echo "Not WSL2"
541
+ function util::is_wsl2(){
542
+ # /proc/sys/fs/binfmt_misc/WSLInterop exists only in WSL2 environments
543
+ [[ -f /proc/sys/fs/binfmt_misc/WSLInterop ]] || \
544
+ ( [[ -f /proc/version ]] && grep -q " WSL2" /proc/version )
545
+ }
536
546
# util::check_clusters_ready checks if a cluster is ready, if not, wait until timeout
537
547
function util::check_clusters_ready() {
538
548
local kubeconfig_path=${1}
@@ -548,7 +558,13 @@ function util::check_clusters_ready() {
548
558
os_name=$( go env GOOS)
549
559
local container_ip_port
550
560
case $os_name in
551
- linux) container_ip_port=$( util::get_docker_native_ipaddress " ${context_name} -control-plane" ) " :6443"
561
+ linux)
562
+ if util::is_wsl2; then
563
+ # WSL2 uses a different method to get the container IP address
564
+ container_ip_port=$( util::get_docker_host_ip_port " ${context_name} -control-plane" )
565
+ else # normal linux environment
566
+ container_ip_port=$( util::get_docker_native_ipaddress " ${context_name} -control-plane" ) " :6443"
567
+ fi
552
568
;;
553
569
darwin) container_ip_port=$( util::get_docker_host_ip_port " ${context_name} -control-plane" )
554
570
;;
@@ -683,6 +699,16 @@ function util::add_routes() {
683
699
unset IFS
684
700
}
685
701
702
+ # util::get_wsl2_ipaddress will get ip address on wsl2, store to 'WSL2_HOST_IP_ADDRESS' if available
703
+ WSL2_HOST_IP_ADDRESS=' '
704
+ function util::get_wsl2_ipaddress() {
705
+ echo " ===================================================="
706
+ echo " = Detected that you are installing Karmada on WSL2 ="
707
+ echo " ===================================================="
708
+ WSL2_HOST_IP_ADDRESS=$( hostname -I | awk ' {print $1}' )
709
+ util::verify_ip_address " ${WSL2_HOST_IP_ADDRESS} "
710
+ }
711
+
686
712
# util::get_macos_ipaddress will get ip address on macos interactively, store to 'MAC_NIC_IPADDRESS' if available
687
713
MAC_NIC_IPADDRESS=' '
688
714
function util::get_macos_ipaddress() {
0 commit comments