|
11 | 11 | import java.util.function.ToDoubleFunction; |
12 | 12 | import java.util.stream.Collectors; |
13 | 13 |
|
| 14 | +import org.jboss.logging.Logger; |
| 15 | + |
14 | 16 | import io.fabric8.kubernetes.api.model.Pod; |
15 | 17 | import io.fabric8.kubernetes.api.model.PodList; |
16 | 18 | import io.fabric8.kubernetes.api.model.Quantity; |
|
24 | 26 | import io.micrometer.core.instrument.Tags; |
25 | 27 |
|
26 | 28 | class PodWatcher implements Watcher<Pod> { |
| 29 | + private static final Logger LOG = Logger.getLogger(PodWatcher.class); |
| 30 | + |
27 | 31 | private final KubernetesClient client; |
28 | 32 | private final MeterRegistry meterRegistry; |
29 | 33 | private final OperatorConfig config; |
@@ -56,6 +60,7 @@ static Map<String, String> convertListToMap(List<String> productNameMapAsList) { |
56 | 60 |
|
57 | 61 | @Override |
58 | 62 | public void eventReceived(Action action, Pod resource) { |
| 63 | + LOG.info("EVENT RECEIVED FOR POD: " + resource.getMetadata().getName()); |
59 | 64 | if (!shouldWatch(spec.getWatchNamespaces(), resource.getMetadata().getNamespace())) { |
60 | 65 | // If we're not watching all namespaces or the event is from a namespace we're not watching, do nothing |
61 | 66 | return; |
@@ -113,7 +118,8 @@ public void onClose(WatcherException cause) { |
113 | 118 | } |
114 | 119 |
|
115 | 120 | Boolean shouldWatch(Set<String> watchingNamespaces, String namespace) { |
116 | | - return watchingNamespaces.isEmpty() || watchingNamespaces.contains(namespace); |
| 121 | + return watchingNamespaces.isEmpty() || watchingNamespaces.contains(namespace) |
| 122 | + || watchingNamespaces.contains(""); |
117 | 123 | } |
118 | 124 |
|
119 | 125 | static Boolean isInfrastructure(OperatorConfig config, Map<String, String> podLabels) { |
@@ -150,7 +156,7 @@ void updateSpec(MeterSpec newSpec) { |
150 | 156 |
|
151 | 157 | PodList pods = client.pods().inAnyNamespace().list(); |
152 | 158 | for (Pod pod : pods.getItems()) { |
153 | | - if (!(newSpec.getWatchNamespaces().isEmpty() || newSpec.getWatchNamespaces().contains(pod.getMetadata().getNamespace()))) { |
| 159 | + if (!shouldWatch(newSpec.getWatchNamespaces(), pod.getMetadata().getNamespace())) { |
154 | 160 | // If we're not watching all namespaces or the event is from a namespace we're not watching, do nothing |
155 | 161 | continue; |
156 | 162 | } |
@@ -187,6 +193,8 @@ String watchedPods() { |
187 | 193 | for (PodGroup podGroup : metrics.values()) { |
188 | 194 | count += podGroup.pods.size(); |
189 | 195 | } |
| 196 | + //TODO remove |
| 197 | + System.out.println("NUMBER OF WATCHED PODS: " + count); |
190 | 198 | return Integer.toString(count); |
191 | 199 | } |
192 | 200 |
|
|
0 commit comments