将 TLA 从 argocd 传递到 jsonnet

Passing TLAs from argocd to jsonnet

试图用 argocd 理解 passing TLAs to my jsonnet file。这是我的 argocd application.yaml 的一部分,它直接从我的 main.jsonnet 文件编译 kube-prometheus 清单。我想在 argocd(prod 和 nonprod)中创建 2 个 kube-prometheus 应用程序,我想通过 TLA 来更改每个应用程序实例的入口主机名后缀。

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: kube-prometheus-nonprod
  namespace: argocd
spec:
  destination:
    name: ''
    namespace: monitoring
    server: 'https://kubernetes.default.svc'
  source:
    path: kube-prometheus/src
    repoURL: 'https://myrepo.git'
    targetRevision: branch-name
    directory:
      jsonnet:
        tlas:
          - name: npDomainSuffix
            value: np.example.io
      libs:
        - kube-prometheus/vendor/

在我的 main.jsonnet 文件中有例如:

hosts: ['grafana.$(npDomainSuffix)']

jsonnet 和 argocd 的新手,无法正常工作。我可以这样使用 TLA 吗?

如果您是 jsonnet 的新手,我建议您改用 extVars,因为 TLA 机制有点难以掌握,来自 jsonnet tutorial 的 TLA 部分,您会发现您的 jsonnet 代码需要一个入口函数,其中的参数以每个顶级参数名称命名。

或者,您应该可以使用 extVars 来代替:

        extVars:
          - name: npDomainSuffix
            value: np.example.io

然后 任何地方 在你的 jsonnet 代码中(extVars 是全局的)

hosts: ['grafana.' + std.extVar('npDomainSuffix')]