6

We are looking for a way of setting the Chart.AppVersion in our pipeline in a way that, 'helm history' would return correct app versions.

REVISION    UPDATED                     STATUS      CHART           APP VERSION DESCRIPTION
1           Mon Jun  8 11:39:51 2020    superseded  spring-1.0.0    1.0.0       Install complete
2           Mon Jun  8 12:19:21 2020    superseded  spring-1.0.0    1.0.0       Upgrade complete
3           Mon Jun  8 12:20:51 2020    deployed    spring-1.0.0    1.0.0       Upgrade complete

Currently helm' history' returns similar results as above (loaned from here: https://github.com/helm/helm/issues/8194#issuecomment-640598047) and not the actual app version.

helm upgrade --app-version "$variable

With command like that we would like to achieve results as below.

REVISION    UPDATED                     STATUS      CHART           APP VERSION DESCRIPTION
1           Mon Jun  8 11:39:51 2020    superseded  spring-1.0.0    1.0.1       Install complete
2           Mon Jun  8 12:19:21 2020    superseded  spring-1.0.0    1.0.2       Upgrade complete
3           Mon Jun  8 12:20:51 2020    deployed    spring-1.0.0    1.0.3       Upgrade complete

Currently we are setting the app version like this:

sed -i "s/^version:.*$/version: $(git describe)/" chart/Chart.yaml
sed -i "s/^appVersion:.*$/appVersion: $(git describe)/" chart/Chart.yaml
helm upgrade app ./chart
Calvin
  • 61
  • 1
  • 3
  • HI, good question From what i gathered your way is the only way, hope someone will find a good answer for this. – Shmuel Jun 02 '22 at 11:13

1 Answers1

1

One option would be to package your helm chart in the pipeline and then deploy the correctly versioned helm package in another job. This will allow you to also manage the versions that you release in a registry or repository.

First, package the helm chart with the correct --version and --app-version. You can declare a $nextReleaseVersion as a variable in the pipeline or use a tool like semantic-release to automate versioning.

I am not sure what stack you are using but below are examples for Github and Gitlab.

Gitlab

In the gitlab pipeline example, helm cm-push is used to package the chart with the correct versions and push it to the Gitlab Package Registry "helm-chart-library":

package_helm:
  image: 
    name: alpine/helm:3.5.3
    entrypoint: [""]
  before_script:
    - apk add git && helm plugin install https://github.com/chartmuseum/helm-push
  script:
    - helm repo add --username deploy_token --password $DEPLOY_TOKEN helm-chart-library https://gitlab.example.com/api/v4/projects/${CI_PROJECT_ID}/packages/helm/stable
    - helm cm-push charts/ --version="$nextReleaseVersion" --app-version="$nextReleaseVersion" helm-chart-library

Next, you will need to pull the helm package with the correct version from the registry and install it in the cluster. Note that when we install the package, we apply --untar which will unzip the package and create a temporary directory with the Chart's name/release. You will need to apply the correct path of newly versioned helm chart to the helm upgrade command and can also optionally set the image tag --set image.tag=$nextReleaseVersion.

deploy_helm:
  script:
    - helm repo add --username deploy_token --password $DEPLOY_TOKEN helm-chart-library https://gitlab.example.com/api/v4/projects/${CI_PROJECT_ID}/packages/helm/stable
    - helm repo update
    - helm pull helm-chart-library/${HELM_RELEASE_NAME} --untar --version $nextReleaseVersion
    - helm upgrade --install --namespace ${KUBERNETES_NAMESPACE} --values ${HELM_RELEASE_NAME}/${HELM_VALUES_FILE} ${HELM_RELEASE_NAME} ./${HELM_RELEASE_NAME}/

Github

Alternatively, in Github, you can push the chart into a Github Helm Chart Repository. Helm documentation offers an example here - https://helm.sh/docs/topics/chart_repository/#github-pages-example. I have Github Pages disabled and so also experimented pushing the helm packages to a separate branch e.g. "helm-chart-repo"

  helm_package:
    name: Package and Push Helm Charts to Chart Repository
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Current Branch
        uses: actions/checkout@v2

      # Check out the branch where you will store the helm packages
      - name: Checkout helm-chart-repo Branch
        uses: actions/checkout@v3
        with:
          repository: yourOrg/repositoryName
          ref: 'branchName'
          token: '${{ secrets.API_TOKEN }}'

      # Package your chart with the correct versions, move the package 
      # into a directory called 'helm-chart-repository' and push to Github
      - name: Helm Package and Push to Github Repository
        env:
          VERSION: ${{ env.nextReleaseVersion}}
        run: |
          helm package charts/ --version $VERSION --app-version $VERSION
          git config --global user.email "your-email@your-org.com"
          git config --global user.name "your-username"
          mv package-name-$VERSION.tgz helm-chart-repository/package-name-$VERSION.tgz
          CHART_PACKAGE_NAME="package-name-$VERSION.tgz"
          cd charts/
          helm repo index .
          cd ../
          git add .
          git commit -m "$CHART_PACKAGE_NAME [skip ci]"
          git push

This may not be the perfect solution but I hope it helps!

Tallulah
  • 51
  • 1
  • 11