Skip to content

Commit 80a3a9d

Browse files
saumeyaSaumeya Katyal
andauthored
fix: add context to notification (argoproj-labs#1305)
* fix: add condtext to notification Signed-off-by: Saumeya Katyal <skatyal@skatyal-thinkpadt14sgen1.bengluru.csb> changes Signed-off-by: Saumeya Katyal <skatyal@skatyal-thinkpadt14sgen1.bengluru.csb> ci failures Signed-off-by: Saumeya Katyal <skatyal@skatyal-thinkpadt14sgen1.bengluru.csb> review comments Signed-off-by: Saumeya Katyal <skatyal@skatyal-thinkpadt14sgen1.bengluru.csb> * type Signed-off-by: Saumeya Katyal <skatyal@skatyal-thinkpadt14sgen1.bengluru.csb> --------- Signed-off-by: Saumeya Katyal <skatyal@skatyal-thinkpadt14sgen1.bengluru.csb> Co-authored-by: Saumeya Katyal <skatyal@skatyal-thinkpadt14sgen1.bengluru.csb>
1 parent c7c457d commit 80a3a9d

File tree

9 files changed

+61
-0
lines changed

9 files changed

+61
-0
lines changed

api/v1alpha1/notificationsconfiguration_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,6 @@ type NotificationsConfigurationSpec struct {
5757
Services map[string]string `json:"services,omitempty"`
5858
// Subscriptions contain centrally managed global application subscriptions
5959
Subscriptions map[string]string `json:"subscriptions,omitempty"`
60+
// Context is used to define some shared context between all notification templates
61+
Context map[string]string `json:"context,omitempty"`
6062
}

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bundle/manifests/argoproj.io_notificationsconfigurations.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ spec:
3636
description: NotificationsConfigurationSpec allows users to define the
3737
triggers, templates, services, context and subscriptions for the notifications
3838
properties:
39+
context:
40+
additionalProperties:
41+
type: string
42+
description: Context is used to define some shared context between
43+
all notification templates
44+
type: object
3945
services:
4046
additionalProperties:
4147
type: string

config/crd/bases/argoproj.io_notificationsconfigurations.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ spec:
3838
description: NotificationsConfigurationSpec allows users to define the
3939
triggers, templates, services, context and subscriptions for the notifications
4040
properties:
41+
context:
42+
additionalProperties:
43+
type: string
44+
description: Context is used to define some shared context between
45+
all notification templates
46+
type: object
4147
services:
4248
additionalProperties:
4349
type: string

controllers/argocd/notifications.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func (r *ReconcileArgoCD) reconcileNotificationsConfigurationCR(cr *argoproj.Arg
8484
Namespace: cr.Namespace,
8585
},
8686
Spec: v1alpha1.NotificationsConfigurationSpec{
87+
Context: getDefaultNotificationsContext(),
8788
Triggers: getDefaultNotificationsTriggers(),
8889
Templates: getDefaultNotificationsTemplates(),
8990
},

controllers/argocd/notifications_util.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ package argocd
22

33
import argoproj "github.com/argoproj-labs/argocd-operator/api/v1beta1"
44

5+
// getDefaultNotificationsContext returns an empty map for context
6+
func getDefaultNotificationsContext() map[string]string {
7+
notificationContext := make(map[string]string)
8+
return notificationContext
9+
}
10+
511
// getDefaultNotificationsTemplates returns a map that contains default template configurations
612
func getDefaultNotificationsTemplates() map[string]string {
713

controllers/notificationsconfiguration/configmap.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ func (r *NotificationsConfigurationReconciler) reconcileNotificationsConfigmap(c
6060
expectedConfiguration[k] = v
6161
}
6262

63+
if cr.Spec.Context != nil {
64+
expectedConfiguration["context"] = mapToString(cr.Spec.Context)
65+
}
66+
6367
if !reflect.DeepEqual(expectedConfiguration, NotificationsConfigMap.Data) {
6468
NotificationsConfigMap.Data = expectedConfiguration
6569
err := r.Client.Update(context.TODO(), NotificationsConfigMap)
@@ -71,3 +75,10 @@ func (r *NotificationsConfigurationReconciler) reconcileNotificationsConfigmap(c
7175
// Do nothing
7276
return nil
7377
}
78+
func mapToString(m map[string]string) string {
79+
result := ""
80+
for key, value := range m {
81+
result += fmt.Sprintf("%s: %s\n", key, value)
82+
}
83+
return result
84+
}

deploy/olm-catalog/argocd-operator/0.9.0/argoproj.io_notificationsconfigurations.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ spec:
3636
description: NotificationsConfigurationSpec allows users to define the
3737
triggers, templates, services, context and subscriptions for the notifications
3838
properties:
39+
context:
40+
additionalProperties:
41+
type: string
42+
description: Context is used to define some shared context between
43+
all notification templates
44+
type: object
3945
services:
4046
additionalProperties:
4147
type: string

docs/reference/notificationsconfiguration.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Name | Default | Description
1616
**Triggers** | [Empty] | Templates are used to generate the notification template message.
1717
**Services** | [Empty] | Services are used to deliver message.
1818
**Subscriptions** | [Empty] | Subscriptions contain centrally managed global application subscriptions.
19+
**Context** | [Empty] | Context is used to define some shared context between all notification templates.
1920

2021
## Templates Example
2122

@@ -92,3 +93,18 @@ spec:
9293
triggers:
9394
- on-sync-status-unknown
9495
```
96+
97+
## Context Example
98+
99+
The following example shows how to add Context to the `argocd-notification-cm` using the `default-notifications-configuration` custom resource.
100+
101+
``` yaml
102+
apiVersion: argoproj.io/v1alpha1
103+
kind: NotificationsConfiguration
104+
metadata:
105+
name: default-notifications-configuration
106+
spec:
107+
context:
108+
region: east
109+
environmentName: staging
110+
```

0 commit comments

Comments
 (0)