[英]Kustomize best practice to apply the same patch to multiple base files
[英]Kustomize: how to apply the same patch in multiple overlays without LoadRestrictionsNone
我有一個類似這樣的自定義布局:
├──release
│ ├──VariantA
│ │ └──kustomization.yaml
│ │ cluster_a.yaml
| └──VariantB
│ └──kustomization.yaml
│ cluster_b.yaml
└──test
├──TestVariantA
│ └──kustomization.yaml; resources=[VariantA]
│ common_cluster_patch.yaml
└──TestVariantB
└──kustomization.yaml; resources=[VariantB]
common_cluster_patch.yaml
我的問題是common_cluster_patch.yaml
的重復。 這是一個常見的補丁,我需要將其應用於不同的基本集群對象。 我寧願不必為每個測試變體維護相同的副本。
我嘗試的 2 個不成功的解決方案是:
一個常見的補丁資源
├──release
│ ├──VariantA
│ │ └──kustomization.yaml
│ │ cluster_a.yaml
| └──VariantB
│ └──kustomization.yaml
│ cluster_b.yaml
└──test
├──TestVariantA
│ └──kustomization.yaml; resources=[VariantA, TestPatch]
├──TestVariantB
│ └──kustomization.yaml; resources=[VariantB, TestPatch]
└──TestPatch
└──kustomization.yaml
common_cluster_patch.yaml
這失敗了, no matches for Id Cluster...
,大概是因為 TestPatch 正在嘗試修補它不包含的對象。
一個通用的補丁目錄
├──release
│ ├──VariantA
│ │ └──kustomization.yaml
│ │ cluster_a.yaml
| └──VariantB
│ └──kustomization.yaml
│ cluster_b.yaml
└──test
├──TestVariantA
│ └──kustomization.yaml; resources=[VariantA]; patches=[../TestPatch/common_cluster_patch.yaml]
├──TestVariantB
│ └──kustomization.yaml; resources=[VariantB]; patches=[../TestPatch/common_cluster_patch.yaml]
└──TestPatch
└──common_cluster_patch.yaml
這失敗了: '/path/to/test/TestPatch/common_cluster_patch.yaml' is not in or below '/path/to/test/TestVariantA'
。
我可以解決這個問題並使用kustomize build --load-restrictor LoadRestrictionsNone
成功生成我的模板,但這會帶來可怕的警告和預兆。 我希望有一些更好的方法來組織我的資源,不需要變通辦法或重復。
感謝 criztovyl 的回答! 解決方案是自定義組件。 組件目前僅在kustomize.config.k8s.io/v1alpha1
中定義, 參考文檔是一個存根,但它們包含在 kustomize 的當前發行版本中。
我的解決方案現在看起來像:
├──release
│ ├──VariantA
│ │ └──kustomization.yaml
│ │ cluster_a.yaml
| └──VariantB
│ └──kustomization.yaml
│ cluster_b.yaml
└──test
├──TestVariantA
│ └──kustomization.yaml; resources=[VariantA]; components=[../TestCommon]
├──TestVariantB
│ └──kustomization.yaml; resources=[VariantB]; components=[../TestCommon]
└──TestCommon
└──kustomization.yaml; patches=[common_cluster_patch.yaml]
common_cluster_patch.yaml
其中test/TestCommon/kustomization.yaml
有標題:
apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component
組件和資源之間的關鍵區別在於,組件是在其他處理之后應用的。 這意味着它可以修補包含它的資源中的對象。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.