@@ -65,6 +65,13 @@ func TestGetAPIServerProbeAddress(t *testing.T) {
65
65
},
66
66
expected : "10.10.10.10" ,
67
67
},
68
+ {
69
+ desc : "filled in ipv6 AdvertiseAddress endpoint returns it" ,
70
+ endpoint : & kubeadmapi.APIEndpoint {
71
+ AdvertiseAddress : "2001:abcd:bcda::1" ,
72
+ },
73
+ expected : "2001:abcd:bcda::1" ,
74
+ },
68
75
}
69
76
70
77
for _ , test := range tests {
@@ -103,6 +110,17 @@ func TestGetControllerManagerProbeAddress(t *testing.T) {
103
110
},
104
111
expected : "10.10.10.10" ,
105
112
},
113
+ {
114
+ desc : "setting controller manager extra ipv6 address arg to something acknowledges it" ,
115
+ cfg : & kubeadmapi.ClusterConfiguration {
116
+ ControllerManager : kubeadmapi.ControlPlaneComponent {
117
+ ExtraArgs : map [string ]string {
118
+ kubeControllerManagerAddressArg : "2001:abcd:bcda::1" ,
119
+ },
120
+ },
121
+ },
122
+ expected : "2001:abcd:bcda::1" ,
123
+ },
106
124
}
107
125
108
126
for _ , test := range tests {
@@ -119,6 +137,7 @@ func TestGetEtcdProbeEndpoint(t *testing.T) {
119
137
var tests = []struct {
120
138
name string
121
139
cfg * kubeadmapi.Etcd
140
+ isIPv6 bool
122
141
expectedHostname string
123
142
expectedPort int
124
143
expectedScheme v1.URIScheme
@@ -131,6 +150,7 @@ func TestGetEtcdProbeEndpoint(t *testing.T) {
131
150
"listen-metrics-urls" : "https://1.2.3.4:1234,https://4.3.2.1:2381" },
132
151
},
133
152
},
153
+ isIPv6 : false ,
134
154
expectedHostname : "1.2.3.4" ,
135
155
expectedPort : 1234 ,
136
156
expectedScheme : v1 .URISchemeHTTPS ,
@@ -143,6 +163,7 @@ func TestGetEtcdProbeEndpoint(t *testing.T) {
143
163
"listen-metrics-urls" : "http://1.2.3.4:1234" },
144
164
},
145
165
},
166
+ isIPv6 : false ,
146
167
expectedHostname : "1.2.3.4" ,
147
168
expectedPort : 1234 ,
148
169
expectedScheme : v1 .URISchemeHTTP ,
@@ -155,6 +176,7 @@ func TestGetEtcdProbeEndpoint(t *testing.T) {
155
176
"listen-metrics-urls" : "1.2.3.4" },
156
177
},
157
178
},
179
+ isIPv6 : false ,
158
180
expectedHostname : "127.0.0.1" ,
159
181
expectedPort : kubeadmconstants .EtcdMetricsPort ,
160
182
expectedScheme : v1 .URISchemeHTTP ,
@@ -167,23 +189,87 @@ func TestGetEtcdProbeEndpoint(t *testing.T) {
167
189
"listen-metrics-urls" : "https://1.2.3.4" },
168
190
},
169
191
},
192
+ isIPv6 : false ,
170
193
expectedHostname : "1.2.3.4" ,
171
194
expectedPort : kubeadmconstants .EtcdMetricsPort ,
172
195
expectedScheme : v1 .URISchemeHTTPS ,
173
196
},
197
+ {
198
+ name : "etcd probe URL from two IPv6 URLs" ,
199
+ cfg : & kubeadmapi.Etcd {
200
+ Local : & kubeadmapi.LocalEtcd {
201
+ ExtraArgs : map [string ]string {
202
+ "listen-metrics-urls" : "https://[2001:abcd:bcda::1]:1234,https://[2001:abcd:bcda::2]:2381" },
203
+ },
204
+ },
205
+ isIPv6 : true ,
206
+ expectedHostname : "2001:abcd:bcda::1" ,
207
+ expectedPort : 1234 ,
208
+ expectedScheme : v1 .URISchemeHTTPS ,
209
+ },
210
+ {
211
+ name : "etcd probe localhost IPv6 URL with HTTP scheme" ,
212
+ cfg : & kubeadmapi.Etcd {
213
+ Local : & kubeadmapi.LocalEtcd {
214
+ ExtraArgs : map [string ]string {
215
+ "listen-metrics-urls" : "http://[::1]:1234" },
216
+ },
217
+ },
218
+ isIPv6 : true ,
219
+ expectedHostname : "::1" ,
220
+ expectedPort : 1234 ,
221
+ expectedScheme : v1 .URISchemeHTTP ,
222
+ },
223
+ {
224
+ name : "etcd probe IPv6 URL with HTTP scheme" ,
225
+ cfg : & kubeadmapi.Etcd {
226
+ Local : & kubeadmapi.LocalEtcd {
227
+ ExtraArgs : map [string ]string {
228
+ "listen-metrics-urls" : "http://[2001:abcd:bcda::1]:1234" },
229
+ },
230
+ },
231
+ isIPv6 : true ,
232
+ expectedHostname : "2001:abcd:bcda::1" ,
233
+ expectedPort : 1234 ,
234
+ expectedScheme : v1 .URISchemeHTTP ,
235
+ },
236
+ {
237
+ name : "etcd probe IPv6 URL without port" ,
238
+ cfg : & kubeadmapi.Etcd {
239
+ Local : & kubeadmapi.LocalEtcd {
240
+ ExtraArgs : map [string ]string {
241
+ "listen-metrics-urls" : "https://[2001:abcd:bcda::1]" },
242
+ },
243
+ },
244
+ isIPv6 : true ,
245
+ expectedHostname : "2001:abcd:bcda::1" ,
246
+ expectedPort : kubeadmconstants .EtcdMetricsPort ,
247
+ expectedScheme : v1 .URISchemeHTTPS ,
248
+ },
174
249
{
175
250
name : "etcd probe URL from defaults" ,
176
251
cfg : & kubeadmapi.Etcd {
177
252
Local : & kubeadmapi.LocalEtcd {},
178
253
},
254
+ isIPv6 : false ,
179
255
expectedHostname : "127.0.0.1" ,
180
256
expectedPort : kubeadmconstants .EtcdMetricsPort ,
181
257
expectedScheme : v1 .URISchemeHTTP ,
182
258
},
259
+ {
260
+ name : "etcd probe URL from defaults if IPv6" ,
261
+ cfg : & kubeadmapi.Etcd {
262
+ Local : & kubeadmapi.LocalEtcd {},
263
+ },
264
+ isIPv6 : true ,
265
+ expectedHostname : "::1" ,
266
+ expectedPort : kubeadmconstants .EtcdMetricsPort ,
267
+ expectedScheme : v1 .URISchemeHTTP ,
268
+ },
183
269
}
184
270
for _ , rt := range tests {
185
271
t .Run (rt .name , func (t * testing.T ) {
186
- hostname , port , scheme := GetEtcdProbeEndpoint (rt .cfg )
272
+ hostname , port , scheme := GetEtcdProbeEndpoint (rt .cfg , rt . isIPv6 )
187
273
if hostname != rt .expectedHostname {
188
274
t .Errorf ("%q test case failed:\n \t expected hostname: %s\n \t got: %s" ,
189
275
rt .name , rt .expectedHostname , hostname )
0 commit comments