Skip to content

Commit b7c195e

Browse files
committed
fix: Update ArgoCD notifications configuration for context variables
1 parent ce2e4d2 commit b7c195e

2 files changed

Lines changed: 10 additions & 14 deletions

File tree

Act-3/argocd-notifications-config.yaml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@ metadata:
44
name: argocd-notifications-cm
55
namespace: argocd
66
data:
7-
# Cluster name - set this to your cluster context name
8-
# You can set this automatically with: kubectl patch configmap argocd-notifications-cm -n argocd -p "{\"data\":{\"cluster-name\":\"$(kubectl config current-context)\"}}"
9-
cluster-name: "CLUSTER_NAME_PLACEHOLDER"
10-
11-
# Resource Group - set this from node label kubernetes.azure.com/network-resourcegroup
12-
# You can set this automatically with: kubectl patch configmap argocd-notifications-cm -n argocd -p "{\"data\":{\"resource-group\":\"$(kubectl get nodes -o jsonpath='{.items[0].metadata.labels.kubernetes\.azure\.com/network-resourcegroup}')\"}}"
13-
resource-group: "RESOURCE_GROUP_PLACEHOLDER"
7+
# Context variables for notifications
8+
context: |
9+
clusterName: CLUSTER_NAME_PLACEHOLDER
10+
resourceGroup: RESOURCE_GROUP_PLACEHOLDER
1411
1512
# GitHub webhook service configuration
1613
service.webhook.github-webhook: |
@@ -27,12 +24,12 @@ data:
2724
2825
# Trigger on sync failures
2926
trigger.on-sync-failed: |
30-
- when: app.status.operationState.phase in ['Error', 'Failed']
27+
- when: app.status.operationState != nil && app.status.operationState.phase in ['Error', 'Failed']
3128
send: [sync-failed-webhook]
3229
3330
# Trigger on degraded health
3431
trigger.on-health-degraded: |
35-
- when: app.status.health.status == 'Degraded'
32+
- when: app.status.health != nil && app.status.health.status == 'Degraded'
3633
send: [sync-failed-webhook]
3734
3835
# Template for the webhook payload
@@ -50,10 +47,9 @@ data:
5047
"message": "{{.app.status.operationState.message}}",
5148
"revision": "{{.app.status.sync.revision}}",
5249
"repo_url": "{{.app.spec.source.repoURL}}",
53-
"cluster": "$cluster-name",
54-
"resource_group": "$resource-group",
50+
"cluster": "{{.context.clusterName}}",
51+
"resource_group": "{{.context.resourceGroup}}",
5552
"namespace": "{{.app.spec.destination.namespace}}",
56-
"timestamp": "{{.app.status.operationState.finishedAt}}",
5753
"resources": {{toJson .app.status.resources}}
5854
}
5955
}

Act-3/setup-cluster-name.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ RESOURCE_GROUP=$(kubectl get nodes -o jsonpath='{.items[0].metadata.labels.kuber
1010
echo "Setting cluster name in ArgoCD notifications: $CLUSTER_NAME"
1111
echo "Setting resource group in ArgoCD notifications: $RESOURCE_GROUP"
1212

13-
# Update the cluster-name and resource-group in the argocd-notifications-cm ConfigMap
13+
# Update the context in the argocd-notifications-cm ConfigMap
1414
kubectl patch configmap argocd-notifications-cm -n argocd \
15-
-p "{\"data\":{\"cluster-name\":\"$CLUSTER_NAME\",\"resource-group\":\"$RESOURCE_GROUP\"}}"
15+
-p "{\"data\":{\"context\":\"clusterName: $CLUSTER_NAME\\nresourceGroup: $RESOURCE_GROUP\\n\"}}"
1616

1717
# Restart the notifications controller to pick up the change
1818
kubectl rollout restart deployment argocd-notifications-controller -n argocd

0 commit comments

Comments
 (0)