Skip to content

Commit

Permalink
stop auto update on images that reached their eol
Browse files Browse the repository at this point in the history
  • Loading branch information
linostar committed Feb 2, 2024
1 parent 1bd7639 commit 050f99d
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
import json
import logging
import os
from datetime import datetime

import requests
from image.utils.schema.triggers import ImageSchema
import swiftclient
import sys
import tempfile
Expand Down Expand Up @@ -65,6 +68,17 @@ def find_released_revisions(releases_json: dict) -> dict:
return released_revisions


def get_image_eol(image_schema: ImageSchema) -> dict:
"""Given an image schema, returns the eol for each version"""
eol_dict = {}

if image_schema.upload and image_schema.upload[0].release:
for version, value in image_schema.upload[0].release.items():
eol_dict[version] = value.end_of_life

return eol_dict


# Get the new Ubuntu release from the CLI args
ubuntu_release = str(sys.argv[1])
logging.info(f"Ubuntu release: {ubuntu_release}")
Expand Down Expand Up @@ -95,6 +109,12 @@ def find_released_revisions(releases_json: dict) -> dict:
logging.info(f"{image} has not been released yet. Continuing...")
continue

# retrieve the end-of-life values for image versions
with open(f"{oci_imgs_path}/{image}/image.yaml") as image_file:
image_trigger = yaml.safe_load(image_file)
image_schema = ImageSchema(**image_trigger)
revision_eols = get_image_eol(image_schema)

# Get the released revision numbers so we can get their build data
# from Swift
released_revisions = find_released_revisions(releases)
Expand Down Expand Up @@ -139,6 +159,10 @@ def find_released_revisions(releases_json: dict) -> dict:
if int(revision) not in released_revisions:
continue

# check if eol is in the past
if revision_eols[revision] < datetime.now():
continue

try:
_, build_metadata_raw = swift_conn.get_object(
SWIFT_CONTAINER, image_revision["name"]
Expand Down

0 comments on commit 050f99d

Please sign in to comment.