class KubernetesEndpointsCatalogWatch
		implements Function<KubernetesCatalogWatchContext, List<EndpointNameAndNamespace>> {

	private static final LogAccessor LOG = new LogAccessor(LogFactory.getLog(KubernetesEndpointsCatalogWatch.class));

	@Override
	public List<EndpointNameAndNamespace> apply(KubernetesCatalogWatchContext context) {
		List<V1Endpoints> endpoints;
		CoreV1Api coreV1Api = context.coreV1Api();
		if (context.properties().allNamespaces()) {
			LOG.debug(() -> "discovering endpoints in all namespaces");
			endpoints = endpoints(coreV1Api, context.properties().serviceLabels());
		}
		else if (!context.properties().namespaces().isEmpty()) {
			LOG.debug(() -> "discovering endpoints in " + context.properties().namespaces());
			List<V1Endpoints> inner = new ArrayList<>(context.properties().namespaces().size());
			context.properties().namespaces().forEach(namespace -> inner
					.addAll(namespacedEndpoints(coreV1Api, namespace, context.properties().serviceLabels())));
			endpoints = inner;
		}
		else {
			String namespace = KubernetesClientUtils.getApplicationNamespace(null, "catalog-watch",
					context.namespaceProvider());
			LOG.debug(() -> "discovering endpoints in namespace : " + namespace);
			endpoints = namespacedEndpoints(coreV1Api, namespace, context.properties().serviceLabels());
		}

		/**
		 * <pre>
		 *   - An "V1Endpoints" holds a List of V1EndpointSubset.
		 *   - A single V1EndpointSubset holds a List of V1EndpointAddress
		 *
		 *   - (The union of all V1EndpointSubsets is the Set of all V1Endpoints)
		 *   - Set of V1Endpoints is the cartesian product of :
		 *     V1EndpointSubset::getAddresses and V1EndpointSubset::getPorts (each is a List)
		 * </pre>
		 */
		Stream<V1ObjectReference> references = endpoints.stream().map(V1Endpoints::getSubsets).filter(Objects::nonNull)
				.flatMap(List::stream).map(V1EndpointSubset::getAddresses).filter(Objects::nonNull)
				.flatMap(List::stream).map(V1EndpointAddress::getTargetRef);

		return KubernetesCatalogWatchContext.state(references);

	}

	private List<V1Endpoints> endpoints(CoreV1Api client, Map<String, String> labels) {<FILL_FUNCTION_BODY>}

	private List<V1Endpoints> namespacedEndpoints(CoreV1Api client, String namespace, Map<String, String> labels) {
		try {
			return client.listNamespacedEndpoints(namespace, null, null, null, null, labelSelector(labels), null, null,
					null, null, null, null).getItems();
		}
		catch (ApiException e) {
			LOG.warn(e, () -> "can not list endpoints in namespace " + namespace);
			return Collections.emptyList();
		}
	}

}

		try {
			return client.listEndpointsForAllNamespaces(null, null, null, labelSelector(labels), null, null, null, null,
					null, null, null).getItems();
		}
		catch (ApiException e) {
			LOG.warn(e, () -> "can not list endpoints in all namespaces");
			return Collections.emptyList();
		}
	
<no_super_class>