@Test public void getServicesWithDefaultProtocolTest() { port = new ServiceConfig.Port.Builder() .port(8080).targetPort(80).nodePort(50).name("port-test").build(); ports.clear(); ports.add(port); serviceconfig = new ServiceConfig.Builder() .ports(ports).name("service-test").expose(true).headless(false).type("NodePort").build(); serviceConfigs.clear(); serviceConfigs.add(serviceconfig); services = serviceHandler.getServices(serviceConfigs); assertEquals("TCP",services.get(0).getSpec().getPorts().get(0).getProtocol()); }
public List<Service> getServices(List<ServiceConfig> services) { ArrayList<Service> ret = new ArrayList<>(); for (ServiceConfig service : services) { ServiceBuilder serviceBuilder = new ServiceBuilder() .withNewMetadata() .withName(service.getName()) .withAnnotations(getAnnotations(service)) .withLabels(getLabels(service)) .endMetadata(); ServiceFluent.SpecNested<ServiceBuilder> serviceSpecBuilder = serviceBuilder.withNewSpec(); List<ServicePort> servicePorts = new ArrayList<>(); for (ServiceConfig.Port port : service.getPorts()) { ServicePort servicePort = new ServicePortBuilder() .withName(port.getName()) .withProtocol(port.getProtocol() != null ? port.getProtocol().name() : "TCP") .withTargetPort(new IntOrString(port.getTargetPort())) .withPort(port.getPort()) .withNodePort(port.getNodePort()) .build(); servicePorts.add(servicePort); } if (!servicePorts.isEmpty()) { serviceSpecBuilder.withPorts(servicePorts); } if (service.isHeadless()) { serviceSpecBuilder.withClusterIP("None"); } if (StringUtils.isNotBlank(service.getType())) { serviceSpecBuilder.withType(service.getType()); } serviceSpecBuilder.endSpec(); if (service.isHeadless() || !servicePorts.isEmpty()) { ret.add(serviceBuilder.build()); } } return ret; }
ServiceHandler { public List<Service> getServices(List<ServiceConfig> services) { ArrayList<Service> ret = new ArrayList<>(); for (ServiceConfig service : services) { ServiceBuilder serviceBuilder = new ServiceBuilder() .withNewMetadata() .withName(service.getName()) .withAnnotations(getAnnotations(service)) .withLabels(getLabels(service)) .endMetadata(); ServiceFluent.SpecNested<ServiceBuilder> serviceSpecBuilder = serviceBuilder.withNewSpec(); List<ServicePort> servicePorts = new ArrayList<>(); for (ServiceConfig.Port port : service.getPorts()) { ServicePort servicePort = new ServicePortBuilder() .withName(port.getName()) .withProtocol(port.getProtocol() != null ? port.getProtocol().name() : "TCP") .withTargetPort(new IntOrString(port.getTargetPort())) .withPort(port.getPort()) .withNodePort(port.getNodePort()) .build(); servicePorts.add(servicePort); } if (!servicePorts.isEmpty()) { serviceSpecBuilder.withPorts(servicePorts); } if (service.isHeadless()) { serviceSpecBuilder.withClusterIP("None"); } if (StringUtils.isNotBlank(service.getType())) { serviceSpecBuilder.withType(service.getType()); } serviceSpecBuilder.endSpec(); if (service.isHeadless() || !servicePorts.isEmpty()) { ret.add(serviceBuilder.build()); } } return ret; } }
ServiceHandler { public List<Service> getServices(List<ServiceConfig> services) { ArrayList<Service> ret = new ArrayList<>(); for (ServiceConfig service : services) { ServiceBuilder serviceBuilder = new ServiceBuilder() .withNewMetadata() .withName(service.getName()) .withAnnotations(getAnnotations(service)) .withLabels(getLabels(service)) .endMetadata(); ServiceFluent.SpecNested<ServiceBuilder> serviceSpecBuilder = serviceBuilder.withNewSpec(); List<ServicePort> servicePorts = new ArrayList<>(); for (ServiceConfig.Port port : service.getPorts()) { ServicePort servicePort = new ServicePortBuilder() .withName(port.getName()) .withProtocol(port.getProtocol() != null ? port.getProtocol().name() : "TCP") .withTargetPort(new IntOrString(port.getTargetPort())) .withPort(port.getPort()) .withNodePort(port.getNodePort()) .build(); servicePorts.add(servicePort); } if (!servicePorts.isEmpty()) { serviceSpecBuilder.withPorts(servicePorts); } if (service.isHeadless()) { serviceSpecBuilder.withClusterIP("None"); } if (StringUtils.isNotBlank(service.getType())) { serviceSpecBuilder.withType(service.getType()); } serviceSpecBuilder.endSpec(); if (service.isHeadless() || !servicePorts.isEmpty()) { ret.add(serviceBuilder.build()); } } return ret; }  }
ServiceHandler { public List<Service> getServices(List<ServiceConfig> services) { ArrayList<Service> ret = new ArrayList<>(); for (ServiceConfig service : services) { ServiceBuilder serviceBuilder = new ServiceBuilder() .withNewMetadata() .withName(service.getName()) .withAnnotations(getAnnotations(service)) .withLabels(getLabels(service)) .endMetadata(); ServiceFluent.SpecNested<ServiceBuilder> serviceSpecBuilder = serviceBuilder.withNewSpec(); List<ServicePort> servicePorts = new ArrayList<>(); for (ServiceConfig.Port port : service.getPorts()) { ServicePort servicePort = new ServicePortBuilder() .withName(port.getName()) .withProtocol(port.getProtocol() != null ? port.getProtocol().name() : "TCP") .withTargetPort(new IntOrString(port.getTargetPort())) .withPort(port.getPort()) .withNodePort(port.getNodePort()) .build(); servicePorts.add(servicePort); } if (!servicePorts.isEmpty()) { serviceSpecBuilder.withPorts(servicePorts); } if (service.isHeadless()) { serviceSpecBuilder.withClusterIP("None"); } if (StringUtils.isNotBlank(service.getType())) { serviceSpecBuilder.withType(service.getType()); } serviceSpecBuilder.endSpec(); if (service.isHeadless() || !servicePorts.isEmpty()) { ret.add(serviceBuilder.build()); } } return ret; }  List<Service> getServices(List<ServiceConfig> services); }
ServiceHandler { public List<Service> getServices(List<ServiceConfig> services) { ArrayList<Service> ret = new ArrayList<>(); for (ServiceConfig service : services) { ServiceBuilder serviceBuilder = new ServiceBuilder() .withNewMetadata() .withName(service.getName()) .withAnnotations(getAnnotations(service)) .withLabels(getLabels(service)) .endMetadata(); ServiceFluent.SpecNested<ServiceBuilder> serviceSpecBuilder = serviceBuilder.withNewSpec(); List<ServicePort> servicePorts = new ArrayList<>(); for (ServiceConfig.Port port : service.getPorts()) { ServicePort servicePort = new ServicePortBuilder() .withName(port.getName()) .withProtocol(port.getProtocol() != null ? port.getProtocol().name() : "TCP") .withTargetPort(new IntOrString(port.getTargetPort())) .withPort(port.getPort()) .withNodePort(port.getNodePort()) .build(); servicePorts.add(servicePort); } if (!servicePorts.isEmpty()) { serviceSpecBuilder.withPorts(servicePorts); } if (service.isHeadless()) { serviceSpecBuilder.withClusterIP("None"); } if (StringUtils.isNotBlank(service.getType())) { serviceSpecBuilder.withType(service.getType()); } serviceSpecBuilder.endSpec(); if (service.isHeadless() || !servicePorts.isEmpty()) { ret.add(serviceBuilder.build()); } } return ret; }  List<Service> getServices(List<ServiceConfig> services);  }