use of io.fabric8.openshift.api.model.Project in project fabric8-maven-plugin by fabric8io.
the class ApplyMojo method overrideTemplateParameters.
/**
* Before applying the given template lets allow template parameters to be overridden via the maven
* properties - or optionally - via the command line if in interactive mode.
*/
protected static void overrideTemplateParameters(Template template, MavenProject project, Logger log) {
List<io.fabric8.openshift.api.model.Parameter> parameters = template.getParameters();
if (parameters != null && project != null) {
Properties properties = getProjectAndFabric8Properties(project);
boolean missingProperty = false;
for (io.fabric8.openshift.api.model.Parameter parameter : parameters) {
String parameterName = parameter.getName();
String name = "fabric8.apply." + parameterName;
String propertyValue = properties.getProperty(name);
if (propertyValue != null) {
log.info("Overriding template parameter " + name + " with value: " + propertyValue);
parameter.setValue(propertyValue);
} else {
missingProperty = true;
log.info("No property defined for template parameter: " + name);
}
}
if (missingProperty) {
log.debug("Current properties " + new TreeSet<>(properties.keySet()));
}
}
}
use of io.fabric8.openshift.api.model.Project in project fabric8-maven-plugin by fabric8io.
the class ApplyMojo method executeInternal.
public void executeInternal() throws MojoExecutionException, MojoFailureException {
clusterAccess = new ClusterAccess(namespace);
try {
KubernetesClient kubernetes = clusterAccess.createDefaultClient(log);
URL masterUrl = kubernetes.getMasterUrl();
File manifest;
if (KubernetesHelper.isOpenShift(kubernetes)) {
manifest = openshiftManifest;
} else {
manifest = kubernetesManifest;
}
if (!Files.isFile(manifest)) {
if (failOnNoKubernetesJson) {
throw new MojoFailureException("No such generated manifest file: " + manifest);
} else {
log.warn("No such generated manifest file %s for this project so ignoring", manifest);
return;
}
}
String clusterKind = "Kubernetes";
if (KubernetesHelper.isOpenShift(kubernetes)) {
clusterKind = "OpenShift";
}
KubernetesResourceUtil.validateKubernetesMasterUrl(masterUrl);
log.info("Using %s at %s in namespace %s with manifest %s ", clusterKind, masterUrl, clusterAccess.getNamespace(), manifest);
Controller controller = createController();
controller.setAllowCreate(createNewResources);
controller.setServicesOnlyMode(servicesOnly);
controller.setIgnoreServiceMode(ignoreServices);
controller.setLogJsonDir(jsonLogDir);
controller.setBasedir(getRootProjectFolder());
controller.setIgnoreRunningOAuthClients(ignoreRunningOAuthClients);
controller.setProcessTemplatesLocally(processTemplatesLocally);
controller.setDeletePodsOnReplicationControllerUpdate(deletePodsOnReplicationControllerUpdate);
controller.setRollingUpgrade(rollingUpgrades);
controller.setRollingUpgradePreserveScale(isRollingUpgradePreserveScale());
boolean openShift = KubernetesHelper.isOpenShift(kubernetes);
if (openShift) {
getLog().info("OpenShift platform detected");
} else {
disableOpenShiftFeatures(controller);
}
// lets check we have created the namespace
String namespace = clusterAccess.getNamespace();
controller.applyNamespace(namespace);
controller.setNamespace(namespace);
Set<HasMetadata> entities = KubernetesResourceUtil.loadResources(manifest);
if (createExternalUrls) {
if (controller.getOpenShiftClientOrNull() != null) {
createRoutes(controller, entities);
} else {
createIngress(controller, kubernetes, entities);
}
}
applyEntities(controller, kubernetes, namespace, manifest.getName(), entities);
} catch (KubernetesClientException e) {
KubernetesResourceUtil.handleKubernetesClientException(e, this.log);
} catch (MojoExecutionException e) {
throw e;
} catch (Exception e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
use of io.fabric8.openshift.api.model.Project in project fabric8-maven-plugin by fabric8io.
the class PushMojo method customizeConfig.
/**
* Customization hook called by the base plugin.
*
* @param configs configuration to customize
* @return the configuration customized by our generators.
*/
@Override
public List<ImageConfiguration> customizeConfig(List<ImageConfiguration> configs) {
try {
ProcessorConfig generatorConfig = ProfileUtil.blendProfileWithConfiguration(ProfileUtil.GENERATOR_CONFIG, profile, resourceDir, generator);
GeneratorContext ctx = new GeneratorContext.Builder().config(generatorConfig).project(project).session(session).goalFinder(goalFinder).goalName("fabric8:push").logger(log).mode(mode).strategy(buildStrategy).useProjectClasspath(false).build();
return GeneratorManager.generate(configs, ctx, true);
} catch (Exception e) {
throw new IllegalArgumentException("Cannot extract generator config: " + e, e);
}
}
use of io.fabric8.openshift.api.model.Project in project fabric8-maven-plugin by fabric8io.
the class ResourceMojo method getResolvedImages.
private List<ImageConfiguration> getResolvedImages(List<ImageConfiguration> images, final Logger log) throws MojoExecutionException {
List<ImageConfiguration> ret;
ret = ConfigHelper.resolveImages(log, images, new ConfigHelper.Resolver() {
@Override
public List<ImageConfiguration> resolve(ImageConfiguration image) {
return imageConfigResolver.resolve(image, project, session);
}
}, // no filter on image name yet (TODO: Maybe add this, too ?)
null, new ConfigHelper.Customizer() {
@Override
public List<ImageConfiguration> customizeConfig(List<ImageConfiguration> configs) {
try {
GeneratorContext ctx = new GeneratorContext.Builder().config(extractGeneratorConfig()).project(project).session(session).goalFinder(goalFinder).goalName("fabric8:resource").logger(log).mode(mode).strategy(buildStrategy).useProjectClasspath(useProjectClasspath).build();
return GeneratorManager.generate(configs, ctx, true);
} catch (Exception e) {
throw new IllegalArgumentException("Cannot extract generator: " + e, e);
}
}
});
Date now = getBuildReferenceDate();
storeReferenceDateInPluginContext(now);
String minimalApiVersion = ConfigHelper.initAndValidate(ret, null, /* no minimal api version */
new ImageNameFormatter(project, now), log);
return ret;
}
use of io.fabric8.openshift.api.model.Project 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();
}
Aggregations