summaryrefslogtreecommitdiff
path: root/armada/handlers/wait.py
diff options
context:
space:
mode:
Diffstat (limited to 'armada/handlers/wait.py')
-rw-r--r--armada/handlers/wait.py41
1 files changed, 40 insertions, 1 deletions
diff --git a/armada/handlers/wait.py b/armada/handlers/wait.py
index a131265..7a27945 100644
--- a/armada/handlers/wait.py
+++ b/armada/handlers/wait.py
@@ -148,6 +148,16 @@ class ResourceWait(ABC):
148 ''' 148 '''
149 pass 149 pass
150 150
151 def include_resource(self, resource):
152 '''
153 Test to include or exclude a resource in a wait operation. This method
154 can be used to exclude resources that should not be included in wait
155 operations (e.g. test pods).
156 :param resource: resource to test
157 :returns: boolean representing test result
158 '''
159 return True
160
151 def handle_resource(self, resource): 161 def handle_resource(self, resource):
152 resource_name = resource.metadata.name 162 resource_name = resource.metadata.name
153 163
@@ -259,7 +269,9 @@ class ResourceWait(ABC):
259 269
260 resource_list = self.get_resources(**kwargs) 270 resource_list = self.get_resources(**kwargs)
261 for resource in resource_list.items: 271 for resource in resource_list.items:
262 ready[resource.metadata.name] = self.handle_resource(resource) 272 # Only include resources that should be included in wait ops
273 if self.include_resource(resource):
274 ready[resource.metadata.name] = self.handle_resource(resource)
263 if not resource_list.items: 275 if not resource_list.items:
264 if self.skip_if_none_found: 276 if self.skip_if_none_found:
265 msg = 'Skipping wait, no %s resources found.' 277 msg = 'Skipping wait, no %s resources found.'
@@ -279,6 +291,11 @@ class ResourceWait(ABC):
279 resource = event['object'] 291 resource = event['object']
280 resource_name = resource.metadata.name 292 resource_name = resource.metadata.name
281 resource_version = resource.metadata.resource_version 293 resource_version = resource.metadata.resource_version
294
295 # Skip resources that should be excluded from wait operations
296 if not self.include_resource(resource):
297 continue
298
282 msg = ('Watch event: type=%s, name=%s, namespace=%s,' 299 msg = ('Watch event: type=%s, name=%s, namespace=%s,'
283 'resource_version=%s') 300 'resource_version=%s')
284 LOG.debug(msg, event_type, resource_name, 301 LOG.debug(msg, event_type, resource_name,
@@ -330,6 +347,28 @@ class PodWait(ResourceWait):
330 resource_type, chart_wait, labels, 347 resource_type, chart_wait, labels,
331 chart_wait.k8s.client.list_namespaced_pod, **kwargs) 348 chart_wait.k8s.client.list_namespaced_pod, **kwargs)
332 349
350 def include_resource(self, resource):
351 pod = resource
352 annotations = pod.metadata.annotations
353
354 # Retrieve pod's Helm test hooks
355 test_hooks = None
356 if annotations:
357 hook_string = annotations.get(const.HELM_HOOK_ANNOTATION)
358 if hook_string:
359 hooks = hook_string.split(',')
360 test_hooks = [h for h in hooks if h in const.HELM_TEST_HOOKS]
361
362 # NOTE(drewwalters96): Test pods may cause wait operations to fail
363 # when old resources remain from previous upgrades/tests. Indicate that
364 # test pods should not be included in wait operations.
365 if test_hooks:
366 LOG.debug('Pod %s will be skipped during wait operations.',
367 pod.metadata.name)
368 return False
369 else:
370 return True
371
333 def is_resource_ready(self, resource): 372 def is_resource_ready(self, resource):
334 pod = resource 373 pod = resource
335 name = pod.metadata.name 374 name = pod.metadata.name