Skip to content

Commit

Permalink
Merge pull request #7577 from Codesmith1024/main
Browse files Browse the repository at this point in the history
Fix : Waiting for K8s API under WSL2 Mirrored-Mode Networking
  • Loading branch information
jandubois authored Oct 4, 2024
2 parents 23c6ea4 + ef32112 commit 8b269c1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,7 @@ wslconfig
WSLENV
WSLg
wslify
wslinfo
WSLINSTALLED
WSLIs
WSLKERNELOUTDATED
Expand Down
12 changes: 12 additions & 0 deletions pkg/rancher-desktop/backend/wsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,18 @@ export default class WSLBackend extends events.EventEmitter implements VMBackend
/** Get the IPv4 address of the VM, assuming it's already up. */
get ipAddress(): Promise<string | undefined> {
return (async() => {
// When using mirrored-mode networking, 127.0.0.1 works just fine
// ...also, there may not even be an `eth0` to find the IP of!
try {
const networkModeString = await this.captureCommand('wslinfo', '-n', '--networking-mode');

if (networkModeString === 'mirrored') {
return '127.0.0.1';
}
} catch {
// wslinfo is missing (wsl < 2.0.4) - fall back to old behavior
}

// We need to locate the _local_ route (netmask) for eth0, and then
// look it up in /proc/net/fib_trie to find the local address.
const routesString = await this.captureCommand('cat', '/proc/net/route');
Expand Down

0 comments on commit 8b269c1

Please sign in to comment.