|
6 | 6 | # Example of policy.yaml
|
7 | 7 | # rawhide:
|
8 | 8 | # # all cloud images
|
9 |
| -# cloud-uploads: 2 years |
| 9 | +# cloud-uploads: 2y |
10 | 10 | # # artifacts in meta.json's `images` key
|
11 |
| -# images: 2 years |
| 11 | +# images: 2y |
12 | 12 | # images-keep: [qemu, live-iso]
|
13 |
| -# build: 3 years |
| 13 | +# build: 3y |
| 14 | +# containers: 2w |
14 | 15 | # The script also updates the builds.json for the respective stream by
|
15 | 16 | # adding the policy-cleanup key when we set the upload_builds_json flag.
|
16 | 17 | # It adds the relevant actions completed to that key
|
@@ -44,7 +45,8 @@ from cosalib.gcp import remove_gcp_image
|
44 | 45 | from cosalib.aws import deregister_aws_resource
|
45 | 46 | from cosalib.builds import BUILDFILES
|
46 | 47 | from cosalib.s3 import s3_copy
|
47 |
| -from cosalib.cmdlib import parse_fcos_version_to_timestamp |
| 48 | +from cosalib.cmdlib import parse_fcos_version_to_timestamp_and_stream |
| 49 | +from cosalib.cmdlib import convert_duration_to_days |
48 | 50 |
|
49 | 51 | Build = collections.namedtuple("Build", ["id", "images", "arch", "meta_json"])
|
50 | 52 | # set metadata caching to 5m
|
@@ -105,17 +107,17 @@ def main():
|
105 | 107 | for action in ['cloud-uploads', 'images', 'build']:
|
106 | 108 | if action not in policy[stream]:
|
107 | 109 | continue
|
108 |
| - duration = get_period_in_months(policy[stream][action]) |
109 |
| - ref_date = today_date - relativedelta(months=int(duration)) |
| 110 | + duration = convert_duration_to_days(policy[stream][action]) |
| 111 | + ref_date = today_date - relativedelta(days=int(duration)) |
110 | 112 |
|
111 |
| - print(f"Pruning resources of type {action} older than {duration} months ({ref_date.date()}) on stream {stream}") |
| 113 | + print(f"Pruning resources of type {action} older than {policy[stream][action]} ({ref_date.date()}) on stream {stream}") |
112 | 114 | # Enumerating in reverse to go from the oldest build to the newest one
|
113 | 115 | for index, build in enumerate(reversed(builds_json_data["builds"])):
|
114 | 116 | build_id = build["id"]
|
115 | 117 | if action in build.get("policy-cleanup", []):
|
116 | 118 | print(f"Build {build_id} has already had {action} pruning completed")
|
117 | 119 | continue
|
118 |
| - build_date = parse_fcos_version_to_timestamp(build_id) |
| 120 | + (build_date, _) = parse_fcos_version_to_timestamp_and_stream(build_id) |
119 | 121 |
|
120 | 122 | if build_date >= ref_date:
|
121 | 123 | break
|
@@ -172,8 +174,8 @@ def validate_policy(stream, policy):
|
172 | 174 | actions = policy[stream]
|
173 | 175 | if 'cloud-uploads' not in actions:
|
174 | 176 | raise Exception("Pruning for cloud-uploads must be set before we prune the builds")
|
175 |
| - cloud_uploads_duration = get_period_in_months(actions["cloud-uploads"]) |
176 |
| - build_duration = get_period_in_months(actions["build"]) |
| 177 | + cloud_uploads_duration = convert_duration_to_days(actions["cloud-uploads"]) |
| 178 | + build_duration = convert_duration_to_days(actions["build"]) |
177 | 179 | if cloud_uploads_duration > build_duration:
|
178 | 180 | raise Exception("Duration of pruning cloud-uploads must be less than or equal to pruning a build")
|
179 | 181 |
|
@@ -286,15 +288,5 @@ def delete_gcp_image(build, cloud_config, dry_run):
|
286 | 288 | return errors
|
287 | 289 |
|
288 | 290 |
|
289 |
| -def get_period_in_months(duration): |
290 |
| - val, unit = duration.split(maxsplit=1) |
291 |
| - if unit in ["years", "year", "y"]: |
292 |
| - return int(val) * 12 |
293 |
| - elif unit in ["months", "month", "m"]: |
294 |
| - return int(val) |
295 |
| - else: |
296 |
| - raise Exception(f"Duration unit provided is {unit}. Pruning duration is only supported in years and months") |
297 |
| - |
298 |
| - |
299 | 291 | if __name__ == "__main__":
|
300 | 292 | main()
|
0 commit comments