Skip to content

Commit

Permalink
fix: add condtext to notification
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Saumeya Katyal committed Apr 18, 2024
1 parent c7c457d commit 7206579
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 0 deletions.
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
```

0 comments on commit 7206579

Please sign in to comment.