דלגו לתוכן

Application YAML — root, multi-source, syncPolicy

file: gitops/argocd/root.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: <APP>
namespace: argocd
finalizers: [resources-finalizer.argocd.argoproj.io]
spec:
project: default
source:
repoURL: https://<GITLAB_HOST>/<GROUP>/<REPO>.git
targetRevision: main
path: argocd/apps
destination: {server: https://kubernetes.default.svc, namespace: argocd}
syncPolicy:
automated: {prune: true, selfHeal: true}
# TRIDENT: name trident-root, repo trident-gitops
  • source יחיד (לא sources). ה-path מכיל Application manifests של ה-children, ולא את root.yaml עצמו.
  • namespace: argocd ב-destination כי ה-Application objects חיים שם.
file: gitops/argocd/apps/<ENV>.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: <APP>
namespace: argocd
finalizers: [resources-finalizer.argocd.argoproj.io]
spec:
project: default
sources:
- repoURL: https://<GITLAB_HOST>/<GROUP>/<REPO>.git # the templates repo
targetRevision: <TAG>
path: <CHART_DIR>
helm:
releaseName: <RELEASE>
valueFiles:
- $values/apps/<SERVICE>/base.yaml
- $values/apps/<SERVICE>/<ENV>.yaml
- $values/apps/<SERVICE>/versions/<ENV>.yaml
# … (one more chart source per chart, same shape)
- repoURL: https://<GITLAB_HOST>/<GROUP>/<REPO>.git # the gitops repo
targetRevision: main
ref: values
destination: {server: https://kubernetes.default.svc, namespace: <NS>}
syncPolicy:
automated: {prune: true, selfHeal: true}
syncOptions: [CreateNamespace=false]
# TRIDENT: templates repo trident-templates, <TAG> = v1.0.0, gitops repo trident-gitops

שים לב: שני ה-repoURL משתמשים ב-<REPO> אבל הם שני repos שונים: charts מ-templates, ערכים מ-gitops.

  • סדר valueFiles: base → <ENV> → versions/<ENV>. המאוחר מנצח; maps מתמזגים לפי מפתח, lists מוחלפים.
  • source הערכים: ref: values, ב-gitops, בלי path. השם values הוא מה שמופיע ב-$values/.
  • versions/<ENV>.yaml נכתב רק על ידי promote.sh. אם הוא "" (מעולם לא עבר promote), הרינדור נכשל: ראה ComparisonError.
  • CreateNamespace=false (או השמטה) כשה-namespace נוצר על ידי script ה-bootstrap, יחד עם ה-Secrets שה-Pods צריכים לפני sync.
runs on: any shell
python3 -c "import sys,yaml; [print(d['kind'], d['metadata']['name']) for d in yaml.safe_load_all(open(sys.argv[1]))]" <FILE>
grep -n 'repoURL: ""' <FILE>

איך מוודאים: השורה הראשונה מדפיסה Application <name> (ה-YAML תקין); ה-grep לא מדפיס כלום (אין repoURL ריק).

Source שהוא תיקייה עם kustomization.yaml. אין מפתח kustomize:; Argo מזהה לבד. משמש להעלאת dashboard כ-ConfigMap (ראה observability).

file: gitops/argocd/apps/observability.yaml (one source of sources:)
- repoURL: https://<GITLAB_HOST>/<GROUP>/<REPO>.git # the gitops repo
targetRevision: main
path: observability/grafana/dashboards
SourcetargetRevisionלמה
charts ב-templates<TAG>נעוץ (pin): push ל-templates לא שובר סביבה חיה
values ב-gitops (ref: values)mainpromote.sh כותב ל-main; הערכים חייבים לעקוב
root, kustomize ב-gitopsmainאותו שינוי, אותה סיבה

destination: איפה ה-Application, ואיפה המשאבים

Section titled “destination: איפה ה-Application, ואיפה המשאבים”
  • metadata.namespace: argocd: ה-Application object עצמו (תמיד).
  • destination.namespace: <NS>: לשם Argo מחיל את המשאבים המרונדרים.
  • destination.server: https://kubernetes.default.svc = אותו cluster שבו Argo רץ.
  • ל-Argo יש הרשאות cluster-wide, ולכן הוא יכול לכתוב ל-<NS> למרות שהוא רץ ב-argocd.
צורהמשמעות
syncPolicy: {}sync ידני בלבד: OutOfSync נשאר עד שמפעילים; אין selfHeal
automated: {}sync אוטומטי, בלי prune ובלי selfHeal
automated: {prune: true, selfHeal: true}המטרה: מחיקה ב-Git מוחקת בקלאסטר, ושינוי חי מוחזר
  • selfHeal נכנס כשהשינוי בצד ה-cluster (scale, edit); prune כשהשינוי ב-Git (קובץ נמחק).
  • resources-finalizer.argocd.argoproj.io: מחיקת ה-Application מוחקת גם את המשאבים שלו (cascade). בלעדיו המשאבים נשארים יתומים. פירוט: verify/cleanup.
  • מחק Application לפני AppProject שלו.
שדהמקור הערך
metadata.nameשם ה-Application לפי החוזה (<APP>)
metadata.namespaceתמיד argocd
repoURL (charts)כתובת HTTPS של repo ה-templates, זהה ל-url ב-repo Secret
repoURL (values, root)כתובת HTTPS של gitops, זהה ל-url ב-repo Secret
targetRevisiontag לצ'ארטים, main לכל השאר
pathתיקיית chart ב-templates (מתחילה ב-charts/) או תיקייה ב-gitops
releaseNameהחוזה (שם ה-release; אל תשתמש ב-.Release.Name בתבניות)
valueFilesקבצים ב-gitops, תחת $values/
destination.namespace<NS> של הסביבה, נוצר ב-bootstrap