@@ -31,16 +31,12 @@ import mu.KotlinLogging
3131class PodRetriever (private val client : NamespacedKubernetesClient ) {
3232
3333 private val logger = KotlinLogging .logger {}
34- private val informers = mutableMapOf <String , SharedIndexInformer < Pod > >()
34+ private val namespaces = HashSet <String >()
3535
3636 fun addNamespace (namespace : String ) {
37- if (informers.containsKey (namespace)) {
38- return
37+ if (namespaces.add (namespace)) {
38+ logger.warn { " Now watching pods in the $namespace namespace. (total count = ${namespaces.size} ) " }
3939 }
40-
41- val informer = client.pods().inNamespace(namespace).withLabels(mapOf (LabelFactory .PROXIED_APP to " true" )).inform(null , 10 * 60 * 1000 .toLong())
42- informers[namespace] = informer
43- logger.warn { " Now watching pods in the $namespace namespace. (total count = ${informers.size} )" }
4440 }
4541
4642 fun getPodsForShinyProxyInstance (shinyProxy : ShinyProxy , shinyProxyInstance : ShinyProxyInstance ): List <Pod > {
@@ -56,26 +52,16 @@ class PodRetriever(private val client: NamespacedKubernetesClient) {
5652 // We don't know the exact namespaces used by older ShinyProxyInstance, therefore we have to look into all namespaces.
5753 // We could save the list of namespaces in the status of the instance, if it turns out this is a performance bottleneck.
5854 // Note: that currently this function is only called for older SP instances and thus this else statement is actually always executed...
59- informers.keys
55+ namespaces
6056 }
6157
6258 logger.debug { " Looking for Pods managed by ${shinyProxyInstance.hashOfSpec} using $labels in $namespacesToCheck " }
6359
6460 for (namespace in namespacesToCheck) {
65- val informer = informers[namespace]
66- if (informer == null ) {
67- logger.warn { " Looking for pods in $namespace but no informer found!" }
68- continue
69- }
70-
71- for (pod in informer.indexer.list()) {
72- if (pod?.metadata?.labels?.entries?.containsAll(labels.entries) == true ) {
73- pods.add(pod)
74- }
75- }
61+ pods.addAll(client.pods().inNamespace(namespace).withLabels(labels).list().items)
7662 }
7763
78- logger.info { " PodCount: ${pods.size} , ${pods.map { it.metadata.name }} " }
64+ logger.info { " PodCount: ${pods.size} , ${pods.map { it.metadata.namespace + " / " + it.metadata. name }} " }
7965 return pods
8066 }
8167
@@ -84,7 +70,7 @@ class PodRetriever(private val client: NamespacedKubernetesClient) {
8470 }
8571
8672 fun getNamespaces (): Set <String > {
87- return informers.keys
73+ return namespaces
8874 }
8975
9076 fun stop () {
0 commit comments