Skip to content
This repository was archived by the owner on Jun 19, 2024. It is now read-only.

Commit c1278ab

Browse files
committed
Fix #1720: Should be able to add custom route, even if fabric8.openshift.generateRoute=false
Removed the filtering of route from ResourceMojo. Ideally it should go into RouteEnricher
1 parent 067d215 commit c1278ab

File tree

4 files changed

+13
-28
lines changed

4 files changed

+13
-28
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ After this we will switch probably to real [Semantic Versioning 2.0.0](http://se
1515
* Fixed image config in thorntail sample
1616
* Fix Autotls enricher in order to add service serving certificate secrets annotations
1717
* Fix #1697: NullpointerException when trying to apply custom resources
18+
* Fix #1720: Should be able to add custom route, even if fabric8.openshift.generateRoute=false
1819
* Fix #1696: fmp not setting imagestreams resourceVersion properly.
1920
* Fix #1689: HELM mode does not support parameters without value
2021
* Fix #1676: Support for latest kubernetes client

enricher/api/src/main/java/io/fabric8/maven/enricher/api/BaseEnricher.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public class BaseEnricher implements Enricher {
5555
protected static final String SIDECAR = "fabric8.sidecar";
5656
protected static final String ENRICH_ALL_WITH_IMAGE_TRIGGERS = "fabric8.openshift.enrichAllWithImageChangeTrigger";
5757
private static final String SWITCH_TO_DEPLOYMENT = "fabric8.build.switchToDeployment";
58+
protected static final String GENERATE_ROUTE = "fabric8.openshift.generateRoute";
5859

5960
protected Logger log;
6061

enricher/standard/src/main/java/io/fabric8/maven/enricher/standard/openshift/RouteEnricher.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,16 @@
4141
* Enricher which generates a Route for each exposed Service
4242
*/
4343
public class RouteEnricher extends BaseEnricher {
44+
private Boolean generateRoute;
4445

4546
public RouteEnricher(MavenEnricherContext buildContext) {
4647
super(buildContext, "fmp-openshift-route");
48+
this.generateRoute = getValueFromConfig(GENERATE_ROUTE, true);
4749
}
4850

4951
@Override
5052
public void create(PlatformMode platformMode, final KubernetesListBuilder listBuilder) {
51-
if(platformMode == PlatformMode.openshift) {
53+
if(platformMode == PlatformMode.openshift && generateRoute.equals(Boolean.TRUE)) {
5254
final List<Route> routes = new ArrayList<>();
5355
listBuilder.accept(new TypedVisitor<ServiceBuilder>() {
5456

plugin/src/main/java/io/fabric8/maven/plugin/mojo/build/ResourceMojo.java

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -305,25 +305,11 @@ protected static Template getSingletonTemplate(KubernetesList resources) {
305305
}
306306

307307
public static File writeResourcesIndividualAndComposite(KubernetesList resources, File resourceFileBase,
308-
ResourceFileType resourceFileType, Logger log, Boolean generateRoute) throws MojoExecutionException {
308+
ResourceFileType resourceFileType, Logger log) throws MojoExecutionException {
309309

310310
//Creating a new items list. This will be used to generate openshift.yml
311311
List<HasMetadata> newItemList = new ArrayList<>();
312312

313-
if (!generateRoute) {
314-
315-
//if flag is set false, this will remove the Route resource from resources list
316-
for (HasMetadata item : resources.getItems()) {
317-
if (item.getKind().equalsIgnoreCase("Route")) {
318-
continue;
319-
}
320-
newItemList.add(item);
321-
}
322-
323-
//update the resource with new list
324-
resources.setItems(newItemList);
325-
}
326-
327313
// entity is object which will be sent to writeResource for openshift.yml
328314
// if generateRoute is false, this will be set to resources with new list
329315
// otherwise it will be set to resources with old list.
@@ -341,12 +327,12 @@ public static File writeResourcesIndividualAndComposite(KubernetesList resources
341327

342328
// write separate files, one for each resource item
343329
// resources passed to writeIndividualResources is also new one.
344-
writeIndividualResources(resources, resourceFileBase, resourceFileType, log, generateRoute);
330+
writeIndividualResources(resources, resourceFileBase, resourceFileType, log);
345331
return file;
346332
}
347333

348334
private static void writeIndividualResources(KubernetesList resources, File targetDir,
349-
ResourceFileType resourceFileType, Logger log, Boolean generateRoute) throws MojoExecutionException {
335+
ResourceFileType resourceFileType, Logger log) throws MojoExecutionException {
350336
for (HasMetadata item : resources.getItems()) {
351337
String name = KubernetesHelper.getName(item);
352338
if (StringUtils.isBlank(name)) {
@@ -355,13 +341,8 @@ private static void writeIndividualResources(KubernetesList resources, File targ
355341
}
356342
String itemFile = KubernetesResourceUtil.getNameWithSuffix(name, item.getKind());
357343

358-
// Here we are writing individual file for all the resources.
359-
// if generateRoute is false and resource is route, we should not generate it.
360-
361-
if (!(item.getKind().equalsIgnoreCase("Route") && !generateRoute)) {
362-
File itemTarget = new File(targetDir, itemFile);
363-
writeResource(itemTarget, item, resourceFileType);
364-
}
344+
File itemTarget = new File(targetDir, itemFile);
345+
writeResource(itemTarget, item, resourceFileType);
365346
}
366347
}
367348

@@ -394,7 +375,7 @@ public void executeInternal() throws MojoExecutionException, MojoFailureExceptio
394375
: ResourceClassifier.OPENSHIFT;
395376

396377
resources = generateResources(platformMode);
397-
writeResources(resources, resourceClassifier, generateRoute);
378+
writeResources(resources, resourceClassifier);
398379
File resourceDir = new File(this.targetDir, resourceClassifier.getValue());
399380
validateIfRequired(resourceDir, resourceClassifier);
400381
}
@@ -650,13 +631,13 @@ private boolean isPomProject() {
650631
return "pom".equals(project.getPackaging());
651632
}
652633

653-
protected void writeResources(KubernetesList resources, ResourceClassifier classifier, Boolean generateRoute)
634+
protected void writeResources(KubernetesList resources, ResourceClassifier classifier)
654635
throws MojoExecutionException {
655636
// write kubernetes.yml / openshift.yml
656637
File resourceFileBase = new File(this.targetDir, classifier.getValue());
657638

658639
File file =
659-
writeResourcesIndividualAndComposite(resources, resourceFileBase, this.resourceFileType, log, generateRoute);
640+
writeResourcesIndividualAndComposite(resources, resourceFileBase, this.resourceFileType, log);
660641
// Resolve template placeholders
661642
if (classifier == ResourceClassifier.KUBERNETES) {
662643
resolveTemplateVariablesIfAny(resources);

0 commit comments

Comments
 (0)