Source:
<code>private void injectsPreviewUrlToCommands(E env, KubernetesNamespace namespace) throws InfrastructureException { if (env.getCommands() == null) { return; } for (CommandImpl command : env.getCommands() .stream() .filter(c -> c.getPreviewUrl() != null) .collect(Collectors.toList())) { Optional<Service> foundService = Services.findServiceWithPort( namespace.services().get(), command.getPreviewUrl().getPort()); if (foundService.isPresent()) { Optional<String> foundHost = findHostForServicePort( namespace, foundService.get(), command.getPreviewUrl().getPort()); if (foundHost.isPresent()) { command.getAttributes().put(PREVIEW_URL_ATTRIBUTE, foundHost.get()); } else { LOG.warn( "unable to find ingress for service and port [{}]", foundService.get(), command.getPreviewUrl().getPort()); } } else { LOG.warn( <START> "unable to find service for port for command [{}]", <END> command.getPreviewUrl().getPort(), command.getName()); } } }</code><technical_language>Personally I prefer reduce nesting levels, Please consider change java for (CommandImpl command : env.getCommands() .stream() .filter(c -> c.getPreviewUrl() != null) .collect(Collectors.toList())) { Optional<Service> foundService = Services.findServiceWithPort( namespace.services().get(), command.getPreviewUrl().getPort()); if (!foundService.isPresent()) { LOG.warn( "unable find service for port for command [{}]", command.getPreviewUrl().getPort(), command.getName()); return; } Optional<String> foundHost = findHostForServicePort( namespace, foundService.get(), command.getPreviewUrl().getPort()); if (foundHost.isPresent()) { command.getAttributes().put(PREVIEW_URL_ATTRIBUTE, foundHost.get()) } else { LOG.warn( "unable find ingress for service port [{}]", foundService.get(), command.getPreviewUrl().getPort()); } } question of taste. change not</technical_language>

Target:
private void injectsPreviewUrlToCommands(E env, KubernetesNamespace namespace) throws InfrastructureException { if (env.getCommands() == null) { return; } List<T> exposureObjects = loadExposureObjects(namespace); List<Service> services = namespace.services().get(); for (CommandImpl command : env.getCommands() .stream() .filter(c -> c.getPreviewUrl() != null) .collect(Collectors.toList())) { Optional<Service> foundService = Services.findServiceWithPort(services, command.getPreviewUrl().getPort()); if (!foundService.isPresent()) { String message = String.format( "unable to find service for port '%s' for command '%s'", command.getPreviewUrl().getPort(), command.getName()); LOG.warn(message); env.addWarning( new WarningImpl( NOT_ABLE_TO_PROVISION_OBJECTS_FOR_PREVIEW_URL, String.format(NOT_ABLE_TO_PROVISION_OBJECTS_FOR_PREVIEW_URL_MESSAGE, message))); continue; } Optional<String> foundHost = findHostForServicePort( exposureObjects, foundService.get(), command.getPreviewUrl().getPort()); if (foundHost.isPresent()) { command.getAttributes().put(PREVIEW_URL_ATTRIBUTE, foundHost.get()); } else { String message = String.format( "unable to find ingress for service '%s' and port '%s'", foundService.get(), command.getPreviewUrl().getPort()); LOG.warn(message); env.addWarning( new WarningImpl( NOT_ABLE_TO_PROVISION_OBJECTS_FOR_PREVIEW_URL, String.format(NOT_ABLE_TO_PROVISION_OBJECTS_FOR_PREVIEW_URL_MESSAGE, message))); } } }