Skip to content

Commit 0ec85a1

Browse files
authored
Merge pull request kubernetes#88934 from aojea/endpointnolog
Stop flooding the kube-proxy logs on dual-stack because of IPFamily
2 parents c4a7d3c + df58c04 commit 0ec85a1

File tree

3 files changed

+100
-4
lines changed

3 files changed

+100
-4
lines changed

pkg/proxy/metaproxier/BUILD

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package(default_visibility = ["//visibility:public"])
22

3-
load("@io_bazel_rules_go//go:def.bzl", "go_library")
3+
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
44

55
go_library(
66
name = "go_default_library",
@@ -28,3 +28,10 @@ filegroup(
2828
srcs = [":package-srcs"],
2929
tags = ["automanaged"],
3030
)
31+
32+
go_test(
33+
name = "go_default_test",
34+
srcs = ["meta_proxier_test.go"],
35+
embed = [":go_default_library"],
36+
deps = ["//staging/src/k8s.io/api/core/v1:go_default_library"],
37+
)

pkg/proxy/metaproxier/meta_proxier.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (proxier *metaProxier) OnServiceSynced() {
103103
func (proxier *metaProxier) OnEndpointsAdd(endpoints *v1.Endpoints) {
104104
ipFamily, err := endpointsIPFamily(endpoints)
105105
if err != nil {
106-
klog.Warningf("failed to add endpoints %s/%s with error %v", endpoints.ObjectMeta.Namespace, endpoints.ObjectMeta.Name, err)
106+
klog.V(4).Infof("failed to add endpoints %s/%s with error %v", endpoints.ObjectMeta.Namespace, endpoints.ObjectMeta.Name, err)
107107
return
108108
}
109109
if *ipFamily == v1.IPv4Protocol {
@@ -118,7 +118,7 @@ func (proxier *metaProxier) OnEndpointsAdd(endpoints *v1.Endpoints) {
118118
func (proxier *metaProxier) OnEndpointsUpdate(oldEndpoints, endpoints *v1.Endpoints) {
119119
ipFamily, err := endpointsIPFamily(endpoints)
120120
if err != nil {
121-
klog.Warningf("failed to update endpoints %s/%s with error %v", endpoints.ObjectMeta.Namespace, endpoints.ObjectMeta.Name, err)
121+
klog.V(4).Infof("failed to update endpoints %s/%s with error %v", endpoints.ObjectMeta.Namespace, endpoints.ObjectMeta.Name, err)
122122
return
123123
}
124124

@@ -134,7 +134,7 @@ func (proxier *metaProxier) OnEndpointsUpdate(oldEndpoints, endpoints *v1.Endpoi
134134
func (proxier *metaProxier) OnEndpointsDelete(endpoints *v1.Endpoints) {
135135
ipFamily, err := endpointsIPFamily(endpoints)
136136
if err != nil {
137-
klog.Warningf("failed to delete endpoints %s/%s with error %v", endpoints.ObjectMeta.Namespace, endpoints.ObjectMeta.Name, err)
137+
klog.V(4).Infof("failed to delete endpoints %s/%s with error %v", endpoints.ObjectMeta.Namespace, endpoints.ObjectMeta.Name, err)
138138
return
139139
}
140140

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
Copyright 2019 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 metaproxier
18+
19+
import (
20+
"reflect"
21+
"testing"
22+
23+
v1 "k8s.io/api/core/v1"
24+
)
25+
26+
func Test_endpointsIPFamily(t *testing.T) {
27+
28+
ipv4 := v1.IPv4Protocol
29+
ipv6 := v1.IPv6Protocol
30+
31+
tests := []struct {
32+
name string
33+
endpoints *v1.Endpoints
34+
want *v1.IPFamily
35+
wantErr bool
36+
errorMsg string
37+
}{
38+
{
39+
name: "Endpoints No Subsets",
40+
endpoints: &v1.Endpoints{},
41+
want: nil,
42+
wantErr: true,
43+
errorMsg: "failed to identify ipfamily for endpoints (no subsets)",
44+
},
45+
{
46+
name: "Endpoints No Addresses",
47+
endpoints: &v1.Endpoints{Subsets: []v1.EndpointSubset{{NotReadyAddresses: []v1.EndpointAddress{}}}},
48+
want: nil,
49+
wantErr: true,
50+
errorMsg: "failed to identify ipfamily for endpoints (no addresses)",
51+
},
52+
{
53+
name: "Endpoints Address Has No IP",
54+
endpoints: &v1.Endpoints{Subsets: []v1.EndpointSubset{{Addresses: []v1.EndpointAddress{{Hostname: "testhost", IP: ""}}}}},
55+
want: nil,
56+
wantErr: true,
57+
errorMsg: "failed to identify ipfamily for endpoints (address has no ip)",
58+
},
59+
{
60+
name: "Endpoints Address IPv4",
61+
endpoints: &v1.Endpoints{Subsets: []v1.EndpointSubset{{Addresses: []v1.EndpointAddress{{IP: "1.2.3.4"}}}}},
62+
want: &ipv4,
63+
wantErr: false,
64+
},
65+
{
66+
name: "Endpoints Address IPv6",
67+
endpoints: &v1.Endpoints{Subsets: []v1.EndpointSubset{{Addresses: []v1.EndpointAddress{{IP: "2001:db9::2"}}}}},
68+
want: &ipv6,
69+
wantErr: false,
70+
},
71+
}
72+
73+
for _, tt := range tests {
74+
t.Run(tt.name, func(t *testing.T) {
75+
got, err := endpointsIPFamily(tt.endpoints)
76+
if (err != nil) != tt.wantErr {
77+
t.Errorf("endpointsIPFamily() error = %v, wantErr %v", err, tt.wantErr)
78+
return
79+
}
80+
if err != nil && err.Error() != tt.errorMsg {
81+
t.Errorf("endpointsIPFamily() error = %v, wantErr %v", err, tt.errorMsg)
82+
return
83+
}
84+
if !reflect.DeepEqual(got, tt.want) {
85+
t.Errorf("endpointsIPFamily() = %v, want %v", got, tt.want)
86+
}
87+
})
88+
}
89+
}

0 commit comments

Comments
 (0)