@@ -33,7 +33,6 @@ import (
33
33
utilpointer "k8s.io/utils/pointer"
34
34
35
35
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
36
- kuberuntime "k8s.io/apimachinery/pkg/runtime"
37
36
"k8s.io/apimachinery/pkg/util/diff"
38
37
componentbaseconfig "k8s.io/component-base/config"
39
38
kubeproxyconfig "k8s.io/kubernetes/pkg/proxy/apis/config"
@@ -161,6 +160,7 @@ nodePortAddresses:
161
160
clusterCIDR string
162
161
healthzBindAddress string
163
162
metricsBindAddress string
163
+ extraConfig string
164
164
}{
165
165
{
166
166
name : "iptables mode, IPv4 all-zeros bind address" ,
@@ -219,6 +219,30 @@ nodePortAddresses:
219
219
healthzBindAddress : "[fd00:1::5]:12345" ,
220
220
metricsBindAddress : "[fd00:2::5]:23456" ,
221
221
},
222
+ {
223
+ // Test for unknown field within config.
224
+ // For v1alpha1 a lenient path is implemented and will throw a
225
+ // strict decoding warning instead of failing to load
226
+ name : "unknown field" ,
227
+ mode : "iptables" ,
228
+ bindAddress : "9.8.7.6" ,
229
+ clusterCIDR : "1.2.3.0/24" ,
230
+ healthzBindAddress : "1.2.3.4:12345" ,
231
+ metricsBindAddress : "2.3.4.5:23456" ,
232
+ extraConfig : "foo: bar" ,
233
+ },
234
+ {
235
+ // Test for duplicate field within config.
236
+ // For v1alpha1 a lenient path is implemented and will throw a
237
+ // strict decoding warning instead of failing to load
238
+ name : "duplicate field" ,
239
+ mode : "iptables" ,
240
+ bindAddress : "9.8.7.6" ,
241
+ clusterCIDR : "1.2.3.0/24" ,
242
+ healthzBindAddress : "1.2.3.4:12345" ,
243
+ metricsBindAddress : "2.3.4.5:23456" ,
244
+ extraConfig : "bindAddress: 9.8.7.6" ,
245
+ },
222
246
}
223
247
224
248
for _ , tc := range testCases {
@@ -268,11 +292,17 @@ nodePortAddresses:
268
292
269
293
options := NewOptions ()
270
294
271
- yaml := fmt .Sprintf (
295
+ baseYAML := fmt .Sprintf (
272
296
yamlTemplate , tc .bindAddress , tc .clusterCIDR ,
273
297
tc .healthzBindAddress , tc .metricsBindAddress , tc .mode )
298
+
299
+ // Append additional configuration to the base yaml template
300
+ yaml := fmt .Sprintf ("%s\n %s" , baseYAML , tc .extraConfig )
301
+
274
302
config , err := options .loadConfig ([]byte (yaml ))
303
+
275
304
assert .NoError (t , err , "unexpected error for %s: %v" , tc .name , err )
305
+
276
306
if ! reflect .DeepEqual (expected , config ) {
277
307
t .Fatalf ("unexpected config for %s, diff = %s" , tc .name , diff .ObjectDiff (config , expected ))
278
308
}
@@ -281,10 +311,15 @@ nodePortAddresses:
281
311
282
312
// TestLoadConfigFailures tests failure modes for loadConfig()
283
313
func TestLoadConfigFailures (t * testing.T ) {
284
- yamlTemplate := `bindAddress: 0.0.0.0
285
- clusterCIDR: "1.2.3.0/24"
286
- configSyncPeriod: 15s
287
- kind: KubeProxyConfiguration`
314
+ // TODO(phenixblue): Uncomment below template when v1alpha2+ of kube-proxy config is
315
+ // released with strict decoding. These associated tests will fail with
316
+ // the lenient codec and only one config API version.
317
+ /*
318
+ yamlTemplate := `bindAddress: 0.0.0.0
319
+ clusterCIDR: "1.2.3.0/24"
320
+ configSyncPeriod: 15s
321
+ kind: KubeProxyConfiguration`
322
+ */
288
323
289
324
testCases := []struct {
290
325
name string
@@ -307,16 +342,21 @@ kind: KubeProxyConfiguration`
307
342
config : "bindAddress: ::" ,
308
343
expErr : "mapping values are not allowed in this context" ,
309
344
},
310
- {
311
- name : "Duplicate fields" ,
312
- config : fmt .Sprintf ("%s\n bindAddess: 1.2.3.4" , yamlTemplate ),
313
- checkFn : kuberuntime .IsStrictDecodingError ,
314
- },
315
- {
316
- name : "Unknown field" ,
317
- config : fmt .Sprintf ("%s\n foo: bar" , yamlTemplate ),
318
- checkFn : kuberuntime .IsStrictDecodingError ,
319
- },
345
+ // TODO(phenixblue): Uncomment below tests when v1alpha2+ of kube-proxy config is
346
+ // released with strict decoding. These tests will fail with the
347
+ // lenient codec and only one config API version.
348
+ /*
349
+ {
350
+ name: "Duplicate fields",
351
+ config: fmt.Sprintf("%s\nbindAddress: 1.2.3.4", yamlTemplate),
352
+ checkFn: kuberuntime.IsStrictDecodingError,
353
+ },
354
+ {
355
+ name: "Unknown field",
356
+ config: fmt.Sprintf("%s\nfoo: bar", yamlTemplate),
357
+ checkFn: kuberuntime.IsStrictDecodingError,
358
+ },
359
+ */
320
360
}
321
361
322
362
version := "apiVersion: kubeproxy.config.k8s.io/v1alpha1"
0 commit comments