Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use chart-release to manage index updates #1082

Open
mgoerens opened this issue Oct 10, 2023 · 1 comment
Open

Use chart-release to manage index updates #1082

mgoerens opened this issue Oct 10, 2023 · 1 comment

Comments

@mgoerens
Copy link
Contributor

Currently we update the index.yaml with a series of git commands:

def update_index_and_push(
indexfile,
indexdir,
repository,
branch,
category,
organization,
chart,
version,
chart_url,
chart_entry,
pr_number,
web_catalog_only,
):
token = os.environ.get("GITHUB_TOKEN")
print(f"Downloading {indexfile}")
r = requests.get(
f"https://raw.githubusercontent.com/{repository}/{branch}/{indexfile}"
)
original_etag = r.headers.get("etag")
now = datetime.now(timezone.utc).astimezone().isoformat()
if r.status_code == 200:
data = yaml.load(r.text, Loader=Loader)
data["generated"] = now
else:
data = {"apiVersion": "v1", "generated": now, "entries": {}}
print("[INFO] Updating the chart entry with new version")
crtentries = []
entry_name = os.environ.get("CHART_ENTRY_NAME")
if not entry_name:
print("[ERROR] Internal error: missing chart entry name")
sys.exit(1)
d = data["entries"].get(entry_name, [])
for v in d:
if v["version"] == version:
continue
crtentries.append(v)
chart_entry["urls"] = [chart_url]
if not web_catalog_only:
set_package_digest(chart_entry)
chart_entry["annotations"]["charts.openshift.io/submissionTimestamp"] = now
crtentries.append(chart_entry)
data["entries"][entry_name] = crtentries
print("[INFO] Add and commit changes to git")
out = yaml.dump(data, Dumper=Dumper)
print(f"{indexfile} content:\n", out)
with open(os.path.join(indexdir, indexfile), "w") as fd:
fd.write(out)
old_cwd = os.getcwd()
os.chdir(indexdir)
out = subprocess.run(["git", "status"], cwd=indexdir, capture_output=True)
print("Git status:")
print(out.stdout.decode("utf-8"))
print(out.stderr.decode("utf-8"))
out = subprocess.run(
["git", "add", os.path.join(indexdir, indexfile)],
cwd=indexdir,
capture_output=True,
)
print(out.stdout.decode("utf-8"))
err = out.stderr.decode("utf-8")
if err.strip():
print(
f"Error adding {indexfile} to git staging area",
"index directory",
indexdir,
"branch",
branch,
)
out = subprocess.run(["git", "status"], cwd=indexdir, capture_output=True)
print("Git status:")
print(out.stdout.decode("utf-8"))
print(out.stderr.decode("utf-8"))
out = subprocess.run(
[
"git",
"commit",
"-m",
f"{organization}-{chart}-{version} {indexfile} (#{pr_number})",
],
cwd=indexdir,
capture_output=True,
)
print(out.stdout.decode("utf-8"))
err = out.stderr.decode("utf-8")
if err.strip():
print(
f"Error committing {indexfile}",
"index directory",
indexdir,
"branch",
branch,
"error:",
err,
)
r = requests.head(
f"https://raw.githubusercontent.com/{repository}/{branch}/{indexfile}"
)
etag = r.headers.get("etag")
if original_etag and etag and (original_etag != etag):
print(
f"{indexfile} not updated. ETag mismatch.",
"original ETag",
original_etag,
"new ETag",
etag,
"index directory",
indexdir,
"branch",
branch,
)
sys.exit(1)
out = subprocess.run(["git", "status"], cwd=indexdir, capture_output=True)
print("Git status:")
print(out.stdout.decode("utf-8"))
print(out.stderr.decode("utf-8"))
out = subprocess.run(
[
"git",
"push",
f"https://x-access-token:{token}@github.com/{repository}",
f"HEAD:refs/heads/{branch}",
"-f",
],
cwd=indexdir,
capture_output=True,
)
print(out.stdout.decode("utf-8"))
print(out.stderr.decode("utf-8"))
if out.returncode:
print(
f"{indexfile} not updated. Push failed.",
"index directory",
indexdir,
"branch",
branch,
)
sys.exit(1)
os.chdir(old_cwd)

chart-releaser provides a way to update an index, see https://github.com/helm/chart-releaser/blob/main/doc/cr_index.md

We should make use of it, via a dedicated action, see https://github.com/helm/chart-releaser-action

@komish
Copy link
Collaborator

komish commented Oct 10, 2023

I believe we already use chart-releaser for some things in the pipeline.

It's worth noting that the helm repo index command also exists for this purpose.

I'm thinking part of the reason why this is done manually is because there are extra annotations that exist in our index entries that may not exist in the charts. Specifically, annotations that correspond with experience improvements within the Developer Hub UX. Don't quote me on it, but I could spend some time at some point looking for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants