Application YAML — root, multi-source, syncPolicy
root Application
Section titled “root Application”apiVersion: argoproj.io/v1alpha1kind: Applicationmetadata: 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-gitopssourceיחיד (לאsources). ה-path מכיל Application manifests של ה-children, ולא אתroot.yamlעצמו.namespace: argocdב-destination כי ה-Application objects חיים שם.
child Application עם multi-source
Section titled “child Application עם multi-source”apiVersion: argoproj.io/v1alpha1kind: Applicationmetadata: 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.
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 ריק).
kustomize directory source
Section titled “kustomize directory source”Source שהוא תיקייה עם kustomization.yaml. אין מפתח kustomize:; Argo מזהה לבד. משמש להעלאת dashboard כ-ConfigMap (ראה observability).
- repoURL: https://<GITLAB_HOST>/<GROUP>/<REPO>.git # the gitops repo targetRevision: main path: observability/grafana/dashboardstag מול branch ב-targetRevision
Section titled “tag מול branch ב-targetRevision”| Source | targetRevision | למה |
|---|---|---|
charts ב-templates | <TAG> | נעוץ (pin): push ל-templates לא שובר סביבה חיה |
values ב-gitops (ref: values) | main | promote.sh כותב ל-main; הערכים חייבים לעקוב |
root, kustomize ב-gitops | main | אותו שינוי, אותה סיבה |
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 ו-finalizers
Section titled “syncPolicy ו-finalizers”| צורה | משמעות |
|---|---|
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 שלו.
טבלה: מאיפה מגיע כל ערך
Section titled “טבלה: מאיפה מגיע כל ערך”| שדה | מקור הערך |
|---|---|
metadata.name | שם ה-Application לפי החוזה (<APP>) |
metadata.namespace | תמיד argocd |
repoURL (charts) | כתובת HTTPS של repo ה-templates, זהה ל-url ב-repo Secret |
repoURL (values, root) | כתובת HTTPS של gitops, זהה ל-url ב-repo Secret |
targetRevision | tag לצ'ארטים, main לכל השאר |
path | תיקיית chart ב-templates (מתחילה ב-charts/) או תיקייה ב-gitops |
releaseName | החוזה (שם ה-release; אל תשתמש ב-.Release.Name בתבניות) |
valueFiles | קבצים ב-gitops, תחת $values/ |
destination.namespace | <NS> של הסביבה, נוצר ב-bootstrap |