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);
}
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;
}
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);
}
}
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);
}
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;
}
Aggregations