use of io.fabric8.patch.Service in project fabric8-maven-plugin by fabric8io.
the class KubernetesResourceUtilTest method readWholeDir.
@Test
public void readWholeDir() throws IOException {
ResourceVersioning v = new ResourceVersioning().withCoreVersion("v2").withExtensionsVersion("extensions/v2");
KubernetesListBuilder builder = KubernetesResourceUtil.readResourceFragmentsFrom(v, "pong", new File(fabric8Dir, "read-dir").listFiles());
KubernetesList list = builder.build();
assertEquals(2, list.getItems().size());
for (HasMetadata item : list.getItems()) {
assertTrue("Service".equals(item.getKind()) || "ReplicationController".equals(item.getKind()));
assertEquals("pong", item.getMetadata().getName());
assertEquals("v2", item.getApiVersion());
}
}
use of io.fabric8.patch.Service in project fabric8-maven-plugin by fabric8io.
the class OpenshiftBuildService method build.
@Override
public void build(ImageConfiguration imageConfig) throws Fabric8ServiceException {
try {
ImageName imageName = new ImageName(imageConfig.getName());
File dockerTar = createBuildArchive(imageConfig);
KubernetesListBuilder builder = new KubernetesListBuilder();
// Check for buildconfig / imagestream and create them if necessary
String buildName = updateOrCreateBuildConfig(config, client, builder, imageConfig);
checkOrCreateImageStream(config, client, builder, getImageStreamName(imageName));
applyResourceObjects(config, client, builder);
// Start the actual build
Build build = startBuild(client, dockerTar, buildName);
// Wait until the build finishes
waitForOpenShiftBuildToComplete(client, build);
// Create a file with generated image streams
addImageStreamToFile(getImageStreamFile(config), imageName, client);
} catch (Fabric8ServiceException e) {
throw e;
} catch (Exception ex) {
throw new Fabric8ServiceException("Unable to build the image using the OpenShift build service", ex);
}
}
use of io.fabric8.patch.Service in project fabric8-maven-plugin by fabric8io.
the class ServiceHandler method getServices.
public List<Service> getServices(List<ServiceConfig> services) {
ArrayList<Service> ret = new ArrayList<>();
for (ServiceConfig service : services) {
ServiceBuilder serviceBuilder = new ServiceBuilder().withNewMetadata().withName(service.getName()).withAnnotations(getAnnotations(service)).withLabels(getLabels(service)).endMetadata();
ServiceFluent.SpecNested<ServiceBuilder> serviceSpecBuilder = serviceBuilder.withNewSpec();
List<ServicePort> servicePorts = new ArrayList<>();
for (ServiceConfig.Port port : service.getPorts()) {
ServicePort servicePort = new ServicePortBuilder().withName(port.getName()).withProtocol(port.getProtocol() != null ? port.getProtocol().name() : "TCP").withTargetPort(new IntOrString(port.getTargetPort())).withPort(port.getPort()).withNodePort(port.getNodePort()).build();
servicePorts.add(servicePort);
}
if (!servicePorts.isEmpty()) {
serviceSpecBuilder.withPorts(servicePorts);
}
if (service.isHeadless()) {
serviceSpecBuilder.withClusterIP("None");
}
if (!Strings.isNullOrBlank(service.getType())) {
serviceSpecBuilder.withType(service.getType());
}
serviceSpecBuilder.endSpec();
if (service.isHeadless() || !servicePorts.isEmpty()) {
ret.add(serviceBuilder.build());
}
}
return ret;
}
use of io.fabric8.patch.Service in project fabric8-maven-plugin by fabric8io.
the class ApplyMojo method shouldCreateExternalURLForService.
/**
* Should we try to create an external URL for the given service?
* <p/>
* By default lets ignore the kubernetes services and any service which does not expose ports 80 and 443
*
* @return true if we should create an OpenShift Route for this service.
*/
private boolean shouldCreateExternalURLForService(Service service, String id) {
if ("kubernetes".equals(id) || "kubernetes-ro".equals(id)) {
return false;
}
Set<Integer> ports = KubernetesHelper.getPorts(service);
log.debug("Service " + id + " has ports: " + ports);
if (ports.size() == 1) {
String type = null;
ServiceSpec spec = service.getSpec();
if (spec != null) {
type = spec.getType();
if (Objects.equals(type, "LoadBalancer")) {
return true;
}
}
log.info("Not generating route for service " + id + " type is not LoadBalancer: " + type);
return false;
} else {
log.info("Not generating route for service " + id + " as only single port services are supported. Has ports: " + ports);
return false;
}
}
use of io.fabric8.patch.Service in project fabric8-maven-plugin by fabric8io.
the class ApplyMojo method createRouteForService.
private Route createRouteForService(String routeDomainPostfix, String namespace, Service service) {
Route route = null;
String id = KubernetesHelper.getName(service);
if (Strings.isNotBlank(id) && hasExactlyOneService(service, id)) {
route = new Route();
String routeId = id;
KubernetesHelper.setName(route, namespace, routeId);
RouteSpec routeSpec = new RouteSpec();
RouteTargetReference objectRef = new RouteTargetReferenceBuilder().withName(id).build();
// objectRef.setNamespace(namespace);
routeSpec.setTo(objectRef);
if (!Strings.isNullOrBlank(routeDomainPostfix)) {
String host = Strings.stripSuffix(Strings.stripSuffix(id, "-service"), ".");
routeSpec.setHost(host + "." + Strings.stripPrefix(routeDomainPostfix, "."));
} else {
routeSpec.setHost("");
}
route.setSpec(routeSpec);
String json;
try {
json = KubernetesHelper.toJson(route);
} catch (JsonProcessingException e) {
json = e.getMessage() + ". object: " + route;
}
log.debug("Created route: " + json);
}
return route;
}
Aggregations