Handle the case of multiple IP addresses for publicDNSIP
We have noticed that sometimes on AWS platform the
ingress.hostname of LB service is resolved to multiple
IP addresses, and each time their order may change.
This PR updates PublicDNSIP to support multiple IP addresses.
@@ -19,12 +19,14 @@ limitations under the License.
package endpoint
import (
+ "bytes"
"context"
"io"
"math/rand"
"net"
"net/http"
"regexp"
+ "sort"
"strings"
"time"
@@ -213,6 +215,12 @@ func publicDNSIP(clientset kubernetes.Interface, namespace, fqdn string) (string
return "", errors.Wrapf(err, "error resolving DNS hostname %q for public IP", fqdn)
}
+ if len(ips) > 1 {
+ sort.Slice(ips, func(i, j int) bool {
+ return bytes.Compare(ips[i], ips[j]) < 0
+ })
+ }
+
return ips[0].String(), nil
}
