You need to enable JavaScript to run this app. Kustomize replacement如何匹配替换数组的所有元素
优惠活动
大模型
产品
解决方案
定价
更多

Kustomize replacement如何匹配替换数组的所有元素

问题原因

你遇到的是Kustomize v4.2.0的已知bug:该版本中-通配符仅能匹配数组的最后一个元素,无法遍历匹配所有数组项。

解决方案

你可以根据实际场景二选一:

方案1:兼容旧版本(无需升级Kustomize)

如果你的http数组元素数量固定,直接显式声明所有待替换的字段路径即可,修改replacements下的fieldPaths配置:

replacements:
- source:
    kind: ConfigMap
    fieldPath: data.HOST
  targets:
  - select:
      kind: VirtualService
    fieldPaths:
     - spec.http.0.route.0.destination.host
     - spec.http.1.route.0.destination.host
    options:
      create: true

该写法在v4.2.0版本可正常替换所有对应位置的占位符。

方案2:通配符匹配(需升级Kustomize)

如果你的http数组元素数量不固定,建议将Kustomize升级到v4.5.0及以上版本,该版本修复了-通配符的匹配逻辑,你原本写的spec.http.-.route.0.destination.host语法即可正常遍历替换http数组下所有项的对应host字段。


内容的提问来源于stack exchange,提问作者bhantol

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.12 18:57:03