ori-edge / k8s_gateway

A CoreDNS plugin to resolve all types of external Kubernetes resources
Apache License 2.0
289 stars 61 forks source link

Avoid changing all chart timestamps when updating Helm index #258

Closed dnrce closed 5 months ago

dnrce commented 5 months ago

When attempting to update the chart index in #256, I noticed that make helm-update completely rebuilds the Helm index file and updates the timestamp of every release, including existing ones. It's pretty insignificant, but it makes for a larger diff on chart updates so I wondered whether there was a good solution.

It turns out this is a known limitation in Helm (https://github.com/helm/helm/issues/7363) but can be solved pretty easily by isolating the new chart when computing the updated index, and then merging the existing index.

For completeness I then updated the index with the correct, earliest timestamp for each version, based on the current digest. (A few versions had been updated in place over time.)

for digest in $(yq '.entries."k8s-gateway"[].digest' index.yaml); do
  sha=$(git log --format=format:%H -S$digest index.yaml)
  timestamp=$(git show $sha:index.yaml | yq -r '.entries."k8s-gateway"[] | select(.digest == "'$digest'") | .created')
  yq -i '.entries."k8s-gateway" = (.entries."k8s-gateway" | (.[] | select(.digest == "'$digest'") | .created) |= "'$timestamp'")' index.yaml
done

ruby -r yaml -e "y = YAML.load_file('index.yaml'); File.write('index.yaml', y.to_yaml)"