|
| 1 | +#!/usr/bin/env -S uv run --script |
| 2 | +# /// script |
| 3 | +# requires-python = ">=3.9" |
| 4 | +# dependencies = ["ruamel.yaml"] |
| 5 | +# /// |
| 6 | +"""Check EKS Kubernetes version lifecycle using the official AWS EKS docs source. |
| 7 | +
|
| 8 | +Primary source: awsdocs/amazon-eks-user-guide raw AsciiDoc on GitHub |
| 9 | +Cross-verify: https://endoflife.date/api/amazon-eks.json |
| 10 | +""" |
| 11 | + |
| 12 | +from __future__ import annotations |
| 13 | + |
| 14 | +import argparse |
| 15 | +import json |
| 16 | +import re |
| 17 | +import sys |
| 18 | +import urllib.error |
| 19 | +import urllib.request |
| 20 | +from datetime import datetime, timezone |
| 21 | + |
| 22 | +from rhdh_lifecycle.configured_versions import print_configured_versions |
| 23 | +from rhdh_lifecycle.repo import resolve_repo_root |
| 24 | +from rhdh_lifecycle.utils import fetch_json, filter_supported_eol_entries |
| 25 | + |
| 26 | +EKS_DOCS_URL = ( |
| 27 | + "https://raw.githubusercontent.com/awsdocs/amazon-eks-user-guide" |
| 28 | + "/mainline/latest/ug/versioning/kubernetes-versions.adoc" |
| 29 | +) |
| 30 | +EOL_API_URL = "https://endoflife.date/api/amazon-eks.json" |
| 31 | +CONFIG_DIR = "ci-operator/config/redhat-developer/rhdh" |
| 32 | + |
| 33 | + |
| 34 | +def fetch_text(url): |
| 35 | + """Fetch text content from a URL.""" |
| 36 | + req = urllib.request.Request(url, headers={"User-Agent": "rhdh-skill"}) |
| 37 | + try: |
| 38 | + with urllib.request.urlopen(req, timeout=30) as resp: |
| 39 | + return resp.read().decode("utf-8") |
| 40 | + except (urllib.error.URLError, OSError) as exc: |
| 41 | + print(f"ERROR: Failed to fetch {url}: {exc}", file=sys.stderr) |
| 42 | + return None |
| 43 | + |
| 44 | + |
| 45 | +def parse_supported_versions(docs): |
| 46 | + """Extract supported versions and their tiers from the AsciiDoc.""" |
| 47 | + section = "" |
| 48 | + versions = [] |
| 49 | + for line in docs.splitlines(): |
| 50 | + if "Available versions on standard support" in line: |
| 51 | + section = "Standard" |
| 52 | + elif "Available versions on extended support" in line: |
| 53 | + section = "Extended" |
| 54 | + elif "Amazon EKS Kubernetes release calendar" in line: |
| 55 | + section = "" |
| 56 | + elif section and re.match(r"^\* `\d+\.\d+`$", line): |
| 57 | + ver = line.strip("* `\n") |
| 58 | + versions.append((ver, section)) |
| 59 | + return versions |
| 60 | + |
| 61 | + |
| 62 | +def parse_release_calendar(docs): |
| 63 | + """Extract the release calendar table from the AsciiDoc.""" |
| 64 | + lines = docs.splitlines() |
| 65 | + in_table = False |
| 66 | + entries = [] |
| 67 | + i = 0 |
| 68 | + while i < len(lines): |
| 69 | + line = lines[i] |
| 70 | + if line.strip() == "|===": |
| 71 | + in_table = not in_table |
| 72 | + i += 1 |
| 73 | + continue |
| 74 | + if in_table and re.match(r"^\|`\d+\.\d+`", line): |
| 75 | + # Next 4 lines are: upstream, eks_release, end_std, end_ext |
| 76 | + version = line.lstrip("|").strip("`").strip() |
| 77 | + fields = [] |
| 78 | + for j in range(1, 5): |
| 79 | + if i + j < len(lines): |
| 80 | + fields.append(lines[i + j].lstrip("|").strip()) |
| 81 | + else: |
| 82 | + fields.append("N/A") |
| 83 | + entries.append((version, *fields)) |
| 84 | + i += 5 |
| 85 | + continue |
| 86 | + i += 1 |
| 87 | + return entries |
| 88 | + |
| 89 | + |
| 90 | +def main(argv=None): |
| 91 | + parser = argparse.ArgumentParser(description="Check EKS K8s version lifecycle.") |
| 92 | + parser.add_argument("--mapt-ref", help="Path to MAPT ref YAML (repo-relative)") |
| 93 | + parser.add_argument("--test-pattern", help="Regex to match test names") |
| 94 | + parser.add_argument("--config-dir", default=CONFIG_DIR, help="CI config directory") |
| 95 | + parser.add_argument("--repo-dir", help="Path to openshift/release checkout") |
| 96 | + parser.add_argument("--json", dest="json_output", action="store_true", help="Output as JSON") |
| 97 | + args = parser.parse_args(argv) |
| 98 | + |
| 99 | + root, is_remote = resolve_repo_root(args.repo_dir) |
| 100 | + |
| 101 | + # Print configured versions if test pattern provided |
| 102 | + if args.test_pattern and not args.json_output: |
| 103 | + print_configured_versions( |
| 104 | + args.config_dir, args.test_pattern, root, is_remote, args.mapt_ref |
| 105 | + ) |
| 106 | + |
| 107 | + # Fetch EKS docs source (primary) |
| 108 | + docs = fetch_text(EKS_DOCS_URL) |
| 109 | + if not docs: |
| 110 | + sys.exit(1) |
| 111 | + |
| 112 | + versions = parse_supported_versions(docs) |
| 113 | + calendar = parse_release_calendar(docs) |
| 114 | + |
| 115 | + # Cross-verify with endoflife.date |
| 116 | + today = datetime.now(timezone.utc).strftime("%Y-%m-%d") |
| 117 | + eol_data = fetch_json(EOL_API_URL) |
| 118 | + eol_supported = filter_supported_eol_entries(eol_data, today) if eol_data else [] |
| 119 | + |
| 120 | + # JSON output |
| 121 | + if args.json_output: |
| 122 | + result = { |
| 123 | + "versions": [{"version": ver, "tier": tier} for ver, tier in versions], |
| 124 | + "calendar": [ |
| 125 | + { |
| 126 | + "version": e[0], |
| 127 | + "upstream_release": e[1], |
| 128 | + "eks_release": e[2], |
| 129 | + "end_standard": e[3], |
| 130 | + "end_extended": e[4], |
| 131 | + } |
| 132 | + for e in calendar |
| 133 | + ], |
| 134 | + "endoflife_date": [ |
| 135 | + { |
| 136 | + "version": e["cycle"], |
| 137 | + "eol": str(e.get("eol", "N/A")), |
| 138 | + "extended_support": str(e.get("extendedSupport", "N/A")), |
| 139 | + } |
| 140 | + for e in eol_supported |
| 141 | + ], |
| 142 | + } |
| 143 | + json.dump(result, sys.stdout, indent=2) |
| 144 | + print() |
| 145 | + return |
| 146 | + |
| 147 | + # Human-readable output |
| 148 | + print("=== EKS Version Support (awsdocs/amazon-eks-user-guide) ===") |
| 149 | + print("Supported minor versions:") |
| 150 | + for ver, tier in versions: |
| 151 | + print(f" {ver:<8s} {tier}") |
| 152 | + |
| 153 | + print() |
| 154 | + print("Release calendar:") |
| 155 | + print( |
| 156 | + f" {'VERSION':<8s} {'UPSTREAM RELEASE':<22s} {'EKS RELEASE':<22s} " |
| 157 | + f"{'END STANDARD':<22s} {'END EXTENDED':<22s}" |
| 158 | + ) |
| 159 | + print( |
| 160 | + f" {'-------':<8s} {'----------------':<22s} {'-----------':<22s} " |
| 161 | + f"{'------------':<22s} {'------------':<22s}" |
| 162 | + ) |
| 163 | + for entry in calendar: |
| 164 | + ver, upstream, eks_rel, end_std, end_ext = entry |
| 165 | + print(f" {ver:<8s} {upstream:<22s} {eks_rel:<22s} {end_std:<22s} {end_ext:<22s}") |
| 166 | + |
| 167 | + print() |
| 168 | + print("=== Cross-verify (endoflife.date) ===") |
| 169 | + if not eol_data: |
| 170 | + print("WARNING: Failed to fetch endoflife.date", file=sys.stderr) |
| 171 | + return |
| 172 | + for entry in eol_supported: |
| 173 | + ext = entry.get("extendedSupport", "N/A") |
| 174 | + print(f" {entry['cycle']}\tEOL: {entry.get('eol', 'N/A')}\tExtended: {ext}") |
| 175 | + |
| 176 | + |
| 177 | +if __name__ == "__main__": |
| 178 | + main() |
0 commit comments