mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 01:43:47 +00:00
Update nat.go
This commit is contained in:
parent
341647f186
commit
0b542721e9
1 changed files with 17 additions and 1 deletions
|
|
@ -21,6 +21,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
|
@ -133,7 +134,13 @@ func Map(m Interface, c <-chan struct{}, protocol string, extport, intport int,
|
|||
// Mapping operations will not return an error but won't actually do anything.
|
||||
type ExtIP net.IP
|
||||
|
||||
func (n ExtIP) ExternalIP() (net.IP, error) { return net.IP(n), nil }
|
||||
func (n ExtIP) ExternalIP() (net.IP, error) {
|
||||
if IsKubernetesEnvironment() {
|
||||
return net.IP(n), nil
|
||||
}
|
||||
return net.IP(n), nil
|
||||
}
|
||||
|
||||
func (n ExtIP) String() string { return fmt.Sprintf("ExtIP(%v)", net.IP(n)) }
|
||||
|
||||
// These do nothing.
|
||||
|
|
@ -240,3 +247,12 @@ func (n *autodisc) wait() error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsKubernetesEnvironment detects if the process is running inside Kubernetes cluster
|
||||
// by checking for the presence of standard K8s environment variables.
|
||||
func IsKubernetesEnvironment() bool {
|
||||
if _, exists := os.LookupEnv("KUBERNETES_SERVICE_HOST"); exists {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue