Java Code Examples for io.fabric8.kubernetes.api.model.Container#setPorts()
The following examples show how to use
io.fabric8.kubernetes.api.model.Container#setPorts() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KubernetesResourceUtil.java From jkube with Eclipse Public License 2.0 | 6 votes |
private static void ensureHasPort(Container container, ContainerPort port) { List<ContainerPort> ports = container.getPorts(); if (ports == null) { ports = new ArrayList<>(); container.setPorts(ports); } for (ContainerPort cp : ports) { String n1 = cp.getName(); String n2 = port.getName(); if (n1 != null && n2 != null && n1.equals(n2)) { return; } Integer p1 = cp.getContainerPort(); Integer p2 = port.getContainerPort(); if (p1 != null && p2 != null && p1.intValue() == p2.intValue()) { return; } } ports.add(port); }
Example 2
Source File: KubernetesIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
private PodSpec createPodSpec() throws IOException { PodSpec podSpec = new PodSpec(); podSpec.setHostname("localhost"); Container container = new Container(); container.setImage("docker.io/wildflyext/wildfly-camel:latest"); container.setName("wildfly-camel-test"); ContainerPort port = new ContainerPort(); port.setHostIP("0.0.0.0"); port.setContainerPort(8080); List<ContainerPort> ports = new ArrayList<>(); ports.add(port); container.setPorts(ports); List<Container> containers = new ArrayList<>(); containers.add(container); podSpec.setContainers(containers); return podSpec; }
Example 3
Source File: DebugEnricher.java From jkube with Eclipse Public License 2.0 | 5 votes |
private boolean enableDebugging(HasMetadata entity, PodTemplateSpec template) { if (template != null) { PodSpec podSpec = template.getSpec(); if (podSpec != null) { List<Container> containers = podSpec.getContainers(); if (!containers.isEmpty()) { Container container = containers.get(0); List<EnvVar> env = container.getEnv(); if (env == null) { env = new ArrayList<>(); } String remoteDebugPort = KubernetesHelper.getEnvVar(env, ENV_VAR_JAVA_DEBUG_PORT, ENV_VAR_JAVA_DEBUG_PORT_DEFAULT); boolean enabled = false; if (KubernetesHelper.setEnvVar(env, ENV_VAR_JAVA_DEBUG, "true")) { container.setEnv(env); enabled = true; } List<ContainerPort> ports = container.getPorts(); if (ports == null) { ports = new ArrayList<>(); } if (KubernetesResourceUtil.addPort(ports, remoteDebugPort, "debug", log)) { container.setPorts(ports); enabled = true; } if (enabled) { log.info("Enabling debug on " + KubernetesHelper.getKind(entity) + " " + KubernetesHelper.getName( entity) + " due to the property: " + ENABLE_DEBUG_MAVEN_PROPERTY); return true; } } } } return false; }
Example 4
Source File: DebugMojo.java From jkube with Eclipse Public License 2.0 | 4 votes |
private boolean enableDebugging(HasMetadata entity, PodTemplateSpec template) { if (template != null) { PodSpec podSpec = template.getSpec(); if (podSpec != null) { List<Container> containers = podSpec.getContainers(); boolean enabled = false; for (int i = 0; i < containers.size(); i++) { Container container = containers.get(i); List<EnvVar> env = container.getEnv(); if (env == null) { env = new ArrayList<>(); } remoteDebugPort = KubernetesHelper.getEnvVar(env, DebugConstants.ENV_VAR_JAVA_DEBUG_PORT, DebugConstants.ENV_VAR_JAVA_DEBUG_PORT_DEFAULT); if (KubernetesHelper.setEnvVar(env, DebugConstants.ENV_VAR_JAVA_DEBUG, "true")) { container.setEnv(env); enabled = true; } if (KubernetesHelper.setEnvVar(env, DebugConstants.ENV_VAR_JAVA_DEBUG_SUSPEND, String.valueOf(debugSuspend))) { container.setEnv(env); enabled = true; } List<ContainerPort> ports = container.getPorts(); if (ports == null) { ports = new ArrayList<>(); } if (KubernetesResourceUtil.addPort(ports, remoteDebugPort, "debug", log)) { container.setPorts(ports); enabled = true; } if (debugSuspend) { // Setting a random session value to force pod restart this.debugSuspendValue = String.valueOf(new Random().nextLong()); KubernetesHelper.setEnvVar(env, DebugConstants.ENV_VAR_JAVA_DEBUG_SESSION, this.debugSuspendValue); container.setEnv(env); if (container.getReadinessProbe() != null) { log.info("Readiness probe will be disabled on " + KubernetesHelper.getKind(entity) + " " + getName(entity) + " to allow attaching a remote debugger during suspension"); container.setReadinessProbe(null); } enabled = true; } else { if (KubernetesHelper.removeEnvVar(env, DebugConstants.ENV_VAR_JAVA_DEBUG_SESSION)) { container.setEnv(env); enabled = true; } } } if (enabled) { log.info("Enabling debug on " + KubernetesHelper.getKind(entity) + " " + getName(entity)); return true; } } } return false; }