Search in sources :

Example 11 with ContainerPort

use of io.fabric8.kubernetes.api.model.ContainerPort in project fabric8-maven-plugin by fabric8io.

the class SpringBootWatcher method getPortForwardUrl.

private String getPortForwardUrl(final Set<HasMetadata> resources) throws Exception {
    LabelSelector selector = KubernetesResourceUtil.getPodLabelSelector(resources);
    if (selector == null) {
        log.warn("Unable to determine a selector for application pods");
        return null;
    }
    Properties properties = SpringBootUtil.getSpringBootApplicationProperties(MavenUtil.getCompileClassLoader(getContext().getProject()));
    SpringBootConfigurationHelper propertyHelper = new SpringBootConfigurationHelper(SpringBootUtil.getSpringBootVersion(getContext().getProject()));
    int port = IoUtil.getFreeRandomPort();
    int containerPort = propertyHelper.getServerPort(properties);
    portForwardService.forwardPortAsync(getContext().getLogger(), selector, containerPort, port);
    return createForwardUrl(propertyHelper, properties, port);
}
Also used : SpringBootConfigurationHelper(io.fabric8.maven.core.util.SpringBootConfigurationHelper) LabelSelector(io.fabric8.kubernetes.api.model.LabelSelector) Properties(java.util.Properties)

Example 12 with ContainerPort

use of io.fabric8.kubernetes.api.model.ContainerPort in project fabric8-maven-plugin by fabric8io.

the class DebugEnricher method enableDebugging.

private boolean enableDebugging(HasMetadata entity, PodTemplateSpec template) {
    if (template != null) {
        PodSpec podSpec = template.getSpec();
        if (podSpec != null) {
            List<Container> containers = podSpec.getContainers();
            if (containers.size() > 0) {
                Container container = containers.get(0);
                List<EnvVar> env = container.getEnv();
                if (env == null) {
                    env = new ArrayList<>();
                }
                String remoteDebugPort = KubernetesResourceUtil.getEnvVar(env, ENV_VAR_JAVA_DEBUG_PORT, ENV_VAR_JAVA_DEBUG_PORT_DEFAULT);
                boolean enabled = false;
                if (KubernetesResourceUtil.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;
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort) EnvVar(io.fabric8.kubernetes.api.model.EnvVar)

Example 13 with ContainerPort

use of io.fabric8.kubernetes.api.model.ContainerPort in project che-server by eclipse-che.

the class KubernetesServerExposer method exposeInContainerIfNeeded.

private void exposeInContainerIfNeeded(ServicePort servicePort) {
    if (container.getPorts().stream().noneMatch(p -> p.getContainerPort().equals(servicePort.getPort()) && servicePort.getProtocol().equals(p.getProtocol()))) {
        ContainerPort containerPort = new ContainerPortBuilder().withContainerPort(servicePort.getPort()).withProtocol(servicePort.getProtocol()).build();
        container.getPorts().add(containerPort);
    }
}
Also used : ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort)

Example 14 with ContainerPort

use of io.fabric8.kubernetes.api.model.ContainerPort in project che-server by eclipse-che.

the class KubernetesPluginsToolingApplierTest method verifyPortsExposed.

private void verifyPortsExposed(Container container, int... ports) {
    List<ContainerPort> actualPorts = container.getPorts();
    List<ContainerPort> expectedPorts = new ArrayList<>();
    for (int port : ports) {
        expectedPorts.add(new ContainerPortBuilder().withContainerPort(port).withProtocol("TCP").build());
    }
    assertEquals(actualPorts, expectedPorts);
}
Also used : ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort) CheContainerPort(org.eclipse.che.api.workspace.server.wsplugins.model.CheContainerPort) ArrayList(java.util.ArrayList) ChePluginEndpoint(org.eclipse.che.api.workspace.server.wsplugins.model.ChePluginEndpoint)

Example 15 with ContainerPort

use of io.fabric8.kubernetes.api.model.ContainerPort in project che-server by eclipse-che.

the class K8sContainerResolverTest method k8sPort.

private ContainerPort k8sPort(Integer port) {
    ContainerPort containerPort = new ContainerPort();
    containerPort.setContainerPort(port);
    containerPort.setProtocol("TCP");
    return containerPort;
}
Also used : ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort)

Aggregations

ContainerPort (io.fabric8.kubernetes.api.model.ContainerPort)84 ArrayList (java.util.ArrayList)34 ContainerPortBuilder (io.fabric8.kubernetes.api.model.ContainerPortBuilder)31 Container (io.fabric8.kubernetes.api.model.Container)30 Pod (io.fabric8.kubernetes.api.model.Pod)22 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)18 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)17 Test (org.junit.jupiter.api.Test)16 Service (io.fabric8.kubernetes.api.model.Service)13 TopologySpreadConstraint (io.fabric8.kubernetes.api.model.TopologySpreadConstraint)12 HashMap (java.util.HashMap)12 ServicePortBuilder (io.fabric8.kubernetes.api.model.ServicePortBuilder)11 IOException (java.io.IOException)11 LinkedList (java.util.LinkedList)11 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)10 ServiceSpecBuilder (io.fabric8.kubernetes.api.model.ServiceSpecBuilder)10 StatefulSet (io.fabric8.kubernetes.api.model.apps.StatefulSet)10 Kafka (io.strimzi.api.kafka.model.Kafka)10 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)10 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)10