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: Allow notifications controller to notify on all namespaces (cont.) #15247

Conversation

sthomson-wyn
Copy link
Contributor

This is a continuation of #13352 which addresses the following:
#13352 (comment)
#13352 (comment)
#13352 (comment)

This adds functionality to the notifications controller to be notified of and send notifications for applications in any namespace. The namespaces to watch are controlled by the same --application-namespaces and ARGOCD_APPLICATION_NAMESPACES variables as in the application controller.

Closes #12912
Closes #11252

Checklist:

  • Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this does not need to be in the release notes.
  • The title of the PR states what changed and the related issues number (used for the release note).
  • The title of the PR conforms to the Toolchain Guide
  • I've included "Closes [ISSUE #]" or "Fixes [ISSUE #]" in the description to automatically close the associated issue.
  • I've updated both the CLI and UI to expose my feature, or I plan to submit a second PR with them.
  • Does this PR require documentation updates?
  • I've updated documentation as required by this PR.
  • Optional. My organization is added to USERS.md.
  • I have signed off all my commits as required by DCO
  • I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
  • My build is green (troubleshooting builds).
  • My new feature complies with the feature status guidelines.
  • I have added a brief description of why this PR is necessary and/or what this PR solves.

Niksko and others added 14 commits April 26, 2023 09:20
This adds functionality to the notifications controller to be notified
of and send notifications for applications in any namespace. The
namespaces to watch are controlled by the same --application-namespaces
and ARGOCD_APPLICATION_NAMESPACES variables as in the application
controller.

Signed-off-by: Nikolas Skoufis <nskoufis@seek.com.au>
Signed-off-by: Nikolas Skoufis <nskoufis@seek.com.au>
Signed-off-by: Nikolas Skoufis <nskoufis@seek.com.au>
Signed-off-by: Nik Skoufis <n.skoufis@gmail.com>
Signed-off-by: Nikolas Skoufis <nskoufis@seek.com.au>
Signed-off-by: Stewart Thomson <sthomson@wynshop.com>
Signed-off-by: Stewart Thomson <sthomson@wynshop.com>
…ault)

Signed-off-by: Stewart Thomson <sthomson@wynshop.com>
…l-namespaces

# Conflicts:
#	manifests/install.yaml
#	manifests/namespace-install.yaml
@sthomson-wyn sthomson-wyn force-pushed the notifications-in-all-namespaces branch from 13cfca6 to 46b0404 Compare August 25, 2023 17:46
@codecov
Copy link

codecov bot commented Aug 25, 2023

Codecov Report

Attention: 13 lines in your changes are missing coverage. Please review.

Comparison is base (54601c8) 49.92% compared to head (6e8dd39) 49.91%.
Report is 113 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #15247      +/-   ##
==========================================
- Coverage   49.92%   49.91%   -0.02%     
==========================================
  Files         263      266       +3     
  Lines       45223    46089     +866     
==========================================
+ Hits        22578    23005     +427     
- Misses      20427    20824     +397     
- Partials     2218     2260      +42     
Files Coverage Δ
notification_controller/controller/controller.go 60.15% <50.00%> (-5.37%) ⬇️

... and 32 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Stewart Thomson <sthomson@wynshop.com>
@sthomson-wyn sthomson-wyn force-pushed the notifications-in-all-namespaces branch from 21a3c10 to 4996eea Compare August 25, 2023 18:11
@mayzhang2000
Copy link
Contributor

mayzhang2000 commented Sep 6, 2023

Thank you @sthomson-wyn for the great contribution!

I tested on my local with one finding. Here is my test case:

Two apps:

NAMESPACE NAME
ns1 appns1
ns2 appns2

Notification controller is started with --application-namespaces=ns1

Expected Result: receive notification for appns1
Test Result: received notifications for both appns1 and appns2

Recommended Fix:
In controller.WithSkipProcessing(), add the following:
`
if namespace != app.GetNamespace() && !glob.MatchStringInList(applicationNamespaces, app.GetNamespace(), false) {
return true, "app is not in one of the application-namespaces, nor the notification controller namespace"
}

`

@sthomson-wyn
Copy link
Contributor Author

Thanks @mayzhang2000 , I've added the suggested change via baa28c8

@mayzhang2000
Copy link
Contributor

Thank you @sthomson-wyn!
Tested and worked on my local. Could you please add some tests and documentation?

@@ -38,8 +39,8 @@ var (
appProjects = schema.GroupVersionResource{Group: application.Group, Version: "v1alpha1", Resource: application.AppProjectPlural}
)

func newAppProjClient(client dynamic.Interface, namespace string) dynamic.ResourceInterface {
resClient := client.Resource(appProjects).Namespace(namespace)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? AppProjects are still restricted to only living in the controller namespace.

- "argoproj.io"
resources:
- "applications"
- "appprojects"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since AppProjects only exist in the controller's namespace, I don't think this is necessary at the cluster level.

app.kubernetes.io/name: argocd-notifications-controller-cluster-apps
app.kubernetes.io/part-of: argocd
app.kubernetes.io/component: notifications-controller
name: argocd-notifications-controller-cluster-apps
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the apps-in-any-namespace docs be updated to mention the two new resources?

Comment on lines +82 to +84
if namespace != app.GetNamespace() && !glob.MatchStringInList(applicationNamespaces, app.GetNamespace(), false) {
return true, "app is not in one of the application-namespaces, nor the notification controller namespace"
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get test coverage on this? If a full test of the notificationController would be prohibitively complex, we could pull out this function and just unit-test that.

return resClient.List(context.Background(), options)
appList, err := resClient.List(context.TODO(), options)
if err != nil {
return nil, err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return nil, err
return nil, fmt.Errorf("failed to list applications: %w", err)

@@ -115,6 +115,7 @@ func TestInit(t *testing.T) {
dynamicClient,
nil,
"default",
[]string{},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding some unit tests to cover the apps-in-any-namespace behavior? I think at the minimum we should make sure the notifications controller refuses to manage apps outside the specified namespaces.

@mayzhang2000
Copy link
Contributor

mayzhang2000 commented Sep 27, 2023

Thank you @sthomson-wyn and @crenshaw-dev !

I created below PR as a continuation of this PR.
#15702

…ml's resources

Signed-off-by: May Zhang <may_zhang@intuit.com>
@mayzhang2000 mayzhang2000 requested a review from a team as a code owner October 4, 2023 21:30
@crenshaw-dev
Copy link
Member

Superseded by #15702

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants