diff --git a/pkg/converters/utils/services.go b/pkg/converters/utils/services.go index 943891f75..ad42161cb 100644 --- a/pkg/converters/utils/services.go +++ b/pkg/converters/utils/services.go @@ -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, diff --git a/pkg/converters/utils/services_test.go b/pkg/converters/utils/services_test.go index 0c96160ca..36c6cc182 100644 --- a/pkg/converters/utils/services_test.go +++ b/pkg/converters/utils/services_test.go @@ -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}, @@ -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) }