You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ArgoCD中为不同应用配置不同targetRevision的方法咨询

ArgoCD AppSet:为不同应用配置不同targetRevision的可行方案

我是ArgoCD新手,目前需要为通过AppSet部署的不同应用设置不同的targetRevision,现有项目结构如下:

project/
├── instances
│   ├── dev
│   │   ├── build
│   │   │   ├── values_main.yaml
│   │   └── vhs
│   │       ├── values_main.yaml
│   └── prod
│       ├── build
│       │   ├── values_main.yaml
│       └── vhs
│           ├── values_main.yaml
├── argo
│   └── argocd-configs.yml <------ AppSet配置文件
└── unittests

当前我有一个可正常部署instances/dev/*下两个应用的AppSet配置:

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: appset
  namespace: argocd
spec:
  generators:
  - git:
      directories:
      - path: instances/dev/*
      repoURL: *REPO*
      revision: '0.0.1'
  template:
    metadata:
      name: '{{path.basename}}'
    spec:
      destination:
        namespace: '{{path.basename}}'
        server: https://kubernetes.default.svc
      project: project
      source:
        helm:
          valueFiles:
          - '{{path}}/values_main.yaml'
        path: ./
        repoURL: *REPO*
        targetRevision: master

现在希望为build应用设置targetRevision: master,为vhs应用设置targetRevision: dev,尝试了以下三种方案均无效:

方案一:多Git生成器+自定义values

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: ckp-project-jenkins-appset
  namespace: argocd
spec:
  generators:
  - git:
      directories:
      - path: instances/dev/build
      repoURL: *REPO*
      revision: '0.0.1'
      values:
        revision: master
  - git:
      directories:
      - path: instances/dev/vhs
      repoURL: *REPO* 
      revision: '0.0.1'
      values:
        revision: dev
  template:
    metadata:
      name: '{{path.basename}}'
    spec:
      destination:
        namespace: '{{path.basename}}'
        server: https://kubernetes.default.svc
      project: projecy
      source:
        helm:
          valueFiles:
          - '{{path}}/values_main.yaml'
        path: ./
        repoURL: *REPO* 
        targetRevision: "{{.values.revision}}"
      syncPolicy:
        automated:
          prune: false
          selfHeal: true
        retry:
          backoff:
            duration: 10s
            factor: 2
            maxDuration: 5m0s
          limit: 3

方案二:模板内条件判断

targetRevision: |
        {{ if eq path.basename "build" }}
        master
        {{ else }}
        dev
        {{ end }}

方案三:使用templatePatch

templatePatch: |
    {{- if eq .path.basename "build" }}
    spec:
      source:
        targetRevision: master
    {{- end }}

请问有没有可行的实现方法?

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 12:18:09