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

potiuk pushed a commit to branch v3-0-test
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/v3-0-test by this push:
     new 5bc5637a2b0 [v3-0-test] Make helm tests even more resilient to "Too 
many requests" (#50029) (#50043)
5bc5637a2b0 is described below

commit 5bc5637a2b0774ec5956a0b3f8535d4c2f21c8db
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Thu May 1 00:17:42 2025 +0200

    [v3-0-test] Make helm tests even more resilient to "Too many requests" 
(#50029) (#50043)
    
    The helm tests are now:
    
    * caching more
    * using GITHUB_TOKEN (already present in the CI job) to authenticate
      the requests to GitHub URLs
    (cherry picked from commit 2ec673154fc7f8bd28adcbbaeda1fe2d711e71da)
    
    Co-authored-by: Jarek Potiuk <[email protected]>
---
 .../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