Skip to content

Instantly share code, notes, and snippets.

@fleeto
Created November 26, 2021 09:04
Show Gist options
  • Save fleeto/11eb8792b3b96e7f7b85846e95c5f4e3 to your computer and use it in GitHub Desktop.
Save fleeto/11eb8792b3b96e7f7b85846e95c5f4e3 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import argparse
import urllib.request
import logging
import hashlib
import yaml
PLATFORMS = [
("arm64", "linux"),
("arm64", "darwin"),
("amd64", "linux"),
("amd64", "darwin")
]
PROJECT = "https://github.com/karmada-io/karmada"
URL_PATTERN = "{}/releases/download/{}/{}"
FILE_PATTERN = "kubectl-karmada-{}-{}.tgz"
parser = argparse.ArgumentParser(description='Update krew index for Karmada')
parser.add_argument('--release', '-r', required=True, help='Release name')
args = parser.parse_args()
release = args.release
file_list = []
SCHEMA = {
"apiVersion": "krew.googlecontainertools.github.com/v1alpha2",
"kind": "Plugin",
"metadata": {"name": "karmada"},
"spec": {
"version": "v0.9.0",
"homepage": PROJECT,
"shortDescription": "CLI of karmada",
"description": "Karmada: Open, Multi-Cloud, Multi-Cluster Kubernetes Orchestration",
"platforms": []
}
}
logging.getLogger().setLevel(logging.INFO)
logging.info("Updating release {}...".format(release))
for arch, os in PLATFORMS:
filename = FILE_PATTERN.format(os, arch)
logging.info("Fetching {}".format(filename))
url = URL_PATTERN.format(PROJECT, release, filename)
logging.info("From {}".format(url))
sha256_hash = hashlib.sha256()
with urllib.request.urlopen(url) as resp:
for byte_block in iter(lambda: resp.read(4096), b""):
sha256_hash.update(byte_block)
file_record = {
"files": [
{"from": "kubectl-karmada", "to": "."},
{"from": "LICENSE", "to": "."}
],
"selector": {
"matchLabels": {
"os": os,
"arch": arch
}
},
"uri": url,
"sha256": sha256_hash.hexdigest(),
"bin": "kubectl-karmada"
}
file_list.append(file_record)
SCHEMA["spec"]["platforms"] += file_list
with open("plugins/karmada.yaml", "w") as writer:
yaml.safe_dump(SCHEMA, writer)
logging.info("git add karmada.yaml\ngit commit -m '',\ngit push")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment