Skip to content

Commit

Permalink
Merge pull request #1734 from swetharepakula/eps-panic-1.17
Browse files Browse the repository at this point in the history
[Cherrypick #1733 in release-1.17] Do not return error if EndpointSlicesServiceKey func errors
  • Loading branch information
k8s-ci-robot authored Jun 21, 2022
2 parents da5eaf4 + 71ec1b7 commit 2eda6fc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
3 changes: 2 additions & 1 deletion pkg/utils/endpointslices/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ func EndpointSlicesByServiceFunc(obj interface{}) ([]string, error) {
}
key, err := EndpointSlicesServiceKey(es)
if err != nil {
return []string{}, err
// Do not return error, otherwise store will panic.
return []string{}, nil
}
return []string{key}, nil
}
11 changes: 3 additions & 8 deletions pkg/utils/endpointslices/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ func TestEndpointSlicesByServiceFunc(t *testing.T) {
testCases := []struct {
desc string
obj interface{}
expectError bool
expectedKeys []string
}{
{
Expand All @@ -44,7 +43,6 @@ func TestEndpointSlicesByServiceFunc(t *testing.T) {
Namespace: "nmspc",
},
},
expectError: true,
},
{
desc: "ReturnsKeyForProperSlices",
Expand All @@ -60,12 +58,9 @@ func TestEndpointSlicesByServiceFunc(t *testing.T) {
}
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
keys, e := EndpointSlicesByServiceFunc(tc.obj)
if tc.expectError && e == nil {
t.Errorf("Expected error, got no error and keys %s", keys)
}
if !tc.expectError && e != nil {
t.Errorf("Incorrect error, got: %v, expected nil", e)
keys, err := EndpointSlicesByServiceFunc(tc.obj)
if err != nil {
t.Errorf("Unexpected error, got: %v, expected nil", err)
}
if len(keys) != len(tc.expectedKeys) || (len(tc.expectedKeys) == 1 && keys[0] != tc.expectedKeys[0]) {
t.Errorf("Incorrect keys, got: %s, expected %s", keys, tc.expectedKeys)
Expand Down

0 comments on commit 2eda6fc

Please sign in to comment.