use of io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder in project flink-kubernetes-operator by apache.
the class IngressUtils method updateIngressRules.
public static void updateIngressRules(FlinkDeployment flinkDeployment, Configuration effectiveConfig, String operatorNamespace, KubernetesClient client, boolean remove) {
if (flinkDeployment.getSpec().getIngressDomain() != null) {
final IngressRule ingressRule = fromDeployment(flinkDeployment, effectiveConfig);
getIngress(operatorNamespace, client).ifPresent(ingress -> {
Ingress updated;
if (remove) {
updated = new IngressBuilder(ingress).editSpec().removeFromRules(ingressRule).endSpec().build();
} else {
updated = new IngressBuilder(ingress).editSpec().addToRules(ingressRule).endSpec().build();
}
LOG.info("Updating ingress rules {}", ingress);
client.resourceList(updated).inNamespace(operatorNamespace).createOrReplace();
});
}
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder in project jkube by eclipse.
the class ApplyServiceTest method testApplyToMultipleNamespacesOverriddenWhenNamespaceConfigured.
@Test
public void testApplyToMultipleNamespacesOverriddenWhenNamespaceConfigured() throws InterruptedException {
// Given
ConfigMap configMap = new ConfigMapBuilder().withNewMetadata().withName("cm1").withNamespace("default").endMetadata().build();
Ingress ingress = new IngressBuilder().withNewMetadata().withName("ing1").withNamespace("default").endMetadata().build();
ServiceAccount serviceAccount = new ServiceAccountBuilder().withNewMetadata().withName("default").endMetadata().build();
List<HasMetadata> entities = new ArrayList<>();
entities.add(configMap);
entities.add(serviceAccount);
entities.add(ingress);
WebServerEventCollector collector = new WebServerEventCollector();
mockServer.expect().post().withPath("/api/v1/namespaces/default/configmaps").andReply(collector.record("configmap-default-ns-create").andReturn(HTTP_OK, configMap)).once();
mockServer.expect().post().withPath("/apis/networking.k8s.io/v1/namespaces/default/ingresses").andReply(collector.record("ingress-default-ns-create").andReturn(HTTP_OK, ingress)).once();
mockServer.expect().post().withPath("/api/v1/namespaces/default/serviceaccounts").andReply(collector.record("serviceaccount-default-ns-create").andReturn(HTTP_OK, serviceAccount)).once();
// When
applyService.applyEntities(null, entities, log, 5);
// Then
collector.assertEventsRecordedInOrder("configmap-default-ns-create", "serviceaccount-default-ns-create", "ingress-default-ns-create");
assertEquals(5, mockServer.getOpenShiftMockServer().getRequestCount());
applyService.setFallbackNamespace(null);
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder in project jkube by eclipse.
the class ExtensionsV1Beta1IngressConverterTest method testConvert.
@Test
public void testConvert() {
// Given
io.fabric8.kubernetes.api.model.networking.v1.Ingress networkV1Ingress = new IngressBuilder().withNewMetadata().withName("test-ing").endMetadata().withNewSpec().withIngressClassName("external-lb").addNewTl().withHosts("test-svc.org.eclipse.jkube").withSecretName("test-jkube-ingress").endTl().addNewRule().withHost("test-svc.org.eclipse.jkube").withNewHttp().addNewPath().withPath("/testpath").withPathType("Prefix").withNewBackend().withNewService().withName("test").withNewPort().withNumber(80).endPort().endService().withNewResource("k8s.example.com", "StorageBucket", "icon-assets").endBackend().endPath().endHttp().endRule().endSpec().build();
// When
Ingress ingress = ExtensionsV1beta1IngressConverter.convert(networkV1Ingress);
// Then
assertThat(ingress).hasFieldOrPropertyWithValue("metadata.name", "test-ing").hasFieldOrPropertyWithValue("spec.ingressClassName", "external-lb").satisfies(ir -> assertThat(ir.getSpec().getTls()).asList().hasSize(1).element(0).hasFieldOrPropertyWithValue("secretName", "test-jkube-ingress").extracting("hosts").asList().hasSize(1).element(0).isEqualTo("test-svc.org.eclipse.jkube")).extracting("spec.rules").asList().hasSize(1).element(0).hasFieldOrPropertyWithValue("host", "test-svc.org.eclipse.jkube").extracting("http.paths").asList().element(0).hasFieldOrPropertyWithValue("path", "/testpath").hasFieldOrPropertyWithValue("pathType", "Prefix").hasFieldOrPropertyWithValue("backend.serviceName", "test").hasFieldOrPropertyWithValue("backend.servicePort", new IntOrString(80)).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.IngressBuilder in project jkube by eclipse.
the class ExtensionsV1Beta1IngressConverterTest method testConvertWithNullSpec.
@Test
public void testConvertWithNullSpec() {
// Given
final io.fabric8.kubernetes.api.model.networking.v1.Ingress from = new IngressBuilder().withNewMetadata().withName("ingress").endMetadata().build();
// When
final Ingress result = ExtensionsV1beta1IngressConverter.convert(from);
// Then
assertThat(result).hasFieldOrPropertyWithValue("spec", null).hasFieldOrPropertyWithValue("metadata.name", "ingress");
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder in project jkube by eclipse.
the class NetworkingV1IngressGenerator method generate.
protected static Ingress generate(KubernetesListBuilder listBuilder, ServiceBuilder serviceBuilder, String routeDomainPostfix, String host, List<IngressRuleConfig> ingressRuleConfigs, List<IngressTlsConfig> ingressTlsConfigs, KitLogger log) {
ObjectMeta serviceMetadata = serviceBuilder.buildMetadata();
if (serviceMetadata == null) {
log.info("No Metadata for service! ");
}
if (isExposedService(serviceMetadata) && shouldCreateExternalURLForService(serviceBuilder, log)) {
Objects.requireNonNull(serviceMetadata);
String serviceName = serviceMetadata.getName();
if (!hasIngress(listBuilder, serviceName)) {
Integer servicePort = getServicePort(serviceBuilder);
if (servicePort != null) {
return new IngressBuilder().withMetadata(getIngressMetadata(serviceMetadata)).withSpec(getIngressSpec(routeDomainPostfix, host, serviceName, servicePort, ingressRuleConfigs, ingressTlsConfigs)).build();
}
}
}
return null;
}
Aggregations