Skip to content
Merged
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
7 changes: 4 additions & 3 deletions pkg/healthchecker/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package types

import (
"fmt"
"net"
"os"
"sort"
"strconv"
Expand All @@ -44,7 +45,7 @@ const (
kubeletPortKey = "KUBELET_PORT"
kubeProxyPortKey = "KUBEPROXY_PORT"

defaultHostAddress = "127.0.0.1"
defaultHostAddress = "localhost"
defaultKubeletPort = "10248"
defaultKubeproxyPort = "10256"
)
Expand Down Expand Up @@ -78,8 +79,8 @@ func setKubeEndpoints() {
kubeProxyPort = o
}

kubeletHealthCheckEndpoint = fmt.Sprintf("http://%s:%s/healthz", hostAddress, kubeletPort)
kubeProxyHealthCheckEndpoint = fmt.Sprintf("http://%s:%s/healthz", hostAddress, kubeProxyPort)
kubeletHealthCheckEndpoint = fmt.Sprintf("http://%s/healthz", net.JoinHostPort(hostAddress, kubeletPort))
kubeProxyHealthCheckEndpoint = fmt.Sprintf("http://%s/healthz", net.JoinHostPort(hostAddress, kubeProxyPort))

}

Expand Down
35 changes: 26 additions & 9 deletions pkg/healthchecker/types/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,31 +109,48 @@ func TestKubeEndpointConfiguration(t *testing.T) {
{
name: "no overrides supplied",
envConfig: map[string]string{},
expectedKubeletEndpoint: "http://127.0.0.1:10248/healthz",
expectedKubeProxyEndpoint: "http://127.0.0.1:10256/healthz",
}, {
expectedKubeletEndpoint: "http://localhost:10248/healthz",
expectedKubeProxyEndpoint: "http://localhost:10256/healthz",
},
{
name: "HOST_ADDRESS override supplied",
envConfig: map[string]string{
"HOST_ADDRESS": "samplehost.testdomain.com",
},
expectedKubeletEndpoint: "http://samplehost.testdomain.com:10248/healthz",
expectedKubeProxyEndpoint: "http://samplehost.testdomain.com:10256/healthz",
},
{
name: "HOST_ADDRESS override supplied with IPv4",
envConfig: map[string]string{
"HOST_ADDRESS": "10.0.5.4",
},
expectedKubeletEndpoint: "http://10.0.5.4:10248/healthz",
expectedKubeProxyEndpoint: "http://10.0.5.4:10256/healthz",
},
{
name: "HOST_ADDRESS override supplied with IPv6",
envConfig: map[string]string{
"HOST_ADDRESS": "80:f4:16::1",
},
expectedKubeletEndpoint: "http://[80:f4:16::1]:10248/healthz",
expectedKubeProxyEndpoint: "http://[80:f4:16::1]:10256/healthz",
},
{
name: "KUBELET_PORT override supplied",
envConfig: map[string]string{
"KUBELET_PORT": "12345",
},
expectedKubeletEndpoint: "http://127.0.0.1:12345/healthz",
expectedKubeProxyEndpoint: "http://127.0.0.1:10256/healthz",
expectedKubeletEndpoint: "http://localhost:12345/healthz",
expectedKubeProxyEndpoint: "http://localhost:10256/healthz",
},
{
name: "KUBEPROXY_PORT override supplied",
envConfig: map[string]string{
"KUBEPROXY_PORT": "12345",
},
expectedKubeletEndpoint: "http://127.0.0.1:10248/healthz",
expectedKubeProxyEndpoint: "http://127.0.0.1:12345/healthz",
expectedKubeletEndpoint: "http://localhost:10248/healthz",
expectedKubeProxyEndpoint: "http://localhost:12345/healthz",
},
{
name: "HOST_ADDRESS and KUBELET_PORT override supplied",
Expand Down Expand Up @@ -174,8 +191,8 @@ func TestKubeEndpointConfiguration(t *testing.T) {
kubeProxyHCEndpoint := KubeProxyHealthCheckEndpoint()
kubeletHCEndpoint := KubeletHealthCheckEndpoint()

assert.Equal(t, kubeProxyHCEndpoint, test.expectedKubeProxyEndpoint)
assert.Equal(t, kubeletHCEndpoint, test.expectedKubeletEndpoint)
assert.Equal(t, test.expectedKubeProxyEndpoint, kubeProxyHCEndpoint)
assert.Equal(t, test.expectedKubeletEndpoint, kubeletHCEndpoint)
})
}
}