Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add context to notification (cherry-pick #1305) #1315

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/v1alpha1/notificationsconfiguration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,6 @@ type NotificationsConfigurationSpec struct {
Services map[string]string `json:"services,omitempty"`
// Subscriptions contain centrally managed global application subscriptions
Subscriptions map[string]string `json:"subscriptions,omitempty"`
// Context is used to define some shared context between all notification templates
Context map[string]string `json:"context,omitempty"`
}
7 changes: 7 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions bundle/manifests/argoproj.io_notificationsconfigurations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ spec:
description: NotificationsConfigurationSpec allows users to define the
triggers, templates, services, context and subscriptions for the notifications
properties:
context:
additionalProperties:
type: string
description: Context is used to define some shared context between
all notification templates
type: object
services:
additionalProperties:
type: string
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/argoproj.io_notificationsconfigurations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ spec:
description: NotificationsConfigurationSpec allows users to define the
triggers, templates, services, context and subscriptions for the notifications
properties:
context:
additionalProperties:
type: string
description: Context is used to define some shared context between
all notification templates
type: object
services:
additionalProperties:
type: string
Expand Down
1 change: 1 addition & 0 deletions controllers/argocd/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func (r *ReconcileArgoCD) reconcileNotificationsConfigurationCR(cr *argoproj.Arg
Namespace: cr.Namespace,
},
Spec: v1alpha1.NotificationsConfigurationSpec{
Context: getDefaultNotificationsContext(),
Triggers: getDefaultNotificationsTriggers(),
Templates: getDefaultNotificationsTemplates(),
},
Expand Down
6 changes: 6 additions & 0 deletions controllers/argocd/notifications_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ package argocd

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

// getDefaultNotificationsContext returns an empty map for context
func getDefaultNotificationsContext() map[string]string {
notificationContext := make(map[string]string)
return notificationContext
}

// getDefaultNotificationsTemplates returns a map that contains default template configurations
func getDefaultNotificationsTemplates() map[string]string {

Expand Down
11 changes: 11 additions & 0 deletions controllers/notificationsconfiguration/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ func (r *NotificationsConfigurationReconciler) reconcileNotificationsConfigmap(c
expectedConfiguration[k] = v
}

if cr.Spec.Context != nil {
expectedConfiguration["context"] = mapToString(cr.Spec.Context)
}

if !reflect.DeepEqual(expectedConfiguration, NotificationsConfigMap.Data) {
NotificationsConfigMap.Data = expectedConfiguration
err := r.Client.Update(context.TODO(), NotificationsConfigMap)
Expand All @@ -71,3 +75,10 @@ func (r *NotificationsConfigurationReconciler) reconcileNotificationsConfigmap(c
// Do nothing
return nil
}
func mapToString(m map[string]string) string {
result := ""
for key, value := range m {
result += fmt.Sprintf("%s: %s\n", key, value)
}
return result
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ spec:
description: NotificationsConfigurationSpec allows users to define the
triggers, templates, services, context and subscriptions for the notifications
properties:
context:
additionalProperties:
type: string
description: Context is used to define some shared context between
all notification templates
type: object
services:
additionalProperties:
type: string
Expand Down
16 changes: 16 additions & 0 deletions docs/reference/notificationsconfiguration.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Name | Default | Description
**Triggers** | [Empty] | Templates are used to generate the notification template message.
**Services** | [Empty] | Services are used to deliver message.
**Subscriptions** | [Empty] | Subscriptions contain centrally managed global application subscriptions.
**Context** | [Empty] | Context is used to define some shared context between all notification templates.

## Templates Example

Expand Down Expand Up @@ -92,3 +93,18 @@ spec:
triggers:
- on-sync-status-unknown
```

## Context Example

The following example shows how to add Context to the `argocd-notification-cm` using the `default-notifications-configuration` custom resource.

``` yaml
apiVersion: argoproj.io/v1alpha1
kind: NotificationsConfiguration
metadata:
name: default-notifications-configuration
spec:
context:
region: east
environmentName: staging
```
Loading