Skip to content

Commit

Permalink
Merge pull request kubernetes#88934 from aojea/endpointnolog
Browse files Browse the repository at this point in the history
Stop flooding the kube-proxy logs on dual-stack because of IPFamily
  • Loading branch information
k8s-ci-robot authored Mar 10, 2020
2 parents c4a7d3c + df58c04 commit 0ec85a1
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 4 deletions.
9 changes: 8 additions & 1 deletion pkg/proxy/metaproxier/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package(default_visibility = ["//visibility:public"])

load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "go_default_library",
Expand Down Expand Up @@ -28,3 +28,10 @@ filegroup(
srcs = [":package-srcs"],
tags = ["automanaged"],
)

go_test(
name = "go_default_test",
srcs = ["meta_proxier_test.go"],
embed = [":go_default_library"],
deps = ["//staging/src/k8s.io/api/core/v1:go_default_library"],
)
6 changes: 3 additions & 3 deletions pkg/proxy/metaproxier/meta_proxier.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (proxier *metaProxier) OnServiceSynced() {
func (proxier *metaProxier) OnEndpointsAdd(endpoints *v1.Endpoints) {
ipFamily, err := endpointsIPFamily(endpoints)
if err != nil {
klog.Warningf("failed to add endpoints %s/%s with error %v", endpoints.ObjectMeta.Namespace, endpoints.ObjectMeta.Name, err)
klog.V(4).Infof("failed to add endpoints %s/%s with error %v", endpoints.ObjectMeta.Namespace, endpoints.ObjectMeta.Name, err)
return
}
if *ipFamily == v1.IPv4Protocol {
Expand All @@ -118,7 +118,7 @@ func (proxier *metaProxier) OnEndpointsAdd(endpoints *v1.Endpoints) {
func (proxier *metaProxier) OnEndpointsUpdate(oldEndpoints, endpoints *v1.Endpoints) {
ipFamily, err := endpointsIPFamily(endpoints)
if err != nil {
klog.Warningf("failed to update endpoints %s/%s with error %v", endpoints.ObjectMeta.Namespace, endpoints.ObjectMeta.Name, err)
klog.V(4).Infof("failed to update endpoints %s/%s with error %v", endpoints.ObjectMeta.Namespace, endpoints.ObjectMeta.Name, err)
return
}

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

Expand Down
89 changes: 89 additions & 0 deletions pkg/proxy/metaproxier/meta_proxier_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package metaproxier

import (
"reflect"
"testing"

v1 "k8s.io/api/core/v1"
)

func Test_endpointsIPFamily(t *testing.T) {

ipv4 := v1.IPv4Protocol
ipv6 := v1.IPv6Protocol

tests := []struct {
name string
endpoints *v1.Endpoints
want *v1.IPFamily
wantErr bool
errorMsg string
}{
{
name: "Endpoints No Subsets",
endpoints: &v1.Endpoints{},
want: nil,
wantErr: true,
errorMsg: "failed to identify ipfamily for endpoints (no subsets)",
},
{
name: "Endpoints No Addresses",
endpoints: &v1.Endpoints{Subsets: []v1.EndpointSubset{{NotReadyAddresses: []v1.EndpointAddress{}}}},
want: nil,
wantErr: true,
errorMsg: "failed to identify ipfamily for endpoints (no addresses)",
},
{
name: "Endpoints Address Has No IP",
endpoints: &v1.Endpoints{Subsets: []v1.EndpointSubset{{Addresses: []v1.EndpointAddress{{Hostname: "testhost", IP: ""}}}}},
want: nil,
wantErr: true,
errorMsg: "failed to identify ipfamily for endpoints (address has no ip)",
},
{
name: "Endpoints Address IPv4",
endpoints: &v1.Endpoints{Subsets: []v1.EndpointSubset{{Addresses: []v1.EndpointAddress{{IP: "1.2.3.4"}}}}},
want: &ipv4,
wantErr: false,
},
{
name: "Endpoints Address IPv6",
endpoints: &v1.Endpoints{Subsets: []v1.EndpointSubset{{Addresses: []v1.EndpointAddress{{IP: "2001:db9::2"}}}}},
want: &ipv6,
wantErr: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := endpointsIPFamily(tt.endpoints)
if (err != nil) != tt.wantErr {
t.Errorf("endpointsIPFamily() error = %v, wantErr %v", err, tt.wantErr)
return
}
if err != nil && err.Error() != tt.errorMsg {
t.Errorf("endpointsIPFamily() error = %v, wantErr %v", err, tt.errorMsg)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("endpointsIPFamily() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 0ec85a1

Please sign in to comment.