class KubernetesDiscoveryClient implements DiscoveryClient, EnvironmentAware {

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

	private final KubernetesDiscoveryProperties properties;

	private final KubernetesClientServicesFunction kubernetesClientServicesFunction;

	private final ServicePortSecureResolver servicePortSecureResolver;

	private final Fabric8DiscoveryServicesAdapter adapter;

	private KubernetesClient client;

	private KubernetesNamespaceProvider namespaceProvider;

	public KubernetesDiscoveryClient(KubernetesClient client,
			KubernetesDiscoveryProperties kubernetesDiscoveryProperties,
			KubernetesClientServicesFunction kubernetesClientServicesFunction) {

		this(client, kubernetesDiscoveryProperties, kubernetesClientServicesFunction, null,
				new ServicePortSecureResolver(kubernetesDiscoveryProperties));
	}

	KubernetesDiscoveryClient(KubernetesClient client, KubernetesDiscoveryProperties kubernetesDiscoveryProperties,
			KubernetesClientServicesFunction kubernetesClientServicesFunction, Predicate<Service> filter,
			ServicePortSecureResolver servicePortSecureResolver) {

		this.client = client;
		this.properties = kubernetesDiscoveryProperties;
		this.servicePortSecureResolver = servicePortSecureResolver;
		this.kubernetesClientServicesFunction = kubernetesClientServicesFunction;
		this.adapter = new Fabric8DiscoveryServicesAdapter(kubernetesClientServicesFunction,
				kubernetesDiscoveryProperties, filter);
	}

	public KubernetesClient getClient() {
		return this.client;
	}

	public void setClient(KubernetesClient client) {
		this.client = client;
	}

	@Override
	public String description() {
		return "Fabric8 Kubernetes Discovery Client";
	}

	@Override
	public List<ServiceInstance> getInstances(String serviceId) {<FILL_FUNCTION_BODY>}

	public List<Endpoints> getEndPointsList(String serviceId) {
		return endpoints(properties, client, namespaceProvider, "fabric8-discovery", serviceId, adapter.filter());
	}

	private List<ServiceInstance> serviceInstances(Endpoints endpoints, String serviceId) {

		List<EndpointSubset> subsets = endpoints.getSubsets();
		if (subsets.isEmpty()) {
			LOG.debug(() -> "serviceId : " + serviceId + " does not have any subsets");
			return List.of();
		}

		String namespace = endpoints.getMetadata().getNamespace();
		List<ServiceInstance> instances = new ArrayList<>();

		Service service = client.services().inNamespace(namespace).withName(serviceId).get();
		ServiceMetadata serviceMetadata = serviceMetadata(service);
		Map<String, Integer> portsData = endpointSubsetsPortData(subsets);

		Map<String, String> serviceInstanceMetadata = serviceInstanceMetadata(portsData, serviceMetadata, properties);

		for (EndpointSubset endpointSubset : subsets) {

			Map<String, Integer> endpointsPortData = endpointSubsetsPortData(List.of(endpointSubset));
			ServicePortNameAndNumber portData = endpointsPort(endpointsPortData, serviceMetadata, properties);

			List<EndpointAddress> addresses = addresses(endpointSubset, properties);
			for (EndpointAddress endpointAddress : addresses) {

				Fabric8InstanceIdHostPodNameSupplier supplierOne = nonExternalName(endpointAddress, service);
				Fabric8PodLabelsAndAnnotationsSupplier supplierTwo = nonExternalName(client, namespace);

				ServiceInstance serviceInstance = serviceInstance(servicePortSecureResolver, serviceMetadata,
						supplierOne, supplierTwo, portData, serviceInstanceMetadata, properties);
				instances.add(serviceInstance);
			}
		}

		return instances;
	}

	@Override
	public List<String> getServices() {
		List<String> services = adapter.apply(client).stream().map(s -> s.getMetadata().getName()).distinct().toList();
		LOG.debug(() -> "will return services : " + services);
		return services;
	}

	@Deprecated(forRemoval = true)
	public List<String> getServices(Predicate<Service> filter) {
		return new Fabric8DiscoveryServicesAdapter(kubernetesClientServicesFunction, properties, filter).apply(client)
				.stream().map(s -> s.getMetadata().getName()).distinct().toList();
	}

	@Override
	public int getOrder() {
		return properties.order();
	}

	@Deprecated(forRemoval = true)
	@Override
	public final void setEnvironment(Environment environment) {
		namespaceProvider = new KubernetesNamespaceProvider(environment);
	}

}

		Objects.requireNonNull(serviceId);

		List<Endpoints> allEndpoints = getEndPointsList(serviceId).stream().toList();

		List<ServiceInstance> instances = new ArrayList<>();
		for (Endpoints endpoints : allEndpoints) {
			// endpoints are only those that matched the serviceId
			instances.addAll(serviceInstances(endpoints, serviceId));
		}

		if (properties.includeExternalNameServices()) {
			LOG.debug(() -> "Searching for 'ExternalName' type of services with serviceId : " + serviceId);
			List<Service> services = services(properties, client, namespaceProvider,
					s -> s.getSpec().getType().equals(EXTERNAL_NAME), Map.of("metadata.name", serviceId),
					"fabric8-discovery");
			for (Service service : services) {
				ServiceMetadata serviceMetadata = serviceMetadata(service);
				Map<String, String> serviceInstanceMetadata = serviceInstanceMetadata(Map.of(), serviceMetadata,
						properties);

				Fabric8InstanceIdHostPodNameSupplier supplierOne = externalName(service);
				Fabric8PodLabelsAndAnnotationsSupplier supplierTwo = externalName();

				ServiceInstance externalNameServiceInstance = serviceInstance(null, serviceMetadata, supplierOne,
						supplierTwo, new ServicePortNameAndNumber(-1, null), serviceInstanceMetadata, properties);
				instances.add(externalNameServiceInstance);
			}
		}

		return instances;
	
<no_super_class>