try appease some of pepperpot's very pedantic rules (though some I disagree with such as merging lots of logical predicates into one if() when nested are easy to reason about & refactor)
@@ -67,12 +67,27 @@ public class OpenShiftRouteEnricher extends BaseEnricher {
if (metadata != null && isExposedService(serviceBuilder)) {
String name = metadata.getName();
if (!hasRoute(listBuilder, name)) {
+ RoutePort routePort = createRoutePort(serviceBuilder);
+ if (routePort != null) {
+ // TODO one day lets support multiple ports on a Route when the model supports it
+ routes.add(new RouteBuilder().
+ withMetadata(serviceBuilder.getMetadata()).
+ withNewSpec().
+ withPort(routePort).
+ withNewTo().withKind("Service").withName(name).endTo().
+ endSpec().
+ build());
+ }
+ }
+ }
+ }
+
+ private RoutePort createRoutePort(ServiceBuilder serviceBuilder) {
RoutePort routePort = null;
ServiceSpec spec = serviceBuilder.getSpec();
if (spec != null) {
List<ServicePort> ports = spec.getPorts();
if (ports != null && ports.size() > 0) {
- // TODO one day lets support multiple ports on a Route when the model supports it
ServicePort servicePort = ports.get(0);
if (servicePort != null) {
IntOrString targetPort = servicePort.getTargetPort();
@@ -83,17 +98,7 @@ public class OpenShiftRouteEnricher extends BaseEnricher {
}
}
}
- if (routePort != null) {
- routes.add(new RouteBuilder().
- withMetadata(serviceBuilder.getMetadata()).
- withNewSpec().
- withPort(routePort).
- withNewTo().withKind("Service").withName(name).endTo().
- endSpec().
- build());
- }
- }
- }
+ return routePort;
}
/**
@@ -106,12 +111,10 @@ public class OpenShiftRouteEnricher extends BaseEnricher {
@Override
public void visit(RouteBuilder builder) {
ObjectMeta metadata = builder.getMetadata();
- if (metadata != null) {
- if (name.equals(metadata.getName())) {
+ if (metadata != null && name.equals(metadata.getName())) {
answer.set(true);
}
}
- }
});
return answer.get();
}
