Bug 1648602: Allow configuring lifecycle rules for workerpools r=tomprince
authorBrian Stack <bstack@mozilla.com>
Fri, 26 Jun 2020 22:46:26 +0000
changeset 240 725e7504edd7b4f877183014e8b478a032838792
parent 239 898b0c1836f6fe9d04722d3276385de3113efbc5
child 241 d9b5a853cb96d9dff94f2a3932866ea3195ec480
push id175
push usermozilla@hocat.ca
push dateMon, 29 Jun 2020 17:32:52 +0000
treeherderci-admin@725e7504edd7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstomprince
bugs1648602
Bug 1648602: Allow configuring lifecycle rules for workerpools r=tomprince Differential Revision: https://phabricator.services.mozilla.com/D81193
src/ciadmin/generate/worker_pools.py
--- a/src/ciadmin/generate/worker_pools.py
+++ b/src/ciadmin/generate/worker_pools.py
@@ -60,16 +60,18 @@ def get_aws_provider_config(
     security = config.pop("security", "untrusted")
     spot = config.pop("spot", True)
     user_data = config.pop("additional-user-data", {})
     implementation = config.pop("implementation", "docker-worker")
 
     defaults = evaluate_keyed_by(defaults, "defaults", {"provider": provider_id})
     aws_config = environment.aws_config
 
+    lifecycle = merge(defaults.get("lifecycle", {}), config.pop("lifecycle", {}))
+
     worker_config = evaluate_keyed_by(
         defaults.get("worker-config", {}), pool_id, {"implementation": implementation},
     )
     worker_config = merge(worker_config, config.get("worker-config", {}))
 
     _validate_instance_capacity(pool_id, implementation, instance_types)
 
     launch_configs = []
@@ -124,31 +126,34 @@ def get_aws_provider_config(
                     launch_config["launchConfig"]["InstanceMarketOptions"] = {
                         "MarketType": "spot"
                     }
                 launch_configs.append(launch_config)
 
     return {
         "minCapacity": config.get("minCapacity", 0),
         "maxCapacity": config["maxCapacity"],
+        "lifecycle": lifecycle,
         "launchConfigs": launch_configs,
     }
 
 
 def get_google_provider_config(
     environment, provider_id, pool_id, config, worker_images, defaults
 ):
     regions = config.pop("regions")
     image = worker_images[config["image"]]
     instance_types = config["instance_types"]
     implementation = config.pop("implementation", "docker-worker")
 
     defaults = evaluate_keyed_by(defaults, "defaults", {"provider": provider_id})
     google_config = environment.google_config
 
+    lifecycle = merge(defaults.get("lifecycle", {}), config.pop("lifecycle", {}))
+
     worker_config = evaluate_keyed_by(
         defaults.get("worker-config", {}), pool_id, {"implementation": implementation},
     )
     worker_config = merge(worker_config, config.get("worker-config", {}))
 
     image_name = image.image_id(provider_id)
 
     _validate_instance_capacity(pool_id, implementation, instance_types)
@@ -180,16 +185,17 @@ def get_google_provider_config(
                     "automaticRestart": False,
                     "preemptible": True,
                 }
                 launch_configs.append(launch_config)
 
     return {
         "minCapacity": config.get("minCapacity", 0),
         "maxCapacity": config["maxCapacity"],
+        "lifecycle": lifecycle,
         "launchConfigs": launch_configs,
     }
 
 
 PROVIDER_IMPLEMENTATIONS = {
     "aws": get_aws_provider_config,
     "google": get_google_provider_config,
 }