Minor fix for service enricher logging
@@ -360,16 +360,21 @@ public class DefaultServiceEnricher extends BaseEnricher {
private String formatPortsAsList(List<ServicePort> ports) {
List<String> p = new ArrayList<>();
for (ServicePort port : ports) {
- IntOrString targetPort = port.getTargetPort();
- String val = targetPort.getStrVal();
- if (val == null) {
- val = Integer.toString(targetPort.getIntVal());
- }
- p.add(val);
+ String targetPort = getPortValue(port.getTargetPort());
+ String servicePort= port.getPort() != null ? Integer.toString(port.getPort()) : targetPort;
+ p.add(targetPort.equals(servicePort) ? targetPort : servicePort + ":" + targetPort);
}
return StringUtils.join(p.iterator(), ",");
}
+ private String getPortValue(IntOrString port) {
+ String val = port.getStrVal();
+ if (val == null) {
+ val = Integer.toString(port.getIntVal());
+ }
+ return val;
+ }
+
private String getDefaultServiceName(Service defaultService) {
String defaultServiceName = KubernetesHelper.getName(defaultService);
if (Strings.isNullOrBlank(defaultServiceName)) {
