Skip to content

Offboard a team from a backend if it's removed from GroupCR - #214

Open
maxkashyap41 wants to merge 3 commits into
redhat-data-and-ai:mainfrom
maxkashyap41:DATA-3526
Open

Offboard a team from a backend if it's removed from GroupCR#214
maxkashyap41 wants to merge 3 commits into
redhat-data-and-ai:mainfrom
maxkashyap41:DATA-3526

Conversation

@maxkashyap41

Copy link
Copy Markdown
Contributor

Changes

📝 Description

What changed?

It handles the problem is the user_group removes any backend (rover/fivetran/gitlab/snowflake) the reconciler simply updates the functionality by removing the group for that specific backend. Also it updates both the groupstore and teamstore.

Why is this change needed?

This changes automates the e2e removal of user_group for a specific backend when the CR state changes and reconciler updates the desired state gracefully automating the process e2e from backend processes to updating the cache store of that particular group.

Dependencies

  • N/A

🧪 Testing

Test Coverage

Performance Impact

  • N/A

🚀 Deployment

Deploy Steps

  1. N/A

Prerequisites

  • N/A

Post-Deployment Monitoring

  • N/A

Rollback Plan

  • N/A

⚠️ Breaking Changes

  • This PR contains breaking changes
  • Migration guide provided (if applicable)

Details:

  • N/A

⚙️ Configuration Changes

  • N/A

✅ Developer Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added positive and negative tests that prove my fix is effective or that my feature works
  • Relevant documentation (README, tech specs, etc.) has been added or updated
  • All CI/CD checks are passing

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a critical automation feature to the Group controller, enabling it to gracefully handle the removal of backend integrations from a Group Custom Resource. Previously, manual intervention might have been required to clean up teams from external systems when their corresponding backend was removed from the Group's specification. This change automates the end-to-end offboarding process, ensuring that when a backend is no longer specified, the associated team is automatically deleted from that backend and relevant cache stores are updated, thereby maintaining data consistency and reducing operational overhead.

Highlights

  • Automated Backend Offboarding: Implemented logic to automatically detect and offboard teams from external backends (e.g., Rover, Fivetran, Snowflake) when those backends are removed from a Group Custom Resource's specification. This ensures that resources are cleaned up consistently.
  • Enhanced Reconciler Logic: Introduced new functions (handleRemovedBackends, detectRemovedBackends, offboardFromRemovedBackends) within the GroupReconciler to manage the lifecycle of backend integrations, specifically for removal scenarios.
  • Cache Locking Refinement: The cache mutex lock in the Reconcile function was moved to an earlier stage to encompass the new backend removal logic, preventing race conditions during concurrent reconciliations.
  • Comprehensive Testing: Added extensive unit tests for the detectRemovedBackends function, covering various edge cases and scenarios to ensure the reliability of backend removal detection.
  • Store Cleanup: Ensured that both the GroupStore and TeamStore are updated and cleaned up appropriately after a backend has been successfully offboarded.
Changelog
  • internal/controller/group_controller.go
    • Moved cache mutex lock to the beginning of the Reconcile function to cover backend removal logic.
    • Added a call to handleRemovedBackends in the Reconcile loop to initiate offboarding for removed backends.
    • Implemented handleRemovedBackends to orchestrate the detection and offboarding process.
    • Introduced getBackendKey helper function for consistent backend identification.
    • Developed detectRemovedBackends to compare spec and status and identify backends no longer present in the spec but active in status.
    • Created offboardFromRemovedBackends to perform the actual deletion of teams from external backends and update internal stores (GroupStore, TeamStore).
    • Improved logging clarity in cleanupUserGroupsIndex.
  • internal/controller/group_controller_test.go
    • Added logrus import for logging in tests.
    • Included new unit tests for the detectRemovedBackends function, covering scenarios like single/multiple backend removals, no removals, and handling of failed backend statuses.
    • Utilized DescribeTable for parameterized testing of detectRemovedBackends edge cases.
Activity
  • The pull request introduces new functionality to automatically offboard teams from backends when they are removed from the Group CR spec.
  • The core reconciliation logic has been updated to incorporate this new offboarding process.
  • New helper functions and a comprehensive offboarding mechanism have been added.
  • Extensive unit tests have been written to validate the backend removal detection logic.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


A backend removed, a team must depart, No longer needed, a fresh, clean start. The controller watches, with vigilant eye, To keep systems tidy, beneath the digital sky.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a key feature to handle the offboarding of teams from backends when they are removed from a Group custom resource, correctly detecting removed backends and orchestrating their cleanup. While the refactoring of the cache lock and the addition of comprehensive unit tests are positive, the implementation has two significant security concerns: a Broken Access Control (IDOR) vulnerability due to GroupName being used as a global identifier without namespace isolation, and a potential Denial of Service (DoS) vulnerability where an expensive network operation (FetchAllTeams) is performed while holding a global lock. Furthermore, the reliance on FetchAllTeams in the new offboarding logic could lead to performance inefficiencies for backends with a large number of teams.

Comment thread internal/controller/group_controller.go
Comment thread internal/controller/group_controller.go
Comment thread internal/controller/group_controller.go
rp926463-arch and others added 2 commits April 13, 2026 21:33
…verage

This PR implements the critical feature to automatically detect and offboard
from backends that have been removed from a Group's specification, ensuring
proper resource cleanup and preventing resource leakage.

- Add handleRemovedBackends() to detect and offboard from removed backends
- Add detectRemovedBackends() to compare spec vs status for removed backends
- Add offboardFromRemovedBackends() to perform cleanup using existing DeleteTeamByID
- Integrate backend removal detection into main Reconcile loop for continuous monitoring

- Add comprehensive unit tests covering all error paths and edge cases
- Test backend deleted while other backends exist (cache updated correctly)
- Test last backend deleted (entire cache entry removed)
- Test error handling for cache operations after backend deletion
- Test graceful handling of cache misses, client creation errors, and transformation failures
- All 18 controller tests passing with 32.9% code coverage

- Implement DRY principle by extracting getBackendKey() helper function
- Replace all duplicate backend key generation logic with helper function
- Enhanced error collection - continues processing all backends even with failures
- Clean up unused imports and resolve all linter errors
- Remove PR reviewer comments from production code

- Robust error handling for group name transformation failures
- Graceful handling of missing backend configurations
- Proper cache management for partial and complete backend removal
- Zero linting issues - production ready

Resolves: DATA-3526
Signed-off-by: Roshan Patil <roshpati@redhat.com>

fix: resolve CI test failures by replacing rover backends with fivetran in tests

- Fixed test panics caused by rover backend global config file loading
- Changed failing tests to use fivetran backends which don't require external config files
- Updated test expectations to match actual error messages
- All 21 controller tests now passing successfully
- Resolves GitHub Actions CI failures

Signed-off-by: Roshan Patil <roshpati@redhat.com>
Signed-off-by: Madhurjya Das <madhurjyakumardas@gmail.com>
…llisions & scan Team details optimizations

Signed-off-by: Madhurjya Das <madhurjyakumardas@gmail.com>

Fixing the review comments on critical issues v2

Signed-off-by: Madhurjya Das <madhurjyakumardas@gmail.com>
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.

3 participants