提供一种在安装或升级期间动态设置 .Chart.AppVersion 的方法,无需编辑 Chart.yaml

Cal*_*vin 6 kubernetes-helm helm3

我们正在寻找一种在管道中设置 Chart.AppVersion 的方法,以便“helm 历史记录”返回正确的应用程序版本。

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
Run Code Online (Sandbox Code Playgroud)

目前,helm“history”返回与上述类似的结果(从此处借用:https: //github.com/helm/helm/issues/8194#issuecomment-640598047),而不是实际的应用程序版本。

helm upgrade --app-version "$variable
Run Code Online (Sandbox Code Playgroud)

通过这样的命令,我们希望达到如下结果。

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
Run Code Online (Sandbox Code Playgroud)

目前我们正在设置应用程序版本,如下所示:

sed -i "s/^version:.*$/version: $(git describe)/" chart/Chart.yaml
sed -i "s/^appVersion:.*$/appVersion: $(git describe)/" chart/Chart.yaml
helm upgrade app ./chart
Run Code Online (Sandbox Code Playgroud)

小智 2

一种选择是将 Helm Chart 打包到管道中,然后在另一项作业中部署版本正确的 Helm 包。这还允许您管理在注册表或存储库中发布的版本。

\n

--version首先,使用正确的和打包 Helm Chart --app-version。您可以将 a 声明$nextReleaseVersion为管道中的变量,或使用语义发布等工具来自动进行版本控制。

\n

我不确定您使用的是什么堆栈,但下面是 Github 和 Gitlab 的示例。

\n

GitLab

\n

在gitlab管道示例中,helm cm-push用于将chart打包为正确的版本,并将其推送到Gitlab包注册表“helm-chart-library”:

\n
package_helm:\n  image: \n    name: alpine/helm:3.5.3\n    entrypoint: [""]\n  before_script:\n    - apk add git && helm plugin install https://github.com/chartmuseum/helm-push\n  script:\n    - 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\n    - helm cm-push charts/ --version="$nextReleaseVersion" --app-version="$nextReleaseVersion" helm-chart-library\n\n
Run Code Online (Sandbox Code Playgroud)\n

接下来,您需要从注册表中提取具有正确版本的 helm 包并将其安装在集群中。请注意,当我们安装包时,我们应用--untar它将解压缩包并使用图表的名称/版本创建一个临时目录。您需要将新版本的 Helm Chart 的正确路径应用于命令helm upgrade,并且还可以选择设置图像标签--set image.tag=$nextReleaseVersion

\n
deploy_helm:\n  script:\n    - 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\n    - helm repo update\n    - helm pull helm-chart-library/${HELM_RELEASE_NAME} --untar --version $nextReleaseVersion\n    - helm upgrade --install --namespace ${KUBERNETES_NAMESPACE} --values ${HELM_RELEASE_NAME}/${HELM_VALUES_FILE} ${HELM_RELEASE_NAME} ./${HELM_RELEASE_NAME}/\n\n
Run Code Online (Sandbox Code Playgroud)\n

吉图布

\n

或者,在 Github 中,您可以将图表推送到 Github Helm Chart 存储库。Helm 文档在此处提供了一个示例 -\xc2\xa0https://helm.sh/docs/topics/chart_repository/#github-pages-example。我禁用了 Github Pages,因此还尝试将 helm 包推送到单独的分支,例如“helm-chart-repo”

\n
  helm_package:\n    name: Package and Push Helm Charts to Chart Repository\n    runs-on: ubuntu-latest\n    steps:\n      - name: Checkout Current Branch\n        uses: actions/checkout@v2\n\n      # Check out the branch where you will store the helm packages\n      - name: Checkout helm-chart-repo Branch\n        uses: actions/checkout@v3\n        with:\n          repository: yourOrg/repositoryName\n          ref: 'branchName'\n          token: '${{ secrets.API_TOKEN }}'\n\n      # Package your chart with the correct versions, move the package \n      # into a directory called 'helm-chart-repository' and push to Github\n      - name: Helm Package and Push to Github Repository\n        env:\n          VERSION: ${{ env.nextReleaseVersion}}\n        run: |\n          helm package charts/ --version $VERSION --app-version $VERSION\n          git config --global user.email "your-email@your-org.com"\n          git config --global user.name "your-username"\n          mv package-name-$VERSION.tgz helm-chart-repository/package-name-$VERSION.tgz\n          CHART_PACKAGE_NAME="package-name-$VERSION.tgz"\n          cd charts/\n          helm repo index .\n          cd ../\n          git add .\n          git commit -m "$CHART_PACKAGE_NAME [skip ci]"\n          git push\n\n
Run Code Online (Sandbox Code Playgroud)\n

这可能不是完美的解决方案,但我希望它能有所帮助!

\n