Skip to content

Commit e979a3f

Browse files
authored
feat: Support notifications in any namespace (#1912)
* Support notifications in any namespace Signed-off-by: nmirasch <neus.miras@gmail.com> * Removed cluster roles and added self-service-notification-enabled to command Signed-off-by: nmirasch <neus.miras@gmail.com> * Add NotificationsConfiguration CR in the spec.notifications.sourceNamespaces Signed-off-by: nmirasch <neus.miras@gmail.com> * Add empty NotificationsConfiguration CR in the source namespaces instead of propagating the configs Signed-off-by: nmirasch <neus.miras@gmail.com> * Create NotificationsConfiguration CR in the source namespaces without spec Signed-off-by: nmirasch <neus.miras@gmail.com> --------- Signed-off-by: nmirasch <neus.miras@gmail.com>
1 parent 387aad6 commit e979a3f

File tree

14 files changed

+798
-23
lines changed

14 files changed

+798
-23
lines changed

api/v1alpha1/argocd_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,9 @@ type ArgoCDNotifications struct {
329329
// Enabled defines whether argocd-notifications controller should be deployed or not
330330
Enabled bool `json:"enabled"`
331331

332+
// SourceNamespaces is a list of namespaces from which the notifications controller will watch for ArgoCD Application resources.
333+
SourceNamespaces []string `json:"sourceNamespaces,omitempty"`
334+
332335
// Env let you specify environment variables for Notifications pods
333336
Env []corev1.EnvVar `json:"env,omitempty"`
334337

api/v1alpha1/argocd_types_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,14 @@ func Test_ParseResourceTrackingMethod(t *testing.T) {
4747
assert.Equal(t, tt.rtm, ParseResourceTrackingMethod(tt.str))
4848
}
4949
}
50+
51+
func Test_ArgoCDNotifications_SourceNamespaces(t *testing.T) {
52+
notifications := ArgoCDNotifications{
53+
SourceNamespaces: []string{"ns1", "ns2"},
54+
}
55+
assert.Equal(t, []string{"ns1", "ns2"}, notifications.SourceNamespaces)
56+
57+
// Test omitempty (zero value)
58+
emptyNotifications := ArgoCDNotifications{}
59+
assert.Nil(t, emptyNotifications.SourceNamespaces)
60+
}

api/v1alpha1/zz_generated.deepcopy.go

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

api/v1beta1/argocd_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,9 @@ type ArgoCDNotifications struct {
411411
// Enabled defines whether argocd-notifications controller should be deployed or not
412412
Enabled bool `json:"enabled"`
413413

414+
// SourceNamespaces is a list of namespaces from which the notifications controller will watch for ArgoCD Notification resources.
415+
SourceNamespaces []string `json:"sourceNamespaces,omitempty"`
416+
414417
// Env let you specify environment variables for Notifications pods
415418
Env []corev1.EnvVar `json:"env,omitempty"`
416419

api/v1beta1/argocd_types_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,14 @@ func Test_ParseResourceTrackingMethod(t *testing.T) {
4747
assert.Equal(t, tt.rtm, ParseResourceTrackingMethod(tt.str))
4848
}
4949
}
50+
51+
func Test_ArgoCDNotifications_SourceNamespaces(t *testing.T) {
52+
notifications := ArgoCDNotifications{
53+
SourceNamespaces: []string{"ns1", "ns2"},
54+
}
55+
assert.Equal(t, []string{"ns1", "ns2"}, notifications.SourceNamespaces)
56+
57+
// Test omitempty (zero value)
58+
emptyNotifications := ArgoCDNotifications{}
59+
assert.Nil(t, emptyNotifications.SourceNamespaces)
60+
}

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 5 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_argocds.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,6 +2011,13 @@ spec:
20112011
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
20122012
type: object
20132013
type: object
2014+
sourceNamespaces:
2015+
description: SourceNamespaces is a list of namespaces from which
2016+
the notifications controller will watch for ArgoCD Application
2017+
resources.
2018+
items:
2019+
type: string
2020+
type: array
20142021
version:
20152022
description: Version is the Argo CD Notifications image tag. (optional)
20162023
type: string
@@ -17115,6 +17122,13 @@ spec:
1711517122
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
1711617123
type: object
1711717124
type: object
17125+
sourceNamespaces:
17126+
description: SourceNamespaces is a list of namespaces from which
17127+
the notifications controller will watch for ArgoCD Notification
17128+
resources.
17129+
items:
17130+
type: string
17131+
type: array
1711817132
version:
1711917133
description: Version is the Argo CD Notifications image tag. (optional)
1712017134
type: string

common/keys.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,12 @@ const (
214214
// ArgoCDManagedByClusterArgoCDLabel is needed to identify namespace mentioned as sourceNamespace on ArgoCD
215215
ArgoCDManagedByClusterArgoCDLabel = "argocd.argoproj.io/managed-by-cluster-argocd"
216216

217-
// ArgoCDManagedByClusterArgoCDLabel is needed to identify namespace mentioned as sourceNamespace on ArgoCD
217+
// ArgoCDApplicationSetManagedByClusterArgoCDLabel is needed to identify namespace mentioned as applicationSet sourceNamespaces on ArgoCD
218218
ArgoCDApplicationSetManagedByClusterArgoCDLabel = "argocd.argoproj.io/applicationset-managed-by-cluster-argocd"
219219

220+
// ArgoCDNotificationsManagedByClusterArgoCDLabel is needed to identify namespace mentioned as notifications sourceNamespaces on ArgoCD
221+
ArgoCDNotificationsManagedByClusterArgoCDLabel = "argocd.argoproj.io/notifications-managed-by-cluster-argocd"
222+
220223
// ArgoCDControllerClusterRoleEnvName is an environment variable to specify a custom cluster role for Argo CD application controller
221224
ArgoCDControllerClusterRoleEnvName = "CONTROLLER_CLUSTER_ROLE"
222225

config/crd/bases/argoproj.io_argocds.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,6 +2000,13 @@ spec:
20002000
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
20012001
type: object
20022002
type: object
2003+
sourceNamespaces:
2004+
description: SourceNamespaces is a list of namespaces from which
2005+
the notifications controller will watch for ArgoCD Application
2006+
resources.
2007+
items:
2008+
type: string
2009+
type: array
20032010
version:
20042011
description: Version is the Argo CD Notifications image tag. (optional)
20052012
type: string
@@ -17104,6 +17111,13 @@ spec:
1710417111
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
1710517112
type: object
1710617113
type: object
17114+
sourceNamespaces:
17115+
description: SourceNamespaces is a list of namespaces from which
17116+
the notifications controller will watch for ArgoCD Notification
17117+
resources.
17118+
items:
17119+
type: string
17120+
type: array
1710717121
version:
1710817122
description: Version is the Argo CD Notifications image tag. (optional)
1710917123
type: string

controllers/argocd/argocd_controller.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ type ReconcileArgoCD struct {
7878
ManagedSourceNamespaces map[string]string
7979
// Stores a list of ApplicationSetSourceNamespaces as keys
8080
ManagedApplicationSetSourceNamespaces map[string]string
81+
82+
// Stores a list of NotificationsSourceNamespaces as keys
83+
ManagedNotificationsSourceNamespaces map[string]string
84+
8185
// Stores label selector used to reconcile a subset of ArgoCD
8286
LabelSelector string
8387

@@ -255,6 +259,9 @@ func (r *ReconcileArgoCD) internalReconcile(ctx context.Context, request ctrl.Re
255259
if err := r.removeUnmanagedApplicationSetSourceNamespaceResources(argocd); err != nil {
256260
return reconcile.Result{}, argocd, argoCDStatus, fmt.Errorf("failed to remove resources from applicationSetSourceNamespaces, error: %w", err)
257261
}
262+
if err := r.removeUnmanagedNotificationsSourceNamespaceResources(argocd); err != nil {
263+
return reconcile.Result{}, argocd, argoCDStatus, fmt.Errorf("failed to remove resources from notificationsSourceNamespaces, error: %w", err)
264+
}
258265

259266
if err := r.removeDeletionFinalizer(argocd); err != nil {
260267
return reconcile.Result{}, argocd, argoCDStatus, err
@@ -285,7 +292,9 @@ func (r *ReconcileArgoCD) internalReconcile(ctx context.Context, request ctrl.Re
285292
if err = r.setManagedApplicationSetSourceNamespaces(argocd); err != nil {
286293
return reconcile.Result{}, argocd, argoCDStatus, err
287294
}
288-
295+
if err = r.setManagedNotificationsSourceNamespaces(argocd); err != nil {
296+
return reconcile.Result{}, argocd, argoCDStatus, err
297+
}
289298
// Handle NamespaceManagement reconciliation and check if Namespace Management is enabled via the Subscription env variable.
290299
if isNamespaceManagementEnabled() {
291300
if err := r.reconcileNamespaceManagement(argocd); err != nil {

0 commit comments

Comments
 (0)