2
2

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.

kustomize buildしたときに`Error: invalid Kustomization: json: cannot unmarshal string into Go struct field Kustomization.patches of type types.Patch`で失敗

Last updated at Posted at 2023-06-28

インターネットに情報があまりなさそうだったのでメモ程度に書いています。

結論

結論から先に書くと手元とリポジトリのkustomizeのバージョン差異だった

  • 手元のMac kustomize 5.1.0
  • リポジトリ kustomize 4.2.0

現状

overlays/production以下などでkustomize buildを行うとコケた。
少し調べてみるとpatches:の書き方が古いのでこのエラーが出ているっぽい。

$ kustomize build .
Error: invalid Kustomization: json: cannot unmarshal string into Go struct field Kustomization.patches of type types.Patch

手元のMacにインストールされているkustomizeのバージョンは5.1.0だったが、リポジトリで使用されているバージョンは4.2.0だった。

$ kustomize version
v5.1.0

修正

再インストールするよりもasdfでkustomizeのバージョン管理を行ったほうが良い気がしたので追記(2023/11/22)

asdfでkustomizeをバージョン管理する

asdfのガイドを参考にasdfをインストールする。今回はbrew+zshの環境です。
https://asdf-vm.com/guide/getting-started.html

# asdfをインストール
$ brew install asdf

# brewでインストールしてzshを使用している場合
$ echo -e "\n. $(brew --prefix asdf)/libexec/asdf.sh" >> ${ZDOTDIR:-~}/.zshrc

asdf pluginでkustomize pluginを入れてkustomizeをインストールします。
https://github.com/Banno/asdf-kustomize

# kustomizeプラグインを追加
asdf plugin-add kustomize https://github.com/Banno/asdf-kustomize.git

# kustomize 4.2.0をasdf経由でインストール
$ asdf install kustomize 4.2.0
Downloading kustomize from https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv4.2.0/kustomize_v4.2.0_darwin_arm64.tar.gz

# kustomize v4.2.0を使うようにする
$ asdf global kustomize 4.2.0

kustomize v4.2.0が使えるようになりました

$ kustomize version
{Version:kustomize/v4.2.0 GitCommit:d53a2ad45d04b0264bcee9e19879437d851cb778 BuildDate:2021-06-30T22:49:26Z GoOs:darwin GoArch:arm64}

brewでインストールされているものをアンインストールしてからバイナリをバージョン指定してインストールする

# brewでインストールされていたものを削除
$ brew uninstall kustomize

# バイナリをバージョン指定してインストール
$ curl -s “https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh” | bash -s <version>

#今回の場合は4.2.0を入れた
$ kustomize version
{Version:kustomize/v4.2.0 GitCommit:d53a2ad45d04b0264bcee9e19879437d851cb778 BuildDate:2021-06-30T22:49:26Z GoOs:darwin GoArch:arm64}

本当はリポジトリのkustomizeのバージョン上げるのが良いですが、大変だったり難しかったり、今すぐ結果を見たい時は手元のバージョンを下げる手段を取るのが良いんだろうなと思いました。

参考

2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?