Skip to content

Commit

Permalink
Merge pull request #629 from kubescape/fix_validator
Browse files Browse the repository at this point in the history
feat: Order Kubernetes releases by publication date
  • Loading branch information
kooomix authored Jul 21, 2024
2 parents 11e87a6 + f45ab40 commit a9da72c
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions scripts/validations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from operator import itemgetter
import os
import re
import requests
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a9da72c

Please sign in to comment.