use of io.fabric8.maven.plugin.enricher.EnricherManager in project fabric8-maven-plugin by fabric8io.
the class ResourceMojo method generateAppResources.
private KubernetesListBuilder generateAppResources(List<ImageConfiguration> images, EnricherManager enricherManager) throws IOException, MojoExecutionException {
Path composeFilePath = checkComposeConfig();
ComposeService composeUtil = new ComposeService(komposeBinDir, composeFilePath, log);
try {
File[] resourceFiles = KubernetesResourceUtil.listResourceFragments(resourceDir);
File[] composeResourceFiles = composeUtil.convertToKubeFragments();
File[] allResources = ArrayUtils.addAll(resourceFiles, composeResourceFiles);
KubernetesListBuilder builder;
// Add resource files found in the fabric8 directory
if (allResources != null && allResources.length > 0) {
if (resourceFiles != null && resourceFiles.length > 0) {
log.info("using resource templates from %s", resourceDir);
}
if (composeResourceFiles != null && composeResourceFiles.length > 0) {
log.info("using resource templates generated from compose file");
}
builder = readResourceFragments(allResources);
} else {
builder = new KubernetesListBuilder();
}
// Add locally configured objects
if (resources != null) {
// TODO: Allow also support resources to be specified via XML
addConfiguredResources(builder, images);
}
// Create default resources for app resources only
enricherManager.createDefaultResources(builder);
// Enrich descriptors
enricherManager.enrich(builder);
return builder;
} catch (ConstraintViolationException e) {
String message = ValidationUtil.createValidationMessage(e.getConstraintViolations());
log.error("ConstraintViolationException: %s", message);
throw new MojoExecutionException(message, e);
} catch (Fabric8ServiceException e) {
throw new MojoExecutionException(e.getMessage(), e);
} finally {
composeUtil.cleanComposeResources();
}
}
use of io.fabric8.maven.plugin.enricher.EnricherManager in project fabric8-maven-plugin by fabric8io.
the class ResourceMojo method generateResources.
private KubernetesList generateResources(List<ImageConfiguration> images) throws IOException, MojoExecutionException {
// Manager for calling enrichers.
openshiftDependencyResources = new OpenShiftDependencyResources(log);
loadOpenShiftOverrideResources();
EnricherContext.Builder ctxBuilder = new EnricherContext.Builder().project(project).session(session).goalFinder(goalFinder).config(extractEnricherConfig()).resources(resources).images(resolvedImages).log(log).useProjectClasspath(useProjectClasspath).openshiftDependencyResources(openshiftDependencyResources);
if (resources != null) {
ctxBuilder.namespace(resources.getNamespace());
}
EnricherManager enricherManager = new EnricherManager(resources, ctxBuilder.build());
// Generate all resources from the main resource diretory, configuration and enrich them accordingly
KubernetesListBuilder builder = generateAppResources(images, enricherManager);
// Add resources found in subdirectories of resourceDir, with a certain profile
// applied
addProfiledResourcesFromSubirectories(builder, resourceDir, enricherManager);
return builder.build();
}
use of io.fabric8.maven.plugin.enricher.EnricherManager in project fabric8-maven-plugin by fabric8io.
the class EnricherManagerTest method enrichSimple.
@Test
public void enrichSimple() {
new Expectations() {
{
context.getConfig();
result = new ProcessorConfig(Arrays.asList("fmp-project"), null, new HashMap<String, TreeMap>());
}
};
EnricherManager manager = new EnricherManager(null, context);
KubernetesListBuilder builder = new KubernetesListBuilder();
builder.addNewReplicaSetItem().withNewSpec().withNewTemplate().withNewSpec().addNewContainer().withName("test").withImage("busybox").endContainer().endSpec().endTemplate().endSpec().endReplicaSetItem();
manager.enrich(builder);
KubernetesList list = builder.build();
assertEquals(1, list.getItems().size());
ReplicaSet pod = (ReplicaSet) list.getItems().get(0);
ObjectMeta metadata = pod.getMetadata();
assertNotNull(metadata);
Map<String, String> labels = metadata.getLabels();
assertNotNull(labels);
assertEquals("fabric8", labels.get("provider"));
}
use of io.fabric8.maven.plugin.enricher.EnricherManager in project fabric8-maven-plugin by fabric8io.
the class EnricherManagerTest method createDefaultResources.
@Test
public void createDefaultResources() {
new Expectations() {
{
context.getConfig();
result = new ProcessorConfig(Arrays.asList("fmp-controller"), null, null);
context.getImages();
result = new ImageConfiguration.Builder().alias("img1").name("img1").build();
}
};
EnricherManager manager = new EnricherManager(null, context);
KubernetesListBuilder builder = new KubernetesListBuilder();
manager.createDefaultResources(builder);
assertTrue(builder.build().getItems().size() > 0);
}
Aggregations