0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【未解決】Helmチャートでインストールされるリソースの順番を変えたい

Last updated at Posted at 2022-11-19

Helmチャートによるリソースのインストール順について

以下のソースで定義されている。

現時点のソースを抜粋。標準だとこの順番でインストールされる。

// Those occurring earlier in the list get installed before those occurring later in the list.
var InstallOrder KindSortOrder = []string{
	"Namespace",
	"NetworkPolicy",
	"ResourceQuota",
	"LimitRange",
	"PodSecurityPolicy",
	"PodDisruptionBudget",
	"ServiceAccount",
	"Secret",
	"SecretList",
	"ConfigMap",
	"StorageClass",
	"PersistentVolume",
	"PersistentVolumeClaim",
	"CustomResourceDefinition",
	"ClusterRole",
	"ClusterRoleList",
	"ClusterRoleBinding",
	"ClusterRoleBindingList",
	"Role",
	"RoleList",
	"RoleBinding",
	"RoleBindingList",
	"Service",
	"DaemonSet",
	"Pod",
	"ReplicationController",
	"ReplicaSet",
	"Deployment",
	"HorizontalPodAutoscaler",
	"StatefulSet",
	"Job",
	"CronJob",
	"IngressClass",
	"Ingress",
	"APIService",
}

課題

上記のInstallOrderにインストール順を縛られると困るケースが、例えば以下のようにある。

  • 特定のJobだけ先に(後に)実行したい。
  • InstallOrderに未登録のリソースのインストール順を制御できない。例えばCustomACustomBのカスタムリソースがあり、「CustomACustomBよりも後にインストールさせたい」場合に、CustomAが先にインストールされてしまう。

筆者が具体的に困ったのが、Argo WorkflowsのカスタムリソースでWorkflowTemplateのリソースで定義したテンプレートをWorkflowから呼ぼうとした時に、先にWorkflowのリソースがインストールされてエラーになってしまったこと。
何度かhelm installを試してみたが、エラーは起きたり起きなかったりするので、InstallOrderに登録されていないカスタムリソースのインストール順は気まぐれに変わっていると思われる。

現状の解決策

インストール順を変えたいリソースのマニフェストで、下例のようにmetadata.annotationshelm.sh/hookのキーと値を追加すると一応は解決する。

metadata:
  annotations:
    "helm.sh/hook": pre-install, pre-upgrade
    "helm.sh/hook-weight": "-5"                  # 必要に応じて設定
    "helm.sh/hook-delete-policy": hook-succeeded # 必要に応じて設定

例えばhelm.sh/hookpre-installpre-upgradeを設定すると、先にそのリソースがインストールされる。post-install, post-upgradeだと後でインストールされる。

各アノテーションの具体的な使い方については、以下の公式ドキュメントを参照いただきたい。

hooksの挙動については、Release lifecycle management with Helmに書かれた以下の図を見ると、筆者も何となく理解できた。

だが図を見てみると、helm.sh/hookのアノテーションはあくまで「本体リソースをインストールするための前処理/後処理」としてリソースを動かす場合を意図したもののようので、本体(図でいうv1.0、v1.1の箱)に持ってきたいリソースは結局のところ、InstallOrderの束縛からは逃れられない…。

※実際、helm uninstallでリソースを消そうとしたところ、上図のv1.0、v1.1に相当するリソースは消えるのだが、helm.sh/hookのアノテーションをつけたリソースは仲間外れにされて消えてくれなかった。

なので現状、この課題の根本的な解決策は見つかっていないと認識している。

以下のGitHubのissueでも「helm.sh/order-weightのようなアノテーションがあるといいのに」という記載があるので、おそらく未解決なのだろう。

※ここまで読んでいただいた方に解決策をご提示できずに申し訳ないですが、解決法がわかり次第本記事をアップデートさせていただきます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?