Skip to content

Commit

Permalink
Fix fabric8io#1720: Should be able to add custom route, even if fabri…
Browse files Browse the repository at this point in the history
…c8.openshift.generateRoute=false

Removed the filtering of route from ResourceMojo. Ideally it should go into RouteEnricher
  • Loading branch information
rohanKanojia committed Oct 3, 2019
1 parent c64d894 commit 82b648a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Route> routes = new ArrayList<>();
listBuilder.accept(new TypedVisitor<ServiceBuilder>() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<HasMetadata> 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.
Expand All @@ -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)) {
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 82b648a

Please sign in to comment.