use of io.fabric8.maven.core.util.kubernetes.KubernetesResourceUtil.getPodLabelSelector 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.maven.core.util.kubernetes.KubernetesResourceUtil.getPodLabelSelector in project fabric8-maven-plugin by fabric8io.
the class PodLogService method tailAppPodsLogs.
public void tailAppPodsLogs(final KubernetesClient kubernetes, final String namespace, final Set<HasMetadata> entities, boolean watchAddedPodsOnly, String onExitOperation, boolean followLog, Date ignorePodsOlderThan, boolean waitInCurrentThread) {
LabelSelector selector = KubernetesResourceUtil.getPodLabelSelector(entities);
if (selector != null) {
String ctrlCMessage = "stop tailing the log";
if (StringUtils.isNotBlank(onExitOperation)) {
final String onExitOperationLower = onExitOperation.toLowerCase().trim();
if (onExitOperationLower.equals(OPERATION_UNDEPLOY)) {
ctrlCMessage = "undeploy the app";
} else if (onExitOperationLower.equals(OPERATION_STOP)) {
ctrlCMessage = "scale down the app and stop tailing the log";
} else {
log.warn("Unknown on-exit command: `%s`", onExitOperationLower);
}
resizeApp(kubernetes, namespace, entities, 1, log);
Runtime.getRuntime().addShutdownHook(new Thread("pod log service shutdown hook") {
@Override
public void run() {
if (onExitOperationLower.equals(OPERATION_UNDEPLOY)) {
log.info("Undeploying the app:");
deleteEntities(kubernetes, namespace, entities, context.getS2iBuildNameSuffix(), log);
} else if (onExitOperationLower.equals(OPERATION_STOP)) {
log.info("Stopping the app:");
resizeApp(kubernetes, namespace, entities, 0, log);
}
if (podWatcher != null) {
podWatcher.close();
}
closeLogWatcher();
}
});
}
waitAndLogPods(kubernetes, namespace, selector, watchAddedPodsOnly, ctrlCMessage, followLog, ignorePodsOlderThan, waitInCurrentThread);
} else {
log.warn("No selector in deployment so cannot watch pods!");
}
}
Aggregations