func()

in pkg/k8scontext/context.go [422:462]


func (c *Context) generateEndpointsFromMultiClusterService(serviceKey string) (*v1.Endpoints, error) {
	multiClusterServiceInterface, exist, err := c.Caches.MultiClusterService.GetByKey(serviceKey)

	if !exist {
		e := controllererrors.NewErrorf(
			controllererrors.ErrorFetchingMultiClusterService,
			"MultiCluster service not found for %s",
			serviceKey)
		klog.Error(e.Error())
		c.MetricStore.IncErrorCount(e.Code)
		return nil, e
	}

	if err != nil {
		e := controllererrors.NewErrorWithInnerErrorf(
			controllererrors.ErrorFetchingMultiClusterService,
			err,
			"Error fetching MultiCluster service from store for %s",
			serviceKey)
		klog.Error(e.Error())
		c.MetricStore.IncErrorCount(e.Code)
		return nil, e
	}

	multiClusterService := multiClusterServiceInterface.(*multiClusterService.MultiClusterService)
	endpoints := &v1.Endpoints{}
	subset := v1.EndpointSubset{}

	for _, multiClusterEndpoint := range multiClusterService.Status.Endpoints {
		address := v1.EndpointAddress{IP: multiClusterEndpoint.IP}
		subset.Addresses = append(subset.Addresses, address)
	}

	for _, ports := range multiClusterService.Spec.Ports {
		v1Port := v1.EndpointPort{Port: int32(ports.Port), Protocol: v1.Protocol(ports.Protocol)}
		subset.Ports = append(subset.Ports, v1Port)
	}

	endpoints.Subsets = []v1.EndpointSubset{subset}
	return endpoints, nil
}