fix: when there is a non-ip IPAddr in Eureka, delete it to avoid a failure in EDS (#1322)

This commit is contained in:
Iris
2024-10-08 14:00:16 +08:00
committed by GitHub
parent 4d0d8a7f50
commit 3ed28f2a66

View File

@@ -18,6 +18,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"net"
"net/http" "net/http"
"time" "time"
@@ -125,13 +126,25 @@ func (c *eurekaHttpClient) getApplications(path string) (*Applications, error) {
apps := map[string]*fargo.Application{} apps := map[string]*fargo.Application{}
for idx := range rj.Response.Applications { for idx := range rj.Response.Applications {
ignore := false
app := rj.Response.Applications[idx] app := rj.Response.Applications[idx]
for _, instance := range app.Instances {
if ip := net.ParseIP(instance.IPAddr); ip == nil {
log.Warnf("the Non-IP IPAddr %s is not allowed, please check your app: %s", instance.IPAddr, app.Name)
ignore = true
break
}
}
if ignore {
continue
}
apps[app.Name] = app apps[app.Name] = app
} }
for name, app := range apps { for name, app := range apps {
log.Debugf("Parsing metadata for app %v", name) log.Debugf("Parsing metadata for app %v", name)
if err := app.ParseAllMetadata(); err != nil { if err := app.ParseAllMetadata(); err != nil {
log.Errorf("Failed to parse metadata for app %v: %v", name, err)
return nil, err return nil, err
} }
} }