use of io.fabric8.kubernetes.api.model.networking.v1.IngressSpec in project devspaces-images by redhat-developer.
the class IngressesTest method createIngress.
private Ingress createIngress(IngressBackend backend) {
Ingress ingress = new Ingress();
ObjectMeta ingressMeta = new ObjectMeta();
ingressMeta.setName("ingressname");
ingress.setMetadata(ingressMeta);
IngressSpec ingressSpec = new IngressSpec();
IngressRule ingressRule = new IngressRule();
ingressRule.setHost("ingresshost");
ingressRule.setHttp(new HTTPIngressRuleValue(singletonList(new HTTPIngressPath(backend, null, null))));
ingressSpec.setRules(singletonList(ingressRule));
ingress.setSpec(ingressSpec);
return ingress;
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressSpec in project jkube by eclipse.
the class IngressEnricherTest method testCreateIngressFromXMLConfigWithConfiguredServiceName.
@Test
public void testCreateIngressFromXMLConfigWithConfiguredServiceName() {
// Given
ResourceConfig resourceConfig = ResourceConfig.builder().ingress(IngressConfig.builder().ingressRule(IngressRuleConfig.builder().host("foo.bar.com").path(IngressRulePathConfig.builder().pathType("ImplementationSpecific").path("/icons").serviceName("hello-k8s").servicePort(80).build()).build()).ingressRule(IngressRuleConfig.builder().host("*.foo.com").path(IngressRulePathConfig.builder().path("/icons-storage").pathType("Exact").resource(IngressRulePathResourceConfig.builder().apiGroup("k8s.example.com").kind("StorageBucket").name("icon-assets").build()).build()).build()).ingressTlsConfig(IngressTlsConfig.builder().host("https-example.foo.com").secretName("testsecret-tls").build()).build()).build();
// @formatter:off
new Expectations() {
{
// Enable creation of Ingress for Service of type LoadBalancer
context.getProperty(CREATE_EXTERNAL_URLS);
result = "true";
context.getConfiguration().getResource();
result = resourceConfig;
}
};
// @formatter:on
Service providedService = initTestService().build();
KubernetesListBuilder kubernetesListBuilder = new KubernetesListBuilder().addToItems(providedService);
// When
ingressEnricher.create(PlatformMode.kubernetes, kubernetesListBuilder);
// Then
assertThat(kubernetesListBuilder).extracting(KubernetesListBuilder::buildItems).asList().hasSize(2).element(1).asInstanceOf(InstanceOfAssertFactories.type(Ingress.class)).hasFieldOrPropertyWithValue("apiVersion", "networking.k8s.io/v1").hasFieldOrPropertyWithValue("metadata.name", providedService.getMetadata().getName()).extracting(Ingress::getSpec).satisfies(is -> assertThat(is).extracting("tls").asList().element(0).hasFieldOrPropertyWithValue("secretName", "testsecret-tls").extracting("hosts").asList().containsExactly("https-example.foo.com")).extracting(IngressSpec::getRules).satisfies(r -> assertThat(r).asList().element(0).hasFieldOrPropertyWithValue("host", "foo.bar.com").extracting("http.paths").asList().element(0).hasFieldOrPropertyWithValue("path", "/icons").hasFieldOrPropertyWithValue("pathType", "ImplementationSpecific").hasFieldOrPropertyWithValue("backend.service.name", "hello-k8s").hasFieldOrPropertyWithValue("backend.service.port.number", 80)).satisfies(r -> assertThat(r).asList().element(1).hasFieldOrPropertyWithValue("host", "*.foo.com").extracting("http.paths").asList().element(0).hasFieldOrPropertyWithValue("path", "/icons-storage").hasFieldOrPropertyWithValue("pathType", "Exact").hasFieldOrPropertyWithValue("backend.resource.apiGroup", "k8s.example.com").hasFieldOrPropertyWithValue("backend.resource.kind", "StorageBucket").hasFieldOrPropertyWithValue("backend.resource.name", "icon-assets"));
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressSpec in project quick by bakdata.
the class GatewayResourceLoaderTest method shouldCreateGatewayIngressWithHttpIngress.
@Test
void shouldCreateGatewayIngressWithHttpIngress() {
// given null host and ingress point
final Optional<String> host = Optional.empty();
final String ingressEntrypoint = "web";
final boolean useSsl = false;
final GatewayCreationData gatewayCreationData = new GatewayCreationData(GATEWAY_NAME, REPLICAS, TAG, null);
final DeploymentConfig customConfig = new DeploymentConfig(this.getDeploymentConfig().getDockerRegistry(), this.getDeploymentConfig().getDefaultImageTag(), this.getDeploymentConfig().getDefaultReplicas(), host, useSsl, ingressEntrypoint);
final GatewayResourceLoader customLoader = new GatewayResourceLoader(new KubernetesResources(), customConfig, TestUtil.newResourceConfig(), NAMESPACE);
final GatewayResources gatewayResources = customLoader.forCreation(gatewayCreationData, ResourcePrefix.GATEWAY);
final Optional<HasMetadata> hasMetadata = findResource(gatewayResources, ResourceKind.INGRESS);
final String expected = ResourcePrefix.GATEWAY.getPrefix() + GATEWAY_NAME;
assertThat(hasMetadata).isPresent().get(InstanceOfAssertFactories.type(Ingress.class)).satisfies(gatewayIngress -> {
assertThat(gatewayIngress.getMetadata()).hasFieldOrPropertyWithValue("name", expected).extracting(ObjectMeta::getAnnotations, MAP).containsExactlyInAnyOrderEntriesOf(Map.of("kubernetes.io/ingress.class", "traefik", "traefik.ingress.kubernetes.io/router.middlewares", String.format("%s-%s@kubernetescrd", "test", expected), "traefik.ingress.kubernetes.io/router.entrypoints", "web", "traefik.ingress.kubernetes.io/router.tls", "false"));
final IngressSpec ingressSpec = gatewayIngress.getSpec();
assertThat(ingressSpec).isNotNull();
assertThat(ingressSpec.getRules()).isNotNull().hasSize(1).first().satisfies(rule -> assertThat(rule.getHost()).isNull());
});
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressSpec in project quick by bakdata.
the class GatewayResourceLoaderTest method shouldCreateGatewayIngress.
@Test
void shouldCreateGatewayIngress() {
final GatewayCreationData gatewayCreationData = new GatewayCreationData(GATEWAY_NAME, REPLICAS, TAG, null);
final GatewayResources gatewayResources = this.loader.forCreation(gatewayCreationData, ResourcePrefix.GATEWAY);
final Optional<HasMetadata> hasMetadata = findResource(gatewayResources, ResourceKind.INGRESS);
final String expected = ResourcePrefix.GATEWAY.getPrefix() + GATEWAY_NAME;
assertThat(hasMetadata).isPresent().get(InstanceOfAssertFactories.type(Ingress.class)).satisfies(gatewayIngress -> {
assertThat(gatewayIngress.getMetadata()).hasFieldOrPropertyWithValue("name", expected).extracting(ObjectMeta::getAnnotations, MAP).containsExactlyInAnyOrderEntriesOf(Map.of("kubernetes.io/ingress.class", "traefik", "traefik.ingress.kubernetes.io/router.middlewares", String.format("%s-%s@kubernetescrd", "test", expected), "traefik.ingress.kubernetes.io/router.entrypoints", "websecure", "traefik.ingress.kubernetes.io/router.tls", "true"));
final IngressSpec ingressSpec = gatewayIngress.getSpec();
assertThat(ingressSpec).isNotNull();
assertThat(ingressSpec.getRules()).isNotNull().hasSize(1).first().satisfies(rule -> assertThat(rule.getHost()).isEqualTo("quick.host.io")).extracting(IngressRule::getHttp).isNotNull().extracting(HTTPIngressRuleValue::getPaths, InstanceOfAssertFactories.list(HTTPIngressPath.class)).isNotNull().hasSize(1).first().hasFieldOrPropertyWithValue("path", "/gateway/" + GATEWAY_NAME).hasFieldOrPropertyWithValue("pathType", "Prefix").extracting(path -> path.getBackend().getService()).isNotNull().hasFieldOrPropertyWithValue("name", expected).extracting(IngressServiceBackend::getPort).hasFieldOrPropertyWithValue("number", KubernetesResources.SERVICE_PORT);
});
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressSpec in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class KubernetesNetworkingService method buildIngress.
private Ingress buildIngress(BridgeIngress bridgeIngress, Service service) {
Ingress ingress = templateProvider.loadBridgeIngressKubernetesIngressTemplate(bridgeIngress);
IngressBackend ingressBackend = new IngressBackendBuilder().withService(new IngressServiceBackendBuilder().withName(service.getMetadata().getName()).withPort(new ServiceBackendPortBuilder().withNumber(service.getSpec().getPorts().get(0).getPort()).build()).build()).build();
HTTPIngressPath httpIngressPath = new HTTPIngressPathBuilder().withBackend(ingressBackend).withPath("/" + service.getMetadata().getName() + PATH_REGEX).withPathType("Prefix").build();
IngressRule ingressRule = new IngressRuleBuilder().withHttp(new HTTPIngressRuleValueBuilder().withPaths(httpIngressPath).build()).build();
IngressSpec ingressSpec = new IngressSpecBuilder().withRules(ingressRule).build();
ingress.setSpec(ingressSpec);
return ingress;
}
Aggregations