Skip to content

Commit

Permalink
Merge pull request #455 from jcmoraisjr/jm-fix-ep-targetref
Browse files Browse the repository at this point in the history
fix panic reading empty targetRef from ep
  • Loading branch information
jcmoraisjr authored Nov 18, 2019
2 parents e773e23 + 510f267 commit ddbab90
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
9 changes: 8 additions & 1 deletion pkg/converters/utils/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,17 @@ func newEndpointAddr(addr *api.EndpointAddress, port int) *Endpoint {
return &Endpoint{
IP: addr.IP,
Port: port,
TargetRef: fmt.Sprintf("%s/%s", addr.TargetRef.Namespace, addr.TargetRef.Name),
TargetRef: targetRefToString(addr.TargetRef),
}
}

func targetRefToString(targetRef *api.ObjectReference) string {
if targetRef == nil {
return ""
}
return fmt.Sprintf("%s/%s", targetRef.Namespace, targetRef.Name)
}

func newEndpointIP(ip string, port int) *Endpoint {
return &Endpoint{
IP: ip,
Expand Down
11 changes: 8 additions & 3 deletions pkg/converters/utils/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ func TestCreateEndpoints(t *testing.T) {
for _, test := range testCases {
c := setup(t)
svc, ep := helper_test.CreateService("default/echo", test.declarePort, test.endpoints)
for _, ss := range ep.Subsets {
for i := range ss.Addresses {
ss.Addresses[i].TargetRef = nil
}
for i := range ss.NotReadyAddresses {
ss.NotReadyAddresses[i].TargetRef = nil
}
}
cache := &helper_test.CacheMock{
SvcList: []*api.Service{svc},
EpList: map[string]*api.Endpoints{"default/echo": ep},
Expand All @@ -112,9 +120,6 @@ func TestCreateEndpoints(t *testing.T) {
if port != nil {
endpoints, _, _ = CreateEndpoints(cache, svc, port)
}
for _, ep := range endpoints {
ep.TargetRef = ""
}
if !reflect.DeepEqual(endpoints, test.expected) {
t.Errorf("endpoints differ: expected=%+v actual=%+v", test.expected, endpoints)
}
Expand Down

0 comments on commit ddbab90

Please sign in to comment.