Skip to content

Commit 1f313ef

Browse files
committed
fix: Log service works for specific Pods
Signed-off-by: Marc Nuri <[email protected]>
1 parent c60062a commit 1f313ef

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Usage:
2121
./scripts/extract-changelog-for-version.sh 1.3.37 5
2222
```
2323
### 1.7.0-SNAPSHOT
24+
* Fix #1315: Pod Log Service works for Jobs with no selector
2425
* Fix #1126: Liveness and readiness TCP ports are not serialized as numbers when defined as numbers
2526
* Fix #1211: Port `java-options-env-merge` integration test and ContainerEnvJavaOptionsMergeEnricher documentation to gradle
2627
* Fix #1214: Add integration test to verify `jkube.debug.enabled` flag works as expected

gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesLogTaskTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void runTask_withNoK8sManifests_shouldLogCantWatchPods() {
5656

5757
// Then
5858
verify(taskEnvironment.logger).lifecycle("k8s: Running in Kubernetes mode");
59-
verify(taskEnvironment.logger).warn("k8s: No selector in deployment so cannot watch pods!");
59+
verify(taskEnvironment.logger).warn("k8s: No selector detected and no Pod name specified, cannot watch Pods!");
6060
}
6161

6262
@Test

jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/PodLogService.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public class PodLogService {
6363

6464
private Watch podWatcher;
6565
private LogWatch logWatcher;
66-
private Map<String, Pod> addedPods = new ConcurrentHashMap<>();
67-
private CountDownLatch terminateLatch = new CountDownLatch(1);
66+
private final Map<String, Pod> addedPods = new ConcurrentHashMap<>();
67+
private final CountDownLatch terminateLatch = new CountDownLatch(1);
6868
private String watchingPodName;
6969
private CountDownLatch logWatchTerminateLatch;
7070

@@ -79,7 +79,7 @@ public void tailAppPodsLogs(final KubernetesClient kubernetes, final String name
7979

8080
LabelSelector selector = KubernetesHelper.extractPodLabelSelector(entities);
8181

82-
if (selector != null) {
82+
if (selector != null || StringUtils.isNotBlank(context.getPodName())) {
8383
String ctrlCMessage = "stop tailing the log";
8484
if (StringUtils.isNotBlank(onExitOperation)) {
8585
final String onExitOperationLower = onExitOperation.toLowerCase().trim();
@@ -113,18 +113,19 @@ public void run() {
113113
}
114114
waitAndLogPods(kubernetes, namespace, selector, watchAddedPodsOnly, ctrlCMessage, followLog, ignorePodsOlderThan, waitInCurrentThread);
115115
} else {
116-
log.warn("No selector in deployment so cannot watch pods!");
116+
log.warn("No selector detected and no Pod name specified, cannot watch Pods!");
117117
}
118118
}
119119

120120
private void waitAndLogPods(final KubernetesClient kubernetes, final String namespace, LabelSelector selector, final boolean watchAddedPodsOnly, final String ctrlCMessage, final boolean
121121
followLog, Date ignorePodsOlderThan, boolean waitInCurrentThread) {
122-
FilterWatchListDeletable<Pod, PodList> pods = withSelector(kubernetes.pods().inNamespace(namespace), selector, log);
123-
if (context.getPodName() != null) {
122+
final FilterWatchListDeletable<Pod, PodList> pods;
123+
if (StringUtils.isNotBlank(context.getPodName())) {
124124
log.info("Watching pod with selector %s, and name %s waiting for a running pod...", selector, context.getPodName());
125-
pods = pods.withField("metadata.name", context.getPodName());
125+
pods = kubernetes.pods().inNamespace(namespace).withField("metadata.name", context.getPodName());
126126
} else {
127127
log.info("Watching pods with selector %s waiting for a running pod...", selector);
128+
pods = withSelector(kubernetes.pods().inNamespace(namespace), selector, log);
128129
}
129130
Pod latestPod = null;
130131
boolean runningPod = false;

0 commit comments

Comments
 (0)