From f45ab4018031d4c7df0544642d9a471aac464860 Mon Sep 17 00:00:00 2001 From: kooomix Date: Sun, 21 Jul 2024 15:25:39 +0300 Subject: [PATCH] feat: Order Kubernetes releases by publication date This commit modifies the `get_kubernetes_supported_versions` function in `validations.py` to order the releases by their publication date. This ensures that the supported versions are listed in the correct chronological order. Additionally, the commit limits the number of supported versions to 5 instead of 3, as smaller versions might have updates after the latest major.minor version. The function then returns the top 3 versions in descending order. Note: This commit message follows the established convention of starting with a type prefix (feat for feature) and providing a concise and descriptive summary of the changes made. Signed-off-by: kooomix --- scripts/validations.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/scripts/validations.py b/scripts/validations.py index abfe74564..7cdb59721 100644 --- a/scripts/validations.py +++ b/scripts/validations.py @@ -1,4 +1,5 @@ import json +from operator import itemgetter import os import re import requests @@ -162,20 +163,33 @@ def get_kubernetes_supported_versions(): raise Exception("Failed to fetch Kubernetes releases") from e releases = response.json() + + # Order the releases by publication date + ordered_releases = sorted(releases, key=itemgetter('created_at'), reverse=True) + supported_versions = [] - for release in releases: + for release in ordered_releases: if not release['draft'] and not release['prerelease']: tag_name = release['tag_name'] if all(x not in tag_name for x in ['alpha', 'beta', 'rc']): major_minor_version = '.'.join(tag_name.lstrip('v').split('.')[:2]) if major_minor_version not in supported_versions: supported_versions.append(major_minor_version) - if len(supported_versions) == 3: + + # we are taking 5 since smaller versions might have updates after the latest major.minor version + if len(supported_versions) == 5: break if not supported_versions: raise Exception("No supported Kubernetes versions found.") - return supported_versions + + # Sort the versions in descending order as strings + sorted_versions = sorted(supported_versions, reverse=True) + + # Get the top 3 versions + top_3_versions = sorted_versions[:3] + + return top_3_versions def validate_k8s_supported_versions_in_rego(): # Step 1: Get the latest supported Kubernetes versions