@@ -63,8 +63,8 @@ public class PodLogService {
63
63
64
64
private Watch podWatcher ;
65
65
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 );
68
68
private String watchingPodName ;
69
69
private CountDownLatch logWatchTerminateLatch ;
70
70
@@ -79,7 +79,7 @@ public void tailAppPodsLogs(final KubernetesClient kubernetes, final String name
79
79
80
80
LabelSelector selector = KubernetesHelper .extractPodLabelSelector (entities );
81
81
82
- if (selector != null ) {
82
+ if (selector != null || StringUtils . isNotBlank ( context . getPodName ()) ) {
83
83
String ctrlCMessage = "stop tailing the log" ;
84
84
if (StringUtils .isNotBlank (onExitOperation )) {
85
85
final String onExitOperationLower = onExitOperation .toLowerCase ().trim ();
@@ -113,18 +113,19 @@ public void run() {
113
113
}
114
114
waitAndLogPods (kubernetes , namespace , selector , watchAddedPodsOnly , ctrlCMessage , followLog , ignorePodsOlderThan , waitInCurrentThread );
115
115
} 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 !" );
117
117
}
118
118
}
119
119
120
120
private void waitAndLogPods (final KubernetesClient kubernetes , final String namespace , LabelSelector selector , final boolean watchAddedPodsOnly , final String ctrlCMessage , final boolean
121
121
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 ()) ) {
124
124
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 ());
126
126
} else {
127
127
log .info ("Watching pods with selector %s waiting for a running pod..." , selector );
128
+ pods = withSelector (kubernetes .pods ().inNamespace (namespace ), selector , log );
128
129
}
129
130
Pod latestPod = null ;
130
131
boolean runningPod = false ;
0 commit comments