io.fabric8.kubernetes.api.model.EndpointsList Java Examples

The following examples show how to use io.fabric8.kubernetes.api.model.EndpointsList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KubernetesCatalogWatchTest.java    From spring-cloud-kubernetes with Apache License 2.0 6 votes vote down vote up
@Test
public void testEndpointsWithoutTargetRefs() {

	EndpointsList endpoints = createSingleEndpointEndpointListByPodName("api-pod");
	endpoints.getItems().get(0).getSubsets().get(0).getAddresses().get(0)
			.setTargetRef(null);

	when(this.endpointsOperation.list()).thenReturn(endpoints);
	when(this.kubernetesClient.endpoints()).thenReturn(this.endpointsOperation);

	this.underTest.catalogServicesWatch();
	// second execution on shuffleServices
	this.underTest.catalogServicesWatch();

	verify(this.applicationEventPublisher).publishEvent(any(HeartbeatEvent.class));
}
 
Example #2
Source File: EndpointsTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testList() {
  server.expect().withPath("/api/v1/namespaces/test/endpoints").andReturn(200, new EndpointsListBuilder().build()).once();
  server.expect().withPath("/api/v1/namespaces/ns1/endpoints").andReturn(200, new EndpointsListBuilder()
    .addNewItem().and()
    .addNewItem().and()
    .build()).once();
  server.expect().withPath("/api/v1/endpoints").andReturn(200, new EndpointsListBuilder()
    .addNewItem().and()
    .addNewItem().and()
    .addNewItem().and()
    .build()).once();

  KubernetesClient client = server.getClient();
  EndpointsList endpointsList = client.endpoints().list();
  assertNotNull(endpointsList);
  assertEquals(0, endpointsList.getItems().size());

  endpointsList = client.endpoints().inNamespace("ns1").list();
  assertNotNull(endpointsList);
  assertEquals(2, endpointsList.getItems().size());

  endpointsList = client.endpoints().inAnyNamespace().list();
  assertNotNull(endpointsList);
  assertEquals(3, endpointsList.getItems().size());
}
 
Example #3
Source File: EndpointsTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testListWithLabels() {
  server.expect().withPath("/api/v1/namespaces/test/endpoints?labelSelector=" + Utils.toUrlEncoded("key1=value1,key2=value2,key3=value3")).andReturn(200, new EndpointsListBuilder().build()).once();
  server.expect().withPath("/api/v1/namespaces/ns1/endpoints?labelSelector=" + Utils.toUrlEncoded("key1=value1,key2=value2")).andReturn(200, new EndpointsListBuilder()
    .addNewItem().and()
    .addNewItem().and()
    .build()).once();

  KubernetesClient client = server.getClient();
  EndpointsList endpointsList = client.endpoints()
    .withLabel("key1", "value1")
    .withLabel("key2","value2")
    .withLabel("key3","value3")
    .list();
  assertNotNull(endpointsList);
  assertEquals(0, endpointsList.getItems().size());

  endpointsList = client.endpoints().inNamespace("ns1")
    .withLabel("key1", "value1")
    .withLabel("key2","value2")
    .list();
  assertNotNull(endpointsList);
  assertEquals(2, endpointsList.getItems().size());
}
 
Example #4
Source File: KubernetesCatalogWatchTest.java    From spring-cloud-kubernetes with Apache License 2.0 5 votes vote down vote up
@Test
public void testEndpointsWithoutSubsets() {

	EndpointsList endpoints = createSingleEndpointEndpointListWithoutSubsets();

	when(this.endpointsOperation.list()).thenReturn(endpoints);
	when(this.kubernetesClient.endpoints()).thenReturn(this.endpointsOperation);

	this.underTest.catalogServicesWatch();
	// second execution on shuffleServices
	this.underTest.catalogServicesWatch();

	verify(this.applicationEventPublisher).publishEvent(any(HeartbeatEvent.class));
}
 
Example #5
Source File: KubernetesCatalogWatchTest.java    From spring-cloud-kubernetes with Apache License 2.0 5 votes vote down vote up
@Test
public void testEndpointsWithoutAddresses() {

	EndpointsList endpoints = createSingleEndpointEndpointListByPodName("api-pod");
	endpoints.getItems().get(0).getSubsets().get(0).setAddresses(null);

	when(this.endpointsOperation.list()).thenReturn(endpoints);
	when(this.kubernetesClient.endpoints()).thenReturn(this.endpointsOperation);

	this.underTest.catalogServicesWatch();
	// second execution on shuffleServices
	this.underTest.catalogServicesWatch();

	verify(this.applicationEventPublisher).publishEvent(any(HeartbeatEvent.class));
}
 
Example #6
Source File: KubernetesCatalogWatchTest.java    From spring-cloud-kubernetes with Apache License 2.0 5 votes vote down vote up
private EndpointsList createEndpointsListByServiceName(String... serviceNames) {
	List<Endpoints> endpoints = stream(serviceNames)
			.map(s -> createEndpointsByPodName(s + "-singlePodUniqueId"))
			.collect(Collectors.toList());

	EndpointsList endpointsList = new EndpointsList();
	endpointsList.setItems(endpoints);
	return endpointsList;
}
 
Example #7
Source File: KubernetesCatalogWatchTest.java    From spring-cloud-kubernetes with Apache License 2.0 5 votes vote down vote up
private EndpointsList createSingleEndpointEndpointListWithoutSubsets() {
	Endpoints endpoints = new Endpoints();

	EndpointsList endpointsList = new EndpointsList();
	endpointsList.setItems(Collections.singletonList(endpoints));
	return endpointsList;
}
 
Example #8
Source File: KubernetesCatalogWatchTest.java    From spring-cloud-kubernetes with Apache License 2.0 5 votes vote down vote up
private EndpointsList createSingleEndpointEndpointListByPodName(String... podNames) {
	Endpoints endpoints = new Endpoints();
	endpoints.setSubsets(createSubsetsByPodName(podNames));

	EndpointsList endpointsList = new EndpointsList();
	endpointsList.setItems(Collections.singletonList(endpoints));
	return endpointsList;
}
 
Example #9
Source File: KubernetesDiscoveryClientTest.java    From spring-cloud-kubernetes with Apache License 2.0 4 votes vote down vote up
@Test
public void getInstancesShouldBeAbleToHandleEndpointsFromMultipleNamespaces() {
	Endpoints endPoints1 = new EndpointsBuilder().withNewMetadata()
			.withName("endpoint").withNamespace("test").endMetadata().addNewSubset()
			.addNewAddress().withIp("ip1").withNewTargetRef().withUid("uid1")
			.endTargetRef().endAddress().addNewPort("http", 80, "TCP").endSubset()
			.build();

	Endpoints endpoints2 = new EndpointsBuilder().withNewMetadata()
			.withName("endpoint").withNamespace("test2").endMetadata().addNewSubset()
			.addNewAddress().withIp("ip2").withNewTargetRef().withUid("uid2")
			.endTargetRef().endAddress().addNewPort("http", 80, "TCP").endSubset()
			.build();

	List<Endpoints> endpointsList = new ArrayList<>();
	endpointsList.add(endPoints1);
	endpointsList.add(endpoints2);

	EndpointsList endpoints = new EndpointsList();
	endpoints.setItems(endpointsList);

	mockServer.expect().get()
			.withPath("/api/v1/endpoints?fieldSelector=metadata.name%3Dendpoint")
			.andReturn(200, endpoints).once();

	mockServer.expect().get().withPath("/api/v1/namespaces/test/endpoints/endpoint")
			.andReturn(200, endPoints1).once();

	mockServer.expect().get().withPath("/api/v1/namespaces/test2/endpoints/endpoint")
			.andReturn(200, endpoints2).once();

	Service service1 = new ServiceBuilder().withNewMetadata().withName("endpoint")
			.withNamespace("test").withLabels(new HashMap<String, String>() {
				{
					put("l", "v");
				}
			}).endMetadata().build();

	Service service2 = new ServiceBuilder().withNewMetadata().withName("endpoint")
			.withNamespace("test2").withLabels(new HashMap<String, String>() {
				{
					put("l", "v");
				}
			}).endMetadata().build();

	List<Service> servicesList = new ArrayList<>();
	servicesList.add(service1);
	servicesList.add(service2);

	ServiceList services = new ServiceList();
	services.setItems(servicesList);

	mockServer.expect().get()
			.withPath("/api/v1/services?fieldSelector=metadata.name%3Dendpoint")
			.andReturn(200, services).once();

	mockServer.expect().get().withPath("/api/v1/namespaces/test/services/endpoint")
			.andReturn(200, service1).always();

	mockServer.expect().get().withPath("/api/v1/namespaces/test2/services/endpoint")
			.andReturn(200, service2).always();

	final KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties();
	properties.setAllNamespaces(true);

	final DiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient,
			properties, KubernetesClient::services,
			new DefaultIsServicePortSecureResolver(properties));

	final List<ServiceInstance> instances = discoveryClient.getInstances("endpoint");

	assertThat(instances).hasSize(2);
	assertThat(instances).filteredOn(s -> s.getHost().equals("ip1") && !s.isSecure())
			.hasSize(1);
	assertThat(instances).filteredOn(s -> s.getHost().equals("ip2") && !s.isSecure())
			.hasSize(1);
	assertThat(instances).filteredOn(s -> s.getInstanceId().equals("uid1"))
			.hasSize(1);
	assertThat(instances).filteredOn(s -> s.getInstanceId().equals("uid2"))
			.hasSize(1);
}
 
Example #10
Source File: KubernetesReactiveDiscoveryClientTests.java    From spring-cloud-kubernetes with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldReturnFluxOfServicesAcrossAllNamespaces(
		@Client KubernetesClient kubernetesClient,
		@Server KubernetesServer kubernetesServer) {
	kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services")
			.andReturn(200,
					new ServiceListBuilder().addNewItem().withNewMetadata()
							.withName("existing-service")
							.withLabels(new HashMap<String, String>() {
								{
									put("label", "value");
								}
							}).endMetadata().endItem().build())
			.once();

	Endpoints endpoints = new EndpointsBuilder().withNewMetadata()
			.withName("endpoint").withNamespace("test").endMetadata().addNewSubset()
			.addNewAddress().withIp("ip1").withNewTargetRef().withUid("uid1")
			.endTargetRef().endAddress().addNewPort("http", 80, "TCP")
			.addNewPort("https", 443, "TCP").endSubset().build();

	EndpointsList endpointsList = new EndpointsList();
	endpointsList.setItems(singletonList(endpoints));

	kubernetesServer.expect().get().withPath(
			"/api/v1/endpoints?fieldSelector=metadata.name%3Dexisting-service")
			.andReturn(200, endpointsList).once();

	kubernetesServer.expect().get()
			.withPath("/api/v1/namespaces/test/services/existing-service")
			.andReturn(200,
					new ServiceBuilder().withNewMetadata()
							.withName("existing-service")
							.withLabels(new HashMap<String, String>() {
								{
									put("label", "value");
								}
							}).endMetadata().build())
			.once();

	KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties();
	properties.setAllNamespaces(true);
	ReactiveDiscoveryClient client = new KubernetesReactiveDiscoveryClient(
			kubernetesClient, properties, KubernetesClient::services);
	Flux<ServiceInstance> instances = client.getInstances("existing-service");
	StepVerifier.create(instances).expectNextCount(1).expectComplete().verify();
}
 
Example #11
Source File: EndpointOperator.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
@Override
protected MixedOperation<Endpoints, EndpointsList, DoneableEndpoints, Resource<Endpoints, DoneableEndpoints>> operation() {
    return client.endpoints();
}
 
Example #12
Source File: Endpoints.java    From vxms with Apache License 2.0 4 votes vote down vote up
public EndpointsList getEndpoints() {
  return labelValue != null && !labelValue.isEmpty() ?
      client.endpoints().inNamespace(namespace).withLabel(labelName, labelValue).list() :
      client.endpoints().inNamespace(namespace).withLabel(labelName).list();
}
 
Example #13
Source File: AutoAdaptableKubernetesClient.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
public MixedOperation<Endpoints, EndpointsList, DoneableEndpoints, Resource<Endpoints, DoneableEndpoints>> endpoints() {
  return delegate.endpoints();
}
 
Example #14
Source File: DefaultKubernetesClient.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
public MixedOperation<Endpoints, EndpointsList, DoneableEndpoints, Resource<Endpoints, DoneableEndpoints>> endpoints() {
  return new EndpointsOperationsImpl(httpClient, getConfiguration());
}
 
Example #15
Source File: ManagedKubernetesClient.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
public MixedOperation<Endpoints, EndpointsList, DoneableEndpoints, Resource<Endpoints, DoneableEndpoints>> endpoints() {
  return delegate.endpoints();
}
 
Example #16
Source File: KubernetesClient.java    From kubernetes-client with Apache License 2.0 2 votes vote down vote up
/**
 * API entrypoint for Endpoints with APIGroup core/v1
 *
 * @return MixedOperation object for doing operations for Endpoints
 */
MixedOperation<Endpoints, EndpointsList, DoneableEndpoints, Resource<Endpoints, DoneableEndpoints>> endpoints();