0

我正在使用 kustomize 并尝试将一些 helm 参数修补到 grafana 配置中,我有以下配置文件 grafana.yaml:

---
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: prod-k8s-grafana
  labels:
    environment: prod
    project: k8s
    role: grafana
spec:
  project: prod-k8s
  source:
    repoURL: 'https://github.com/helm/charts.git'
    path: 'stable/grafana'
    targetRevision: 'ba1d08a129255167457480e29339ab5bfe75d918'
    helm:
      parameters:
      - name: service.type
        value: LoadBalancer
  syncPolicy:
    automated:
      prune: true
  destination:
    namespace: prod-k8s-grafana

然后我有我的 kustomization 文件,我用它来添加修补值 - 特别是到 helm 参数部分。当我添加如下补丁时,它会修补值,但会删除 grafana.yaml 文件中定义的原始名称值:

patches:
- target:
    kind: Application
  patch: |-
    apiVersion: argoproj.io/v1alpha1
    kind: Application
    metadata:
      name: xxx
    spec:
      destination:
        server: https://DSKJHDAKJSH4HDSKHDKSJ0E56C7420CCF041E9.sk1.eu-west-2.eks.amazonaws.com
- target:
    kind: Application
    name: prod-k8s-grafana
  patch: |-
    apiVersion: argoproj.io/v1alpha1
    kind: Application
    metadata:
      name: prod-k8s-grafana
    spec:
      source:
        helm:
          parameters:
          - name: 'datasources."datasources\.yaml".datasources[0].url'
            value: 'http://prod-k8s-prometheus-cluster02-server.prod-k8s-prometheus.svc.cluster.local'
          - name: persistence.storageClassName
            value: gp2
          - name: 'datasources."datasources\.yaml".apiVersion'
            value: '1'
          - name: 'datasources."datasources\.yaml".datasources[0].name'
            value: Prometheus

这样当我检查运行kustomize build命令时,它会删除输出:

      - name: service.type
        value: LoadBalancer

因此,修补这些名称和值似乎会覆盖 grafana.yaml 中的参数。

如何确保补丁将补丁名称附加到 vales,而不是覆盖?

4

1 回答 1

2

我最近遇到了同样的问题,不知道这是否是完美的解决方案,但是如果您patchesJson6902在位置 0 使用并添加环境变量,它不会删除另一个:

- op: add
  path: /spec/template/spec/containers/0/env/0
  value:
    name: ONE
    value: '1'
- op: add
  path: /spec/template/spec/containers/0/env/0
  value:
    name: TWO
    value: '2'
- op: add
  path: /spec/template/spec/containers/0/env/0
  value:
    name: THREE
    value: '3'
于 2020-09-17T08:52:02.533 回答