use of io.fabric8.kubernetes.api.model.ServiceSpec in project fabric8-maven-plugin by fabric8io.
the class ApplyMojo method createIngressForService.
private Ingress createIngressForService(String routeDomainPostfix, String namespace, Service service) {
Ingress ingress = null;
String serviceName = KubernetesHelper.getName(service);
ServiceSpec serviceSpec = service.getSpec();
if (serviceSpec != null && Strings.isNotBlank(serviceName) && shouldCreateExternalURLForService(service, serviceName)) {
String ingressId = serviceName;
String host = "";
if (Strings.isNotBlank(routeDomainPostfix)) {
host = serviceName + "." + namespace + "." + Strings.stripPrefix(routeDomainPostfix, ".");
}
List<HTTPIngressPath> paths = new ArrayList<>();
List<ServicePort> ports = serviceSpec.getPorts();
if (ports != null) {
for (ServicePort port : ports) {
Integer portNumber = port.getPort();
if (portNumber != null) {
HTTPIngressPath path = new HTTPIngressPathBuilder().withNewBackend().withServiceName(serviceName).withServicePort(createIntOrString(portNumber.intValue())).endBackend().build();
paths.add(path);
}
}
}
if (paths.isEmpty()) {
return ingress;
}
ingress = new IngressBuilder().withNewMetadata().withName(ingressId).withNamespace(namespace).endMetadata().withNewSpec().addNewRule().withHost(host).withNewHttp().withPaths(paths).endHttp().endRule().endSpec().build();
String json;
try {
json = KubernetesHelper.toJson(ingress);
} catch (JsonProcessingException e) {
json = e.getMessage() + ". object: " + ingress;
}
log.debug("Created ingress: " + json);
}
return ingress;
}
use of io.fabric8.kubernetes.api.model.ServiceSpec in project fabric8 by fabric8io.
the class KubernetesAssert method getServiceSpec.
protected ServiceSpec getServiceSpec(String serviceId, String namespace) {
Service service = getService(serviceId, namespace);
ServiceSpec spec = service.getSpec();
assertThat(spec).isNotNull();
return spec;
}
use of io.fabric8.kubernetes.api.model.ServiceSpec in project fabric8 by fabric8io.
the class KubernetesAssert method hasServicePort.
/**
* Asserts that the service can be found for the given name and has a port of the given value
*/
public void hasServicePort(String serviceId, int port) {
ServiceSpec spec = getServiceSpec(serviceId, namespace());
boolean found = false;
List<ServicePort> ports = spec.getPorts();
List<Integer> portNumbers = new ArrayList<>();
if (ports != null) {
for (ServicePort servicePort : ports) {
Integer aPort = servicePort.getPort();
if (aPort != null) {
if (aPort == port) {
found = true;
break;
} else {
portNumbers.add(aPort);
}
}
}
}
assertThat(found).describedAs("No port found for " + port + " but found ports: " + portNumbers).isTrue();
}
use of io.fabric8.kubernetes.api.model.ServiceSpec in project fabric8 by fabric8io.
the class ServicePodsAssert method pods.
@Override
public PodSelectionAssert pods() {
spec().isNotNull().selector().isNotNull();
ServiceSpec spec = this.actual.getSpec();
int replicas = 1;
LabelSelector selector = null;
Map<String, String> matchLabels = spec.getSelector();
List<LabelSelectorRequirement> matchExpressions = selector.getMatchExpressions();
return new PodSelectionAssert(client, replicas, matchLabels, matchExpressions, "Service " + KubernetesHelper.getName(actual));
}
use of io.fabric8.kubernetes.api.model.ServiceSpec in project fabric8-maven-plugin by fabric8io.
the class OpenShiftRouteEnricher method createRoutePort.
private RoutePort createRoutePort(ServiceBuilder serviceBuilder) {
RoutePort routePort = null;
ServiceSpec spec = serviceBuilder.getSpec();
if (spec != null) {
List<ServicePort> ports = spec.getPorts();
if (ports != null && ports.size() > 0) {
ServicePort servicePort = ports.get(0);
if (servicePort != null) {
IntOrString targetPort = servicePort.getTargetPort();
if (targetPort != null) {
routePort = new RoutePort();
routePort.setTargetPort(targetPort);
}
}
}
}
return routePort;
}
Aggregations