Skip to content

Commit bab116b

Browse files
authored
fix: correct variable references in workflow (#56)
--------- Signed-off-by: Gerard Vanloo <gerard.vanloo@ibm.com>
1 parent b235139 commit bab116b

File tree

2 files changed

+40
-42
lines changed

2 files changed

+40
-42
lines changed

.github/workflows/sre-build-push-images.yaml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ jobs:
2626
uses: docker/build-push-action@v6
2727
with:
2828
context: sre/tools/kubernetes-topology-mapper
29-
platforms:
30-
- linux/amd64
31-
- linux/arm64
29+
platforms: |
30+
linux/amd64
31+
linux/arm64
3232
push: true
33-
tags:
34-
- it-bench/topology-monitor:0.0.1
35-
- it-bench/topology-monitor:latest
33+
tags: |
34+
it-bench/topology-monitor:0.0.1
35+
it-bench/topology-monitor:latest
3636
unsupported-checkout-service:
3737
runs-on: ubuntu-latest
3838
steps:
@@ -50,19 +50,19 @@ jobs:
5050
uses: docker/build-push-action@v6
5151
with:
5252
context: sre/tools/astronomy-shop-checkout-service
53-
platforms:
54-
- linux/amd64
53+
platforms: |
54+
linux/amd64
5555
push: true
56-
tags:
57-
- it-bench/unsupported-checkout-service-amd64:0.0.1
58-
- it-bench/unsupported-checkout-service-amd64:latest
56+
tags: |
57+
it-bench/unsupported-checkout-service-amd64:0.0.1
58+
it-bench/unsupported-checkout-service-amd64:latest
5959
- name: Build and push Unsupported Astronomy Shop Checkout Service image (arm)
6060
uses: docker/build-push-action@v6
6161
with:
6262
context: sre/tools/astronomy-shop-checkout-service
63-
platforms:
64-
- linux/arm64
63+
platforms: |
64+
linux/arm64
6565
push: true
66-
tags:
67-
- it-bench/unsupported-checkout-service-arm64:0.0.1
68-
- it-bench/unsupported-checkout-service-arm64:latest
66+
tags: |
67+
it-bench/unsupported-checkout-service-arm64:0.0.1
68+
it-bench/unsupported-checkout-service-arm64:latest

sre/tools/kubernetes-topology-mapper/resource_watcher.py

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# resource_watcher.py
2-
31
import logging
42
import threading
53
import queue
@@ -33,44 +31,44 @@ def __init__(self, k8s_client, topology_manager, event_logger):
3331
self.k8s_client = k8s_client
3432
self.topology = topology_manager
3533
self.event_logger = event_logger
36-
34+
3735
self.watch_threads: Dict[str, threading.Thread] = {}
3836
self.resource_versions: Dict[str, str] = {}
3937

4038
self.stop_event = threading.Event()
41-
39+
4240
# Bounded queue to prevent unbounded growth
4341
self.event_queue = queue.Queue(maxsize=10000)
44-
42+
4543
self.processor_thread = None
46-
44+
4745
# Tuning parameters for batch refresh:
4846
self.REFRESH_EVENT_COUNT = 100 # e.g., refresh after 100 relevant events
4947
self.REFRESH_TIME_LIMIT = 30.0 # or 30 seconds
5048

5149
def start(self):
5250
"""Start the watch threads and event processor."""
5351
self.stop_event.clear()
54-
52+
5553
# Start consumer thread to process queued events
5654
self.processor_thread = threading.Thread(
57-
target=self._process_events,
58-
daemon=True,
55+
target=self._process_events,
56+
daemon=True,
5957
name="event-processor"
6058
)
6159
self.processor_thread.start()
62-
60+
6361
# Start watches for each resource type
6462
self._start_resource_watches()
6563

6664
def stop(self):
6765
"""Stop all watch threads and gracefully shut down the processor."""
6866
self.logger.info("Stopping resource watcher...")
6967
self.stop_event.set()
70-
68+
7169
# Put sentinel in the queue so _process_events will exit
7270
self.event_queue.put(None)
73-
71+
7472
# Join the processor thread
7573
if self.processor_thread:
7674
self.processor_thread.join(timeout=5)
@@ -94,12 +92,12 @@ def _start_resource_watches(self):
9492
'Pod', 'Service', 'ConfigMap', 'Secret', 'PersistentVolumeClaim',
9593
'PersistentVolume', 'Node', 'Namespace', 'ServiceAccount', 'Endpoints'
9694
}
97-
95+
9896
# Start core resources first
9997
for kind in core_resources:
10098
self._start_watch("v1", kind)
10199
time.sleep(0.5) # small delay to avoid spamming the API
102-
100+
103101
# Then watch API group resources
104102
for api_version, kind in self.k8s_client.get_api_resources():
105103
if kind not in core_resources:
@@ -109,14 +107,14 @@ def _start_resource_watches(self):
109107
def _start_watch(self, api_version: str, kind: str):
110108
"""Start a watch thread for a specific resource type."""
111109
watch_key = f"{api_version}/{kind}"
112-
110+
113111
# Avoid duplicates
114112
if watch_key in self.watch_threads:
115113
if self.watch_threads[watch_key].is_alive():
116114
return
117115
else:
118116
self.logger.info(f"Restarting dead watch thread for {kind}")
119-
117+
120118
self.logger.info(f"Starting watch for {kind}")
121119
thread = threading.Thread(
122120
target=self._watch_resource,
@@ -142,16 +140,16 @@ def _watch_resource(self, api_version: str, kind: str):
142140
try:
143141
list_response = resource.get()
144142
resource_version = list_response.metadata.resourceVersion
145-
143+
146144
watch_iter = resource.watch(resource_version=resource_version)
147145
start_time = time.time()
148146
for event in watch_iter:
149147
if self.stop_event.is_set() or (time.time() - start_time > 3600):
150148
break
151-
149+
152150
event_type = event['type']
153151
obj = event['object']
154-
152+
155153
# If queue is full, this blocks
156154
self.event_queue.put({
157155
'type': event_type,
@@ -188,10 +186,10 @@ def _get_resource_info(self, obj) -> Dict[str, Any]:
188186

189187
namespace = getattr(obj.metadata, 'namespace', '')
190188
name = getattr(obj.metadata, 'name', '')
191-
189+
192190
# Use the TopologyManager to get a stable ID (pre-existing function)
193191
stable_id = self.topology._get_stable_node_id(group, version, obj.kind, namespace, name)
194-
192+
195193
# Extract owners
196194
owners = []
197195
if getattr(obj.metadata, 'ownerReferences', None):
@@ -201,7 +199,7 @@ def _get_resource_info(self, obj) -> Dict[str, Any]:
201199
'name': ref.name,
202200
'uid': ref.uid
203201
})
204-
202+
205203
return {
206204
'kind': obj.kind,
207205
'group': group,
@@ -216,7 +214,7 @@ def _get_resource_info(self, obj) -> Dict[str, Any]:
216214
def _process_events(self):
217215
"""
218216
Main loop: pop events from the queue, log them (with ID/UID/owners),
219-
and occasionally refresh topology.
217+
and occasionally refresh topology.
220218
"""
221219
self.logger.info("Event processing thread started.")
222220

@@ -232,7 +230,7 @@ def _process_events(self):
232230
event = self.event_queue.get(timeout=1.0)
233231
except queue.Empty:
234232
continue
235-
233+
236234
if event is None:
237235
# Sentinel for shutdown
238236
break
@@ -264,7 +262,7 @@ def _process_events(self):
264262
self.logger.debug(f"Triggering refresh_topology() after "
265263
f"{events_since_last_refresh} events or {int(elapsed)}s elapsed.")
266264
self.topology.refresh_topology()
267-
265+
268266
# Reset counters
269267
last_refresh_time = now
270268
events_since_last_refresh = 0
@@ -274,4 +272,4 @@ def _process_events(self):
274272
finally:
275273
self.event_queue.task_done()
276274

277-
self.logger.info("Event processing thread exiting.")
275+
self.logger.info("Event processing thread exiting.")

0 commit comments

Comments
 (0)