From 0df64e908f4d8c12deda50f817ee9856cf3e9558 Mon Sep 17 00:00:00 2001 From: Rauno Viskus <1334536+rauno56@users.noreply.github.com> Date: Mon, 22 Jul 2024 13:14:10 +0300 Subject: [PATCH] fix: match file names in helm registry index and release assets (#1373) Adding a separate Helm chart for CRDs. :exclamation: The charts are not strictly dependent to one another and need to be separately managed and installed. Meaning we need to document that both of those need to be updated and installed. Fair questions that might arise: **Why isn't CRD chart a declared dependency for `odigos`?** Helm merges dependent resources together with the ones from dependencies. We'd be exactly where we are right now if we did that. **Why not use the official `crd` support?** Helm really doesn't "support" CRDs. It's an opt-out feature of "we don't know how we want to do it so we don't for now". Resources declared as CRDs(different from declaring them under `templates`) are not updated. **How do other charts do it then?** All charts I've encountered(cert-manager, jaeger, contour) have CRDs under a flag and include them in the same chart as the rest of the resources **but then** do not depend on them in in the install. CRs are created either only by the user or later in the applications life-cycle. This doesn't work for us since we declare Odigos Config among resources in the application chart. That begs the question whether Odigos Config must be a CR at all or could it be a config map instead - we wouldn't get "type-checking" by k8s API but would gain some flexibility and could release our charts as one. --- .github/workflows/release.yml | 7 +++++-- helm/odigos/Chart.yaml | 8 ++++---- scripts/release-charts.sh | 30 ++++++++++++++++++++++-------- 3 files changed, 31 insertions(+), 14 deletions(-) mode change 100644 => 100755 scripts/release-charts.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 52a05aef1..80ccc3279 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -name: Release Odigos CLI +name: Release Odigos on: workflow_dispatch: @@ -137,6 +137,7 @@ jobs: echo "TAG=${{ github.event.client_payload.tag }}" >> $GITHUB_ENV else echo "Unknown event type" + echo "TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV exit 1 fi @@ -156,4 +157,6 @@ jobs: version: v3.15.2 - name: Release Helm charts - run: sh ./scripts/release-charts.sh + env: + GH_TOKEN: ${{ github.token }} + run: bash ./scripts/release-charts.sh diff --git a/helm/odigos/Chart.yaml b/helm/odigos/Chart.yaml index 574dc984e..d3f93b350 100644 --- a/helm/odigos/Chart.yaml +++ b/helm/odigos/Chart.yaml @@ -1,8 +1,8 @@ apiVersion: v2 name: odigos -description: Odigos Helm Chart for Kubernetes +description: Odigos distribution for Kubernetes type: application -# v0.0.0 will be replaced by the git tag version on release -version: "v0.0.0" -appVersion: "v0.0.0" +# 0.0.0 will be replaced by the git tag version on release +version: "0.0.0" +appVersion: "0.0.0" icon: https://d2q89wckrml3k4.cloudfront.net/logo.png diff --git a/scripts/release-charts.sh b/scripts/release-charts.sh old mode 100644 new mode 100755 index 443a4824b..04ece9bd8 --- a/scripts/release-charts.sh +++ b/scripts/release-charts.sh @@ -1,8 +1,17 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash # Setup TMPDIR="$(mktemp -d)" -CHARTDIR="helm/odigos" +CHARTDIRS=("helm/odigos") + +prefix () { + echo "${@:1}" + echo "${@:2}" + for i in "${@:2}"; do + echo "Renaming $i to $1$i" + mv "$i" "$1$i" + done +} if [ -z "$TAG" ]; then echo "TAG required" @@ -14,7 +23,7 @@ if [ -z "$GITHUB_REPOSITORY" ]; then exit 1 fi -if [[ $(git diff -- $CHARTDIR | wc -c) -ne 0 ]]; then +if [[ $(git diff -- ${CHARTDIRS[*]} | wc -c) -ne 0 ]]; then echo "Helm chart dirty. Aborting." exit 1 fi @@ -24,16 +33,21 @@ helm repo add odigos https://odigos-io.github.io/odigos-charts 2> /dev/null || t git worktree add $TMPDIR gh-pages -f # Update index with new packages -sed -i -E 's/v0.0.0/'"${TAG}"'/' $CHARTDIR/Chart.yaml -helm package helm/* -d $TMPDIR +for chart in "${CHARTDIRS[@]}" +do + echo "Updating $chart/Chart.yaml with version ${TAG#v}" + sed -i -E 's/0.0.0/'"${TAG#v}"'/' $chart/Chart.yaml +done +helm package ${CHARTDIRS[*]} -d $TMPDIR pushd $TMPDIR +prefix 'test-helm-assets-' *.tgz helm repo index . --merge index.yaml --url https://github.com/$GITHUB_REPOSITORY/releases/download/$TAG/ +git diff -G apiVersion # The check avoids pushing the same tag twice and only pushes if there's a new entry in the index if [[ $(git diff -G apiVersion | wc -c) -ne 0 ]]; then # Upload new packages - rename 'odigos' 'test-helm-assets-odigos' *.tgz - gh release upload -R $GITHUB_REPOSITORY $TAG $TMPDIR/*.tgz + gh release upload -R $GITHUB_REPOSITORY $TAG $TMPDIR/*.tgz || exit 1 git add index.yaml git commit -m "update index with $TAG" && git push @@ -45,5 +59,5 @@ else fi # Roll back chart version changes -git checkout $CHARTDIR +git checkout ${CHARTDIRS[*]} git worktree remove $TMPDIR -f || echo " -> Failed to clean up temp worktree"