From 23abc484c70295763b5189895a175f1e743bf10e Mon Sep 17 00:00:00 2001 From: chemavx Date: Fri, 12 Jun 2026 15:31:07 +0000 Subject: [PATCH] feat(argocd): recover Telegram notifications (failed/degraded) and prune for polymarket-bot - Notifications via generic webhook to the Telegram Bot API: the engine's native telegram service only supports channels and negative group IDs, so a positive private chat_id never worked ("chat not found"). - Only on-sync-failed and on-health-degraded triggers; on-sync-succeeded dropped (CI already reports successful deploys). - Subscribe annotations on polymarket-bot, researchowl and n8n. - prune: true on polymarket-bot, guarded by Prune=false on the postgres PVC so removing the manifest from git can never destroy the data. Co-Authored-By: Claude Fable 5 --- argocd/application-n8n.yaml | 3 ++ argocd/application-polymarket-bot.yaml | 4 ++ argocd/application-researchowl.yaml | 2 + argocd/configmap-argocd-notifications-cm.yaml | 45 ++++++++++--------- polymarket-bot/pvc-data-postgres-0.yaml | 2 + 5 files changed, 34 insertions(+), 22 deletions(-) diff --git a/argocd/application-n8n.yaml b/argocd/application-n8n.yaml index 9143b1a..94baa2c 100644 --- a/argocd/application-n8n.yaml +++ b/argocd/application-n8n.yaml @@ -3,6 +3,9 @@ kind: Application metadata: name: n8n namespace: argocd + annotations: + notifications.argoproj.io/subscribe.on-sync-failed.telegram: "5138407666" + notifications.argoproj.io/subscribe.on-health-degraded.telegram: "5138407666" spec: destination: namespace: n8n diff --git a/argocd/application-polymarket-bot.yaml b/argocd/application-polymarket-bot.yaml index 94db263..839a3cb 100644 --- a/argocd/application-polymarket-bot.yaml +++ b/argocd/application-polymarket-bot.yaml @@ -3,6 +3,9 @@ kind: Application metadata: name: polymarket-bot namespace: argocd + annotations: + notifications.argoproj.io/subscribe.on-sync-failed.telegram: "5138407666" + notifications.argoproj.io/subscribe.on-health-degraded.telegram: "5138407666" spec: destination: namespace: polymarket-bot @@ -14,4 +17,5 @@ spec: targetRevision: main syncPolicy: automated: + prune: true selfHeal: true diff --git a/argocd/application-researchowl.yaml b/argocd/application-researchowl.yaml index ec5eafc..053f8a5 100644 --- a/argocd/application-researchowl.yaml +++ b/argocd/application-researchowl.yaml @@ -5,6 +5,8 @@ metadata: namespace: argocd annotations: argocd.argoproj.io/tracking-id: researchowl:argoproj.io/Application:argocd/researchowl + notifications.argoproj.io/subscribe.on-sync-failed.telegram: "5138407666" + notifications.argoproj.io/subscribe.on-health-degraded.telegram: "5138407666" spec: destination: namespace: researchowl diff --git a/argocd/configmap-argocd-notifications-cm.yaml b/argocd/configmap-argocd-notifications-cm.yaml index 2ab38be..84203f1 100644 --- a/argocd/configmap-argocd-notifications-cm.yaml +++ b/argocd/configmap-argocd-notifications-cm.yaml @@ -8,35 +8,36 @@ metadata: name: argocd-notifications-cm namespace: argocd data: - service.telegram: | - token: $telegram-token - - template.app-sync-succeeded: | - telegram: - message: | - ✅ ArgoCD: {{.app.metadata.name}} sync completado - Revisión: {{.app.status.operationState.syncResult.revision | trunc 8}} + # The native telegram service of the notifications engine only supports + # channels (@name) and negative group chat IDs; a positive private chat ID + # like ours gets sent as "@" and fails with "chat not found". Workaround: + # a generic webhook service against the Telegram Bot API, which accepts any + # chat_id. The service is still named "telegram" so the subscribe annotations + # read naturally. + service.webhook.telegram: | + url: https://api.telegram.org/bot$telegram-token/sendMessage + headers: + - name: Content-Type + value: application/json template.app-sync-failed: | - telegram: - message: | - ❌ ArgoCD: {{.app.metadata.name}} sync fallido - {{if .app.status.operationState.message}}Error: {{.app.status.operationState.message}}{{end}} + webhook: + telegram: + method: POST + body: | + {"chat_id": "5138407666", "text": {{toJson (printf "❌ ArgoCD: %s sync fallido\n%s" .app.metadata.name (or .app.status.operationState.message ""))}}} template.app-degraded: | - telegram: - message: | - ⚠️ ArgoCD: {{.app.metadata.name}} degradada - Health: {{.app.status.health.status}} - - trigger.on-sync-succeeded: | - - when: app.status.operationState.phase in ['Succeeded'] - send: [app-sync-succeeded] + webhook: + telegram: + method: POST + body: | + {"chat_id": "5138407666", "text": {{toJson (printf "⚠️ ArgoCD: %s degradada\nHealth: %s" .app.metadata.name .app.status.health.status)}}} trigger.on-sync-failed: | - - when: app.status.operationState.phase in ['Error', 'Failed'] + - when: app.status.operationState != nil && app.status.operationState.phase in ['Error', 'Failed'] send: [app-sync-failed] - trigger.on-degraded: | + trigger.on-health-degraded: | - when: app.status.health.status == 'Degraded' send: [app-degraded] diff --git a/polymarket-bot/pvc-data-postgres-0.yaml b/polymarket-bot/pvc-data-postgres-0.yaml index 62b1975..58731c9 100644 --- a/polymarket-bot/pvc-data-postgres-0.yaml +++ b/polymarket-bot/pvc-data-postgres-0.yaml @@ -2,6 +2,8 @@ apiVersion: v1 kind: PersistentVolumeClaim metadata: annotations: + # Never let ArgoCD prune this PVC: it holds the paper-trading postgres data. + argocd.argoproj.io/sync-options: Prune=false pv.kubernetes.io/bind-completed: 'yes' pv.kubernetes.io/bound-by-controller: 'yes' volume.beta.kubernetes.io/storage-provisioner: rancher.io/local-path