use of io.fabric8.knative.serving.v1.Service in project fabric8-maven-plugin by fabric8io.
the class ExposeEnricher method enrichService.
private void enrichService(Service service) {
if (hasWebPort(service)) {
ObjectMeta metadata = service.getMetadata();
if (metadata == null) {
metadata = new ObjectMeta();
service.setMetadata(metadata);
}
Map<String, String> labels = getOrCreateLabels(service);
if (!labels.containsKey(EXPOSE_LABEL)) {
labels.put(EXPOSE_LABEL, "true");
log.verbose("Adding Service label '%s:true' on service %s" + " so that it is exposed by the exposecontroller microservice." + " To disable use the maven argument: '-Dfabric8.profile=internal-microservice'", EXPOSE_LABEL, KubernetesHelper.getName(service));
}
}
}
use of io.fabric8.knative.serving.v1.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.knative.serving.v1.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.knative.serving.v1.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.knative.serving.v1.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;
}
}
Aggregations