diff --git a/CHANGELOG.md b/CHANGELOG.md index f756bd4a5e..ac49077d5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ After this we will switch probably to real [Semantic Versioning 2.0.0](http://se * Updated custom-enricher sample * Fixed image config in thorntail sample * Fix #1697: NullpointerException when trying to apply custom resources +* Fix #1720: Should be able to add custom route, even if fabric8.openshift.generateRoute=false * Fix #1696: fmp not setting imagestreams resourceVersion properly. * Fix #1689: HELM mode does not support parameters without value * Fix #1676: Support for latest kubernetes client diff --git a/enricher/api/src/main/java/io/fabric8/maven/enricher/api/BaseEnricher.java b/enricher/api/src/main/java/io/fabric8/maven/enricher/api/BaseEnricher.java index 1158d5c7f5..d6322527ed 100644 --- a/enricher/api/src/main/java/io/fabric8/maven/enricher/api/BaseEnricher.java +++ b/enricher/api/src/main/java/io/fabric8/maven/enricher/api/BaseEnricher.java @@ -55,6 +55,7 @@ public class BaseEnricher implements Enricher { protected static final String SIDECAR = "fabric8.sidecar"; protected static final String ENRICH_ALL_WITH_IMAGE_TRIGGERS = "fabric8.openshift.enrichAllWithImageChangeTrigger"; private static final String SWITCH_TO_DEPLOYMENT = "fabric8.build.switchToDeployment"; + protected static final String GENERATE_ROUTE = "fabric8.openshift.generateRoute"; protected Logger log; diff --git a/enricher/standard/src/main/java/io/fabric8/maven/enricher/standard/openshift/RouteEnricher.java b/enricher/standard/src/main/java/io/fabric8/maven/enricher/standard/openshift/RouteEnricher.java index 41adedfd75..4f9bd0e82c 100644 --- a/enricher/standard/src/main/java/io/fabric8/maven/enricher/standard/openshift/RouteEnricher.java +++ b/enricher/standard/src/main/java/io/fabric8/maven/enricher/standard/openshift/RouteEnricher.java @@ -41,14 +41,16 @@ * Enricher which generates a Route for each exposed Service */ public class RouteEnricher extends BaseEnricher { + private Boolean generateRoute; public RouteEnricher(MavenEnricherContext buildContext) { super(buildContext, "fmp-openshift-route"); + this.generateRoute = getValueFromConfig(GENERATE_ROUTE, true); } @Override public void create(PlatformMode platformMode, final KubernetesListBuilder listBuilder) { - if(platformMode == PlatformMode.openshift) { + if(platformMode == PlatformMode.openshift && generateRoute.equals(Boolean.TRUE)) { final List routes = new ArrayList<>(); listBuilder.accept(new TypedVisitor() { diff --git a/plugin/src/main/java/io/fabric8/maven/plugin/mojo/build/ResourceMojo.java b/plugin/src/main/java/io/fabric8/maven/plugin/mojo/build/ResourceMojo.java index f49345ec32..48db1506e7 100644 --- a/plugin/src/main/java/io/fabric8/maven/plugin/mojo/build/ResourceMojo.java +++ b/plugin/src/main/java/io/fabric8/maven/plugin/mojo/build/ResourceMojo.java @@ -305,25 +305,11 @@ protected static Template getSingletonTemplate(KubernetesList resources) { } public static File writeResourcesIndividualAndComposite(KubernetesList resources, File resourceFileBase, - ResourceFileType resourceFileType, Logger log, Boolean generateRoute) throws MojoExecutionException { + ResourceFileType resourceFileType, Logger log) throws MojoExecutionException { //Creating a new items list. This will be used to generate openshift.yml List newItemList = new ArrayList<>(); - if (!generateRoute) { - - //if flag is set false, this will remove the Route resource from resources list - for (HasMetadata item : resources.getItems()) { - if (item.getKind().equalsIgnoreCase("Route")) { - continue; - } - newItemList.add(item); - } - - //update the resource with new list - resources.setItems(newItemList); - } - // entity is object which will be sent to writeResource for openshift.yml // if generateRoute is false, this will be set to resources with new list // otherwise it will be set to resources with old list. @@ -341,12 +327,12 @@ public static File writeResourcesIndividualAndComposite(KubernetesList resources // write separate files, one for each resource item // resources passed to writeIndividualResources is also new one. - writeIndividualResources(resources, resourceFileBase, resourceFileType, log, generateRoute); + writeIndividualResources(resources, resourceFileBase, resourceFileType, log); return file; } private static void writeIndividualResources(KubernetesList resources, File targetDir, - ResourceFileType resourceFileType, Logger log, Boolean generateRoute) throws MojoExecutionException { + ResourceFileType resourceFileType, Logger log) throws MojoExecutionException { for (HasMetadata item : resources.getItems()) { String name = KubernetesHelper.getName(item); if (StringUtils.isBlank(name)) { @@ -355,13 +341,8 @@ private static void writeIndividualResources(KubernetesList resources, File targ } String itemFile = KubernetesResourceUtil.getNameWithSuffix(name, item.getKind()); - // Here we are writing individual file for all the resources. - // if generateRoute is false and resource is route, we should not generate it. - - if (!(item.getKind().equalsIgnoreCase("Route") && !generateRoute)) { - File itemTarget = new File(targetDir, itemFile); - writeResource(itemTarget, item, resourceFileType); - } + File itemTarget = new File(targetDir, itemFile); + writeResource(itemTarget, item, resourceFileType); } } @@ -394,7 +375,7 @@ public void executeInternal() throws MojoExecutionException, MojoFailureExceptio : ResourceClassifier.OPENSHIFT; resources = generateResources(platformMode); - writeResources(resources, resourceClassifier, generateRoute); + writeResources(resources, resourceClassifier); File resourceDir = new File(this.targetDir, resourceClassifier.getValue()); validateIfRequired(resourceDir, resourceClassifier); } @@ -650,13 +631,13 @@ private boolean isPomProject() { return "pom".equals(project.getPackaging()); } - protected void writeResources(KubernetesList resources, ResourceClassifier classifier, Boolean generateRoute) + protected void writeResources(KubernetesList resources, ResourceClassifier classifier) throws MojoExecutionException { // write kubernetes.yml / openshift.yml File resourceFileBase = new File(this.targetDir, classifier.getValue()); File file = - writeResourcesIndividualAndComposite(resources, resourceFileBase, this.resourceFileType, log, generateRoute); + writeResourcesIndividualAndComposite(resources, resourceFileBase, this.resourceFileType, log); // Resolve template placeholders if (classifier == ResourceClassifier.KUBERNETES) { resolveTemplateVariablesIfAny(resources);