helmfileをv1にアップグレードする

helm

2025-04-10

#はじめに

2025年5月1日に、helmfileのv1がリリースされる予定です。
これまで、重い腰を上げられずにいましたが、v1にアップグレードすることにしました。

#参考リンク

helmfile v1のリリース予告が下記のリンクに記載されています。

Helmfile V1 🎉 May 1st 2025 · helmfile/helmfile · Discussion #1912
Hey everyone 👋 After a two-year graceful migration from Helmfile v0.x to v1, we're finally turning on the V1 mode by default (#1903). To anyone unfamiliar with the V1 mode- we've been helping you t...
Helmfile V1 🎉 May 1st 2025 · helmfile/helmfile · Discussion #1912 favicon github.com
Helmfile V1 🎉 May 1st 2025 · helmfile/helmfile · Discussion #1912

下位互換性の無い変更については下記を参照してください。

helmfile/docs/proposals/towards-1.0.md at main · helmfile/helmfile
Declaratively deploy your Kubernetes manifests, Kustomize configs, and Charts as Helm releases. Generate all-in-one manifests for use with ArgoCD. - helmfile/helmfile
helmfile/docs/proposals/towards-1.0.md at main · helmfile/helmfile favicon github.com
helmfile/docs/proposals/towards-1.0.md at main · helmfile/helmfile

#影響範囲

#The changes in 1.0

  1. Forbid the use of environments and releases within a single helmfile.yaml.gotmpl part
  2. Force .gotmpl file extension for helmfile.yaml in case you want helmfile to render it as a go template before yaml parsing.
  3. Remove the --args flag from the helmfile command
  4. Remove HELMFILE_SKIP_INSECURE_TEMPLATE_FUNCTIONS in favor of HELMFILE_DISABLE_INSECURE_FEATURES
  5. The long deprecated charts.yaml has been finally removed
  6. List experimental features
  7. Remove charts and delete sub-commands

私の場合、影響している部分は2だけでしたので、これらについて対応する必要があります。
とはいえ、量が多いので、できるだけ機械的に処理したい。

#v1をインストールする

まず、まだv0系を使っているので、v1をインストールします。
miseをつかってhelmfileを管理しているので、.tool-versionsを修正します。
v1系のRC版がリリースされているので、そちらをインストールします。

  • .tool-versions
helmfile 1.0.0-rc.12

miseでインストールします。

mise install
...
helmfile -v
helmfile version 1.0.0-rc.12

#修正する

#1. helmfile.yamlの拡張子を変更する

ほとんどのhelmfile.yamlがGoテンプレートを使っているので、
helmfile.yamlの拡張子をhelmfile.yaml.gotmplに変更します。

find . -path './*/helmfile.yaml' -exec sh -c 'mv "$1" "$(dirname "$1")/helmfile.yaml.gotmpl"' sh {} \;

その他にも一部yamlでGoテンプレートを使用している箇所が合ったので、拡張子を変更しました。

find . -path '*.yaml' -exec sh -c 'mv "$1" "$1.gotmpl"' sh {} \;

#2. yamlの内容を修正する

それまでyamlのなかで、helmfile.yamlなどを読み込んでいた部分が、ファイル名が変わったので、grepして一括置換したいと思います。

grep -l 'helmfile\.yaml' ./* | xargs sed -i.bak -e 's/helmfile\.yaml/helmfile\.yaml\.gotmpl/g'

environments.yamlなどもGoテンプレートがあたので、手動で変更。

#動作確認

helmfile diff

動いたのでヨシ。

#まとめ

今回は、helmfileをv1にアップグレードするための手順をまとめました。
Goテンプレートの拡張子を変更する必要があったので、find,grep,sedを使って一括置換しました。
v1にアップグレードを初めてやったときは、互換性がなくてすぐにv0系に戻して、重い腰が上がらずにいました。しかし、参考リンクにある影響範囲をみたら、どうやって直せばよいか書かれていました。実際、そのとおりに修正したらうまく行きました。