Skip to content

Commit d5f8960

Browse files
Fix updating Kubernetes script (#700)
1 parent 83b0218 commit d5f8960

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

.github/workflows/update-kubernetes.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,20 @@ on:
1010

1111
jobs:
1212
update-kubernetes:
13+
if: github.repository == 'kr8s-org/kr8s'
1314
runs-on: ubuntu-latest
1415
steps:
1516
- name: Checkout
1617
uses: actions/checkout@v3
1718
- name: Install uv
1819
uses: astral-sh/setup-uv@v5
1920
- name: Update Kubernetes
21+
env:
22+
# Set optional secrets for Docker Hub authentication
23+
# If not set, the script will not attempt to authenticate with Docker Hub
24+
# but may run into rate limiting errors from Docker Hub.
25+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME || '' }}
26+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN || '' }}
2027
run: uv run ./ci/update-kubernetes.py
2128
- name: Show diff
2229
id: diff

ci/update-kubernetes.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,37 @@ def extend_versions(versions, extended_versions, provider):
140140
return versions
141141

142142

143+
def dockerhub_auth():
144+
if not os.environ.get("DOCKERHUB_USERNAME") or not os.environ.get(
145+
"DOCKERHUB_TOKEN"
146+
):
147+
return None
148+
data = json.dumps(
149+
{
150+
"identifier": os.environ.get("DOCKERHUB_USERNAME"),
151+
"secret": os.environ.get("DOCKERHUB_TOKEN"),
152+
}
153+
).encode()
154+
req = urllib.request.Request(
155+
"https://hub.docker.com/v2/auth/token",
156+
data=data,
157+
headers={"Content-Type": "application/json"},
158+
)
159+
with urllib.request.urlopen(req) as resp:
160+
return json.load(resp)["access_token"]
161+
162+
143163
def get_kind_versions():
144164
print("Loading Kubernetes tags from https://hub.docker.com/r/kindest/node/tags...")
145165
container_tags = []
166+
headers = {}
167+
jwt_token = dockerhub_auth()
168+
if jwt_token:
169+
headers = {"Authorization": f"Bearer {jwt_token}"}
146170
next_url = "https://hub.docker.com/v2/repositories/kindest/node/tags"
147171
while next_url:
148-
with urllib.request.urlopen(next_url) as url:
172+
req = urllib.request.Request(next_url, headers=headers)
173+
with urllib.request.urlopen(req) as url:
149174
results = json.load(url)
150175
container_tags += results["results"]
151176
if "next" in results and results["next"]:

0 commit comments

Comments
 (0)