Skip to content

feat: Introduce ContactGroupEnrollmentPolicy and controller to automate contact group memberships.#603

Merged
JoseSzycho merged 5 commits into
mainfrom
668-default-contact-group-enrollment-for-new-users
May 20, 2026
Merged

feat: Introduce ContactGroupEnrollmentPolicy and controller to automate contact group memberships.#603
JoseSzycho merged 5 commits into
mainfrom
668-default-contact-group-enrollment-for-new-users

Conversation

@JoseSzycho
Copy link
Copy Markdown
Contributor

@JoseSzycho JoseSzycho commented May 6, 2026

Pull Request: Implement ContactGroupEnrollmentPolicy and Controller

Title

feat(notification): implement ContactGroupEnrollmentPolicy and controller for automated memberships

Description

This PR introduces the ContactGroupEnrollmentPolicy API and its corresponding controller to automate the enrollment of newly created contacts into designated contact groups. It also includes comprehensive E2E integration tests, API registration, and auto-generated manifests.

Key Changes

1. API Definition (ContactGroupEnrollmentPolicy)

  • Introduced a new cluster-scoped CRD: ContactGroupEnrollmentPolicy (notification.miloapis.com/v1alpha1).
  • Spec details:
    • contactGroupRef: Specifies the target group (name and namespace) for enrollment.
    • trigger: Defines when enrollment happens (e.g. type: ContactCreated).
    • contactSelector (optional): Enables filtering by SubjectKind (e.g. User).
  • Generated Deepcopy and CRD manifests.

2. Reconciler (ContactGroupEnrollmentController)

  • Watches Contact and ContactGroupEnrollmentPolicy resources.
  • Automatically creates ContactGroupMembership records for matching policies when a contact is created.
  • Opt-Out Handling: Inspects existing ContactGroupMembershipRemoval records and skips enrollment for opted-out contacts.
  • Idempotency: Annotates processed contacts with evaluated policies using enrollment.notification.miloapis.com/{policyName} = true to avoid duplicate reconciliations.
  • Webhook Handling: Gracefully handles and skips non-retryable admission webhook rejections (e.g. duplicate memberships or opt-out collisions).
  • Efficiency: Configures a field indexer on ContactGroupMembershipRemoval by spec.contactRef.name for fast lookup.

3. Controller Manager Integration

  • Registered the controller within cmd/milo/controller-manager/controllermanager.go.
  • Generated RBAC permissions required for managing contacts, contactgroupenrollmentpolicies, contactgroupmemberships, and contactgroupmembershipremovals.

4. End-to-End Tests

  • Added a robust suite of chainsaw integration tests under test/notification/contact-group-enrollment/ covering:
    1. Enrollment of Contacts with User subject references.
    2. Exclusion of Contacts not matching the selector (e.g. bare contacts).
    3. Honoring pre-existing opt-out removal records.
    4. Idempotency validation (duplicate runs do not cause duplicates).
    5. Retroactive enrollment of existing Contacts when a new policy is created.
    6. End-to-end flow from User registration to Contact creation and ContactGroupMembership enrollment.

Verification Results

All E2E tests have passed successfully:

--- PASS: chainsaw (25.51s)
    --- PASS: chainsaw/contact-group-enrollment (13.48s)

@JoseSzycho JoseSzycho marked this pull request as draft May 6, 2026 12:13
@joggrbot

This comment has been minimized.

@JoseSzycho JoseSzycho force-pushed the 668-default-contact-group-enrollment-for-new-users branch from f24676e to b249d2a Compare May 19, 2026 18:57
@JoseSzycho JoseSzycho marked this pull request as ready for review May 19, 2026 19:07
@JoseSzycho JoseSzycho merged commit 28a7f77 into main May 20, 2026
5 checks passed
@JoseSzycho JoseSzycho deleted the 668-default-contact-group-enrollment-for-new-users branch May 20, 2026 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default Contact Group Enrollment for New Users

2 participants