Skip to content

Commit 9b473a0

Browse files
authored
Merge pull request #1061 from marqc/default_to_ipfamily_agnostic_localhost_host_address
feat!: Set default host address value to `localhost`.
2 parents 9e366f5 + a765aae commit 9b473a0

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

pkg/healthchecker/types/types.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package types
1818

1919
import (
2020
"fmt"
21+
"net"
2122
"os"
2223
"sort"
2324
"strconv"
@@ -44,7 +45,7 @@ const (
4445
kubeletPortKey = "KUBELET_PORT"
4546
kubeProxyPortKey = "KUBEPROXY_PORT"
4647

47-
defaultHostAddress = "127.0.0.1"
48+
defaultHostAddress = "localhost"
4849
defaultKubeletPort = "10248"
4950
defaultKubeproxyPort = "10256"
5051
)
@@ -78,8 +79,8 @@ func setKubeEndpoints() {
7879
kubeProxyPort = o
7980
}
8081

81-
kubeletHealthCheckEndpoint = fmt.Sprintf("http://%s:%s/healthz", hostAddress, kubeletPort)
82-
kubeProxyHealthCheckEndpoint = fmt.Sprintf("http://%s:%s/healthz", hostAddress, kubeProxyPort)
82+
kubeletHealthCheckEndpoint = fmt.Sprintf("http://%s/healthz", net.JoinHostPort(hostAddress, kubeletPort))
83+
kubeProxyHealthCheckEndpoint = fmt.Sprintf("http://%s/healthz", net.JoinHostPort(hostAddress, kubeProxyPort))
8384

8485
}
8586

pkg/healthchecker/types/types_test.go

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,31 +109,48 @@ func TestKubeEndpointConfiguration(t *testing.T) {
109109
{
110110
name: "no overrides supplied",
111111
envConfig: map[string]string{},
112-
expectedKubeletEndpoint: "http://127.0.0.1:10248/healthz",
113-
expectedKubeProxyEndpoint: "http://127.0.0.1:10256/healthz",
114-
}, {
112+
expectedKubeletEndpoint: "http://localhost:10248/healthz",
113+
expectedKubeProxyEndpoint: "http://localhost:10256/healthz",
114+
},
115+
{
115116
name: "HOST_ADDRESS override supplied",
116117
envConfig: map[string]string{
117118
"HOST_ADDRESS": "samplehost.testdomain.com",
118119
},
119120
expectedKubeletEndpoint: "http://samplehost.testdomain.com:10248/healthz",
120121
expectedKubeProxyEndpoint: "http://samplehost.testdomain.com:10256/healthz",
121122
},
123+
{
124+
name: "HOST_ADDRESS override supplied with IPv4",
125+
envConfig: map[string]string{
126+
"HOST_ADDRESS": "10.0.5.4",
127+
},
128+
expectedKubeletEndpoint: "http://10.0.5.4:10248/healthz",
129+
expectedKubeProxyEndpoint: "http://10.0.5.4:10256/healthz",
130+
},
131+
{
132+
name: "HOST_ADDRESS override supplied with IPv6",
133+
envConfig: map[string]string{
134+
"HOST_ADDRESS": "80:f4:16::1",
135+
},
136+
expectedKubeletEndpoint: "http://[80:f4:16::1]:10248/healthz",
137+
expectedKubeProxyEndpoint: "http://[80:f4:16::1]:10256/healthz",
138+
},
122139
{
123140
name: "KUBELET_PORT override supplied",
124141
envConfig: map[string]string{
125142
"KUBELET_PORT": "12345",
126143
},
127-
expectedKubeletEndpoint: "http://127.0.0.1:12345/healthz",
128-
expectedKubeProxyEndpoint: "http://127.0.0.1:10256/healthz",
144+
expectedKubeletEndpoint: "http://localhost:12345/healthz",
145+
expectedKubeProxyEndpoint: "http://localhost:10256/healthz",
129146
},
130147
{
131148
name: "KUBEPROXY_PORT override supplied",
132149
envConfig: map[string]string{
133150
"KUBEPROXY_PORT": "12345",
134151
},
135-
expectedKubeletEndpoint: "http://127.0.0.1:10248/healthz",
136-
expectedKubeProxyEndpoint: "http://127.0.0.1:12345/healthz",
152+
expectedKubeletEndpoint: "http://localhost:10248/healthz",
153+
expectedKubeProxyEndpoint: "http://localhost:12345/healthz",
137154
},
138155
{
139156
name: "HOST_ADDRESS and KUBELET_PORT override supplied",
@@ -174,8 +191,8 @@ func TestKubeEndpointConfiguration(t *testing.T) {
174191
kubeProxyHCEndpoint := KubeProxyHealthCheckEndpoint()
175192
kubeletHCEndpoint := KubeletHealthCheckEndpoint()
176193

177-
assert.Equal(t, kubeProxyHCEndpoint, test.expectedKubeProxyEndpoint)
178-
assert.Equal(t, kubeletHCEndpoint, test.expectedKubeletEndpoint)
194+
assert.Equal(t, test.expectedKubeProxyEndpoint, kubeProxyHCEndpoint)
195+
assert.Equal(t, test.expectedKubeletEndpoint, kubeletHCEndpoint)
179196
})
180197
}
181198
}

0 commit comments

Comments
 (0)