Skip to content

Commit 9f0a783

Browse files
authored
Merge pull request kubernetes#95254 from cmluciano/cml/proxyconfigdefaults
proxy: Add tests for kube-proxy config defaulting
2 parents 6e9475b + 601c515 commit 9f0a783

File tree

2 files changed

+130
-0
lines changed

2 files changed

+130
-0
lines changed

pkg/proxy/apis/config/v1alpha1/BUILD

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package(default_visibility = ["//visibility:public"])
33
load(
44
"@io_bazel_rules_go//go:def.bzl",
55
"go_library",
6+
"go_test",
67
)
78

89
go_library(
@@ -43,3 +44,15 @@ filegroup(
4344
srcs = [":package-srcs"],
4445
tags = ["automanaged"],
4546
)
47+
48+
go_test(
49+
name = "go_default_test",
50+
srcs = ["defaults_test.go"],
51+
embed = [":go_default_library"],
52+
deps = [
53+
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
54+
"//staging/src/k8s.io/component-base/config/v1alpha1:go_default_library",
55+
"//staging/src/k8s.io/kube-proxy/config/v1alpha1:go_default_library",
56+
"//vendor/github.com/google/go-cmp/cmp:go_default_library",
57+
],
58+
)
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
"testing"
21+
"time"
22+
23+
"github.com/google/go-cmp/cmp"
24+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25+
componentbaseconfig "k8s.io/component-base/config/v1alpha1"
26+
kubeproxyconfigv1alpha1 "k8s.io/kube-proxy/config/v1alpha1"
27+
)
28+
29+
func TestDefaultsKubeProxyConfiguration(t *testing.T) {
30+
masqBit := int32(14)
31+
oomScore := int32(-999)
32+
ctMaxPerCore := int32(32768)
33+
ctMin := int32(131072)
34+
testCases := []struct {
35+
name string
36+
original *kubeproxyconfigv1alpha1.KubeProxyConfiguration
37+
expected *kubeproxyconfigv1alpha1.KubeProxyConfiguration
38+
}{
39+
{
40+
name: "empty-config",
41+
original: &kubeproxyconfigv1alpha1.KubeProxyConfiguration{},
42+
expected: &kubeproxyconfigv1alpha1.KubeProxyConfiguration{
43+
FeatureGates: map[string]bool{},
44+
BindAddress: "0.0.0.0",
45+
HealthzBindAddress: "0.0.0.0:10256",
46+
MetricsBindAddress: "127.0.0.1:10249",
47+
ClientConnection: componentbaseconfig.ClientConnectionConfiguration{
48+
ContentType: "application/vnd.kubernetes.protobuf",
49+
QPS: 5,
50+
Burst: 10,
51+
},
52+
IPTables: kubeproxyconfigv1alpha1.KubeProxyIPTablesConfiguration{
53+
MasqueradeBit: &masqBit,
54+
MasqueradeAll: false,
55+
SyncPeriod: metav1.Duration{Duration: 30 * time.Second},
56+
MinSyncPeriod: metav1.Duration{Duration: 1 * time.Second},
57+
},
58+
IPVS: kubeproxyconfigv1alpha1.KubeProxyIPVSConfiguration{
59+
SyncPeriod: metav1.Duration{Duration: 30 * time.Second},
60+
},
61+
OOMScoreAdj: &oomScore,
62+
UDPIdleTimeout: metav1.Duration{Duration: 250 * time.Millisecond},
63+
Conntrack: kubeproxyconfigv1alpha1.KubeProxyConntrackConfiguration{
64+
MaxPerCore: &ctMaxPerCore,
65+
Min: &ctMin,
66+
TCPEstablishedTimeout: &metav1.Duration{Duration: 24 * time.Hour},
67+
TCPCloseWaitTimeout: &metav1.Duration{Duration: 1 * time.Hour},
68+
},
69+
ConfigSyncPeriod: metav1.Duration{Duration: 15 * time.Minute},
70+
},
71+
},
72+
{
73+
name: "metrics and healthz address with no port",
74+
original: &kubeproxyconfigv1alpha1.KubeProxyConfiguration{
75+
MetricsBindAddress: "127.0.0.1",
76+
HealthzBindAddress: "127.0.0.1",
77+
},
78+
expected: &kubeproxyconfigv1alpha1.KubeProxyConfiguration{
79+
FeatureGates: map[string]bool{},
80+
BindAddress: "0.0.0.0",
81+
HealthzBindAddress: "127.0.0.1:10256",
82+
MetricsBindAddress: "127.0.0.1:10249",
83+
ClientConnection: componentbaseconfig.ClientConnectionConfiguration{
84+
ContentType: "application/vnd.kubernetes.protobuf",
85+
QPS: 5,
86+
Burst: 10,
87+
},
88+
IPTables: kubeproxyconfigv1alpha1.KubeProxyIPTablesConfiguration{
89+
MasqueradeBit: &masqBit,
90+
MasqueradeAll: false,
91+
SyncPeriod: metav1.Duration{Duration: 30 * time.Second},
92+
MinSyncPeriod: metav1.Duration{Duration: 1 * time.Second},
93+
},
94+
IPVS: kubeproxyconfigv1alpha1.KubeProxyIPVSConfiguration{
95+
SyncPeriod: metav1.Duration{Duration: 30 * time.Second},
96+
},
97+
OOMScoreAdj: &oomScore,
98+
UDPIdleTimeout: metav1.Duration{Duration: 250 * time.Millisecond},
99+
Conntrack: kubeproxyconfigv1alpha1.KubeProxyConntrackConfiguration{
100+
MaxPerCore: &ctMaxPerCore,
101+
Min: &ctMin,
102+
TCPEstablishedTimeout: &metav1.Duration{Duration: 24 * time.Hour},
103+
TCPCloseWaitTimeout: &metav1.Duration{Duration: 1 * time.Hour},
104+
},
105+
ConfigSyncPeriod: metav1.Duration{Duration: 15 * time.Minute},
106+
},
107+
},
108+
}
109+
for _, tc := range testCases {
110+
t.Run(tc.name, func(t *testing.T) {
111+
SetDefaults_KubeProxyConfiguration(tc.original)
112+
if diff := cmp.Diff(tc.expected, tc.original); diff != "" {
113+
t.Errorf("Got unexpected defaults (-want, +got):\n%s", diff)
114+
}
115+
})
116+
}
117+
}

0 commit comments

Comments
 (0)