@@ -143,7 +143,7 @@ func (c *Checker) APIServerDirect(ctx context.Context) string {
143143 return skippedStr
144144 }
145145
146- apiurl := fmt .Sprintf ("https://%s:%s/version" , c .KubernetesServiceHost , c .KubernetesServicePort )
146+ apiurl := fmt .Sprintf ("https://%s:%s/version" , formatIPForURL ( c .KubernetesServiceHost ) , c .KubernetesServicePort )
147147
148148 return c .doRequest (ctx , apiurl , false )
149149}
@@ -154,7 +154,7 @@ func (c *Checker) APIServerDNS(ctx context.Context) string {
154154 return skippedStr
155155 }
156156
157- apiurl := fmt .Sprintf ("https://%s:%s/version" , c .KubernetesServiceDNS , c .KubernetesServicePort )
157+ apiurl := fmt .Sprintf ("https://%s:%s/version" , formatIPForURL ( c .KubernetesServiceDNS ) , c .KubernetesServicePort )
158158
159159 return c .doRequest (ctx , apiurl , false )
160160}
@@ -188,10 +188,21 @@ func (c *Checker) measure(ctx context.Context, wg *sync.WaitGroup, res *sync.Map
188188 res .Store (requestType , check (ctx ))
189189}
190190
191+ // formatIPForURL formats an IP address for use in a URL
192+ // If the IP is an IPv6 address, it encloses it in square brackets [...]
193+ func formatIPForURL (ip string ) string {
194+ if parsedIP := net .ParseIP (ip ); parsedIP != nil && parsedIP .To4 () == nil {
195+ return "[" + ip + "]"
196+ }
197+ return ip
198+ }
199+
191200func podIPtoURL (podIP string , useTLS bool ) string {
201+ formattedIP := formatIPForURL (podIP )
202+
192203 if useTLS {
193- return "https://" + podIP + ":8443/alwayshappy"
204+ return "https://" + formattedIP + ":8443/alwayshappy"
194205 }
195206
196- return "http://" + podIP + ":8080/alwayshappy"
207+ return "http://" + formattedIP + ":8080/alwayshappy"
197208}
0 commit comments