@Test public void containerPortsWithDifferentPortTest(){ ports.add("172.22.27.82:82:8082"); ports.add("172.22.27.81:81:8081/tcp"); ports.add("172.22.27.83:83:8083/udp"); ports.add("90:9093/tcp"); ports.add("172.22.27.84:8084/tcp"); ports.add("172.22.27.84:84/tcp"); ports.add("9090/tcp"); ports.add("9091"); ports.add("9092/udp"); buildImageConfiguration1 = new BuildConfiguration.Builder(). ports(ports).from("fabric8/maven:latest").cleanup("try").compression("gzip").build(); imageConfiguration1 = new ImageConfiguration.Builder(). name("test").alias("test-app").buildConfig(buildImageConfiguration1).registry("docker.io").build(); images.clear(); images.add(imageConfiguration1); ContainerHandler handler = createContainerHandler(project); containers = handler.getContainers(config, images); List<ContainerPort> outputports = containers.get(0).getPorts(); assertEquals(9,outputports.size()); int protocolCount=0,tcpCount=0,udpCount=0,containerPortCount=0,hostIPCount=0,hostPortCount=0; for(int i=0;i<9;i++){ if(!StringUtils.isBlank(outputports.get(i).getProtocol())){ protocolCount++; if(outputports.get(i).getProtocol().equalsIgnoreCase("tcp")){ tcpCount++; } else{ udpCount++; } } if(!StringUtils.isBlank(outputports.get(i).getHostIP())){ hostIPCount++; } if(outputports.get(i).getContainerPort()!=null){ containerPortCount++; } if(outputports.get(i).getHostPort()!=null){ hostPortCount++; } } assertEquals(9,protocolCount); assertEquals(7,tcpCount); assertEquals(2,udpCount); assertEquals(3,hostIPCount); assertEquals(9,containerPortCount); assertEquals(4,hostPortCount); }
List<Container> getContainers(ResourceConfig config, List<ImageConfiguration> images) { List<Container> ret = new ArrayList<>(); for (ImageConfiguration imageConfig : images) { if (imageConfig.getBuildConfiguration() != null) { Probe livenessProbe = probeHandler.getProbe(config.getLiveness()); Probe readinessProbe = probeHandler.getProbe(config.getReadiness()); Container container = new ContainerBuilder() .withName(KubernetesResourceUtil.extractContainerName(this.groupArtifactVersion, imageConfig)) .withImage(getImageName(imageConfig)) .withImagePullPolicy(getImagePullPolicy(config)) .withEnv(getEnvVars(config)) .withSecurityContext(createSecurityContext(config)) .withPorts(getContainerPorts(imageConfig)) .withVolumeMounts(getVolumeMounts(config)) .withLivenessProbe(livenessProbe) .withReadinessProbe(readinessProbe) .build(); ret.add(container); } } return ret; }
ContainerHandler { List<Container> getContainers(ResourceConfig config, List<ImageConfiguration> images) { List<Container> ret = new ArrayList<>(); for (ImageConfiguration imageConfig : images) { if (imageConfig.getBuildConfiguration() != null) { Probe livenessProbe = probeHandler.getProbe(config.getLiveness()); Probe readinessProbe = probeHandler.getProbe(config.getReadiness()); Container container = new ContainerBuilder() .withName(KubernetesResourceUtil.extractContainerName(this.groupArtifactVersion, imageConfig)) .withImage(getImageName(imageConfig)) .withImagePullPolicy(getImagePullPolicy(config)) .withEnv(getEnvVars(config)) .withSecurityContext(createSecurityContext(config)) .withPorts(getContainerPorts(imageConfig)) .withVolumeMounts(getVolumeMounts(config)) .withLivenessProbe(livenessProbe) .withReadinessProbe(readinessProbe) .build(); ret.add(container); } } return ret; } }
ContainerHandler { List<Container> getContainers(ResourceConfig config, List<ImageConfiguration> images) { List<Container> ret = new ArrayList<>(); for (ImageConfiguration imageConfig : images) { if (imageConfig.getBuildConfiguration() != null) { Probe livenessProbe = probeHandler.getProbe(config.getLiveness()); Probe readinessProbe = probeHandler.getProbe(config.getReadiness()); Container container = new ContainerBuilder() .withName(KubernetesResourceUtil.extractContainerName(this.groupArtifactVersion, imageConfig)) .withImage(getImageName(imageConfig)) .withImagePullPolicy(getImagePullPolicy(config)) .withEnv(getEnvVars(config)) .withSecurityContext(createSecurityContext(config)) .withPorts(getContainerPorts(imageConfig)) .withVolumeMounts(getVolumeMounts(config)) .withLivenessProbe(livenessProbe) .withReadinessProbe(readinessProbe) .build(); ret.add(container); } } return ret; } ContainerHandler(Properties configurationProperties, GroupArtifactVersion groupArtifactVersion, ProbeHandler probeHandler); }
ContainerHandler { List<Container> getContainers(ResourceConfig config, List<ImageConfiguration> images) { List<Container> ret = new ArrayList<>(); for (ImageConfiguration imageConfig : images) { if (imageConfig.getBuildConfiguration() != null) { Probe livenessProbe = probeHandler.getProbe(config.getLiveness()); Probe readinessProbe = probeHandler.getProbe(config.getReadiness()); Container container = new ContainerBuilder() .withName(KubernetesResourceUtil.extractContainerName(this.groupArtifactVersion, imageConfig)) .withImage(getImageName(imageConfig)) .withImagePullPolicy(getImagePullPolicy(config)) .withEnv(getEnvVars(config)) .withSecurityContext(createSecurityContext(config)) .withPorts(getContainerPorts(imageConfig)) .withVolumeMounts(getVolumeMounts(config)) .withLivenessProbe(livenessProbe) .withReadinessProbe(readinessProbe) .build(); ret.add(container); } } return ret; } ContainerHandler(Properties configurationProperties, GroupArtifactVersion groupArtifactVersion, ProbeHandler probeHandler);  }
ContainerHandler { List<Container> getContainers(ResourceConfig config, List<ImageConfiguration> images) { List<Container> ret = new ArrayList<>(); for (ImageConfiguration imageConfig : images) { if (imageConfig.getBuildConfiguration() != null) { Probe livenessProbe = probeHandler.getProbe(config.getLiveness()); Probe readinessProbe = probeHandler.getProbe(config.getReadiness()); Container container = new ContainerBuilder() .withName(KubernetesResourceUtil.extractContainerName(this.groupArtifactVersion, imageConfig)) .withImage(getImageName(imageConfig)) .withImagePullPolicy(getImagePullPolicy(config)) .withEnv(getEnvVars(config)) .withSecurityContext(createSecurityContext(config)) .withPorts(getContainerPorts(imageConfig)) .withVolumeMounts(getVolumeMounts(config)) .withLivenessProbe(livenessProbe) .withReadinessProbe(readinessProbe) .build(); ret.add(container); } } return ret; } ContainerHandler(Properties configurationProperties, GroupArtifactVersion groupArtifactVersion, ProbeHandler probeHandler);   }