io.fabric8.kubernetes.client.server.mock.KubernetesServer Java Examples

The following examples show how to use io.fabric8.kubernetes.client.server.mock.KubernetesServer. 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: KubernetesReactiveDiscoveryClientTests.java    From spring-cloud-kubernetes with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldReturnEmptyFluxWhenServiceHasNoSubsets(
		@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();

	KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties();
	ReactiveDiscoveryClient client = new KubernetesReactiveDiscoveryClient(
			kubernetesClient, properties, KubernetesClient::services);
	Flux<ServiceInstance> instances = client.getInstances("existing-service");
	StepVerifier.create(instances).expectNextCount(0).expectComplete().verify();
}
 
Example #2
Source File: KubernetesExtension.java    From spring-cloud-kubernetes with Apache License 2.0 5 votes vote down vote up
@Override
public boolean supportsParameter(ParameterContext parameterContext,
		ExtensionContext context) {
	return (parameterContext.getParameter().isAnnotationPresent(Server.class)
			&& KubernetesServer.class
					.isAssignableFrom(parameterContext.getParameter().getType()))
			|| (parameterContext.getParameter().isAnnotationPresent(Client.class)
					&& KubernetesClient.class.isAssignableFrom(
							parameterContext.getParameter().getType()));
}
 
Example #3
Source File: MultipleConfigMapsTests.java    From spring-cloud-kubernetes with Apache License 2.0 5 votes vote down vote up
private static void createConfigmap(KubernetesServer server, String configMapName,
		String namespace, Map<String, String> data) {

	server.expect()
			.withPath(String.format("/api/v1/namespaces/%s/configmaps/%s", namespace,
					configMapName))
			.andReturn(200, new ConfigMapBuilder().withNewMetadata()
					.withName(configMapName).endMetadata().addToData(data).build())
			.always();
}
 
Example #4
Source File: MockKubernetesServerSupport.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
public KubernetesServer getServer() {
    return server;
}
 
Example #5
Source File: MockKubernetesServerSupport.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
/**
 * Override to setup a different kind of server
 */
protected final void initializeServer(final boolean crudMode) {
    this.server = new KubernetesServer(false, crudMode);
}
 
Example #6
Source File: KubernetesReactiveDiscoveryClientTests.java    From spring-cloud-kubernetes with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldReturnFlux(@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").endSubset()
			.build();

	kubernetesServer.expect().get()
			.withPath("/api/v1/namespaces/test/endpoints/existing-service")
			.andReturn(200, endPoints).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();
	ReactiveDiscoveryClient client = new KubernetesReactiveDiscoveryClient(
			kubernetesClient, properties, KubernetesClient::services);
	Flux<ServiceInstance> instances = client.getInstances("existing-service");
	StepVerifier.create(instances).expectNextCount(1).expectComplete().verify();
}
 
Example #7
Source File: KubernetesReactiveDiscoveryClientTests.java    From spring-cloud-kubernetes with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldReturnFluxWithPrefixedMetadata(
		@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").endSubset()
			.build();

	kubernetesServer.expect().get()
			.withPath("/api/v1/namespaces/test/endpoints/existing-service")
			.andReturn(200, endPoints).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.getMetadata().setAnnotationsPrefix("annotation.");
	properties.getMetadata().setLabelsPrefix("label.");
	properties.getMetadata().setPortsPrefix("port.");
	ReactiveDiscoveryClient client = new KubernetesReactiveDiscoveryClient(
			kubernetesClient, properties, KubernetesClient::services);
	Flux<ServiceInstance> instances = client.getInstances("existing-service");
	StepVerifier.create(instances).expectNextCount(1).expectComplete().verify();
}
 
Example #8
Source File: KubernetesReactiveDiscoveryClientTests.java    From spring-cloud-kubernetes with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldReturnFluxWhenServiceHasMultiplePortsAndPrimaryPortNameIsSet(
		@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();

	kubernetesServer.expect().get()
			.withPath("/api/v1/namespaces/test/endpoints/existing-service")
			.andReturn(200, endPoints).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.setPrimaryPortName("https");
	ReactiveDiscoveryClient client = new KubernetesReactiveDiscoveryClient(
			kubernetesClient, properties, KubernetesClient::services);
	Flux<ServiceInstance> instances = client.getInstances("existing-service");
	StepVerifier.create(instances).expectNextCount(1).expectComplete().verify();
}
 
Example #9
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();
}