This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 2ec673154fc Make helm tests even more resilient to "Too many requests" 
(#50029)
2ec673154fc is described below

commit 2ec673154fc7f8bd28adcbbaeda1fe2d711e71da
Author: Jarek Potiuk <[email protected]>
AuthorDate: Wed Apr 30 19:54:30 2025 +0200

    Make helm tests even more resilient to "Too many requests" (#50029)
    
    The helm tests are now:
    
    * caching more
    * using GITHUB_TOKEN (already present in the CI job) to authenticate
      the requests to GitHub URLs
---
 .../tests/chart_utils/helm_template_generator.py      | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/helm-tests/tests/chart_utils/helm_template_generator.py 
b/helm-tests/tests/chart_utils/helm_template_generator.py
index 0a054439732..3dd33fdbcfe 100644
--- a/helm-tests/tests/chart_utils/helm_template_generator.py
+++ b/helm-tests/tests/chart_utils/helm_template_generator.py
@@ -17,6 +17,7 @@
 from __future__ import annotations
 
 import json
+import os
 import subprocess
 from functools import cache
 from io import StringIO
@@ -47,6 +48,10 @@ crd_lookup = {
 }
 
 
+GITHUB_TOKEN = os.environ.get("GITHUB_TOKEN", "")
+
+
+@cache
 def get_schema_k8s(api_version, kind, kubernetes_version):
     api_version = api_version.lower()
     kind = kind.lower()
@@ -57,7 +62,12 @@ def get_schema_k8s(api_version, kind, kubernetes_version):
         url = f"{BASE_URL_SPEC}/{kind}-{ext}-{api_version}.json"
     else:
         url = f"{BASE_URL_SPEC}/{kind}-{api_version}.json"
-    request = requests.get(url)
+
+    headers = {}
+    if GITHUB_TOKEN:
+        headers["Authorization"] = f"Bearer {GITHUB_TOKEN}"
+        headers["X-GitHub-Api-Version"] = "2022-11-28"
+    request = requests.get(url, headers=headers)
     request.raise_for_status()
     schema = json.loads(
         request.text.replace(
@@ -67,11 +77,16 @@ def get_schema_k8s(api_version, kind, kubernetes_version):
     return schema
 
 
+@cache
 def get_schema_crd(api_version, kind):
     url = crd_lookup.get(f"{api_version}::{kind}")
     if not url:
         return None
-    response = requests.get(url)
+    headers = {}
+    if GITHUB_TOKEN:
+        headers["Authorization"] = f"Bearer {GITHUB_TOKEN}"
+        headers["X-GitHub-Api-Version"] = "2022-11-28"
+    response = requests.get(url, headers=headers)
     yaml_schema = response.content.decode("utf-8")
     schema = yaml.safe_load(StringIO(yaml_schema))
     return schema

Reply via email to