在ArgoCD app-of-apps配置文件中,需要添加一个“sync-policy”以指示在部署子应用时应如何同步清单文件。例如,可以将sync-policy设置为“automated”,使得子应用在被创建后自动同步到应用程序中。
示例代码:
apiVersion: argoproj.io/v1alpha1 kind: Application metadata: name: app-of-apps namespace: argocd spec: project: default source: repoURL: git@github.com:example/app-of-apps.git path: manifests targetRevision: HEAD destination: server: https://kubernetes.default.svc namespace: argocd syncPolicy: automated: prune: true selfHeal: true allowEmpty: true minReadySeconds: 5 retry: limit: 3 backoff: duration: 30s factor: 2 maxDuration: 5m post: - command: ["kubectl", "apply", "-f", "prune.yml"] container: image: bitnami/kubectl:latest imagePullPolicy: IfNotPresent hooks: - name: "YOUR_HOOK_NAME" delete: false labelSelector: matchLabels: app.kubernetes.io/name: YOUR_APP_NAME matchExpressions: - {key: app.kubernetes.io/instance, operator: In, values: [YOUR_APP_INSTANCE]} annotationSelector: matchAnnotations: argocd.argoproj.io/hook: PostSync when: phase: PostSync status: Succeeded syncResult: Succeeded