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
4 changes: 4 additions & 0 deletions clients/config_client/config_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ func NewConfigClientWithRamCredentialProvider(nc nacos_client.INacosClient, prov
if err != nil {
return nil, err
}
// Set custom client IP if configured
if clientConfig.ClientIP != "" {
util.SetCustomClientIP(clientConfig.ClientIP)
}
serverConfig, err := nc.GetServerConfig()
if err != nil {
return nil, err
Expand Down
8 changes: 8 additions & 0 deletions common/constant/client_config_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,11 @@ func WithAppConnLabels(appConnLabels map[string]string) ClientOption {
config.AppConnLabels = appConnLabels
}
}

// WithClientIP sets custom client IP for gRPC communication.
// This is useful in containerized environments where the auto-detected IP might be incorrect.
func WithClientIP(clientIP string) ClientOption {
return func(config *ClientConfig) {
config.ClientIP = clientIP
}
}
1 change: 1 addition & 0 deletions common/constant/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type ClientConfig struct {
EndpointQueryParams string // the address server endpoint query params
ClusterName string // the address server clusterName
AppConnLabels map[string]string // app conn labels
ClientIP string // the custom client ip, if not set, will use local ip auto detected
}

type ClientLogSamplingConfig struct {
Expand Down
14 changes: 14 additions & 0 deletions util/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,22 @@ func GetConfigCacheKey(dataId string, group string, tenant string) string {
}

var localIP = ""
var customClientIP = ""

// SetCustomClientIP sets a custom client IP to be used in gRPC communication.
// This will override the auto-detected local IP.
// Useful for containerized environments where the auto-detected IP might be incorrect.
func SetCustomClientIP(ip string) {
customClientIP = ip
if len(customClientIP) > 0 {
logger.Infof("Custom Client IP set to: %s", customClientIP)
}
}

func LocalIP() string {
if customClientIP != "" {
return customClientIP
}
if localIP == "" {
netInterfaces, err := net.Interfaces()
if err != nil {
Expand Down