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

chore: Refactor Mandatorymodule controller to 3 tier structure #2283

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

ruanxin
Copy link
Contributor

@ruanxin ruanxin commented Feb 27, 2025

Description

This PR introduces a layered architecture for the mandatory module controller, aiming to improve the maintainability and scalability of the KLM (Kyma Lifecycle Manager) codebase. This serves as an example for team discussions on refining the overall reconciliation logic and guiding future refactoring efforts.

Proposed Architecture

1. Reconciliation Controller Tier

This layer acts as the entry point for the reconciliation process and is responsible for handling all reconcile related logic.

  • The controller remains lightweight, focusing on processing reconciliation requests and delegating business logic to the appropriate domain models.
  • Business logic does not handle ctrl.Result directly—this ensures clear separation and avoids tight coupling between reconciliation flow and business processing.
  • This tier also ensures proper error handling and requeue strategies, abstracting them away from the business logic.

2. Business Logic Tier

The business logic layer is structured based on Domain-Driven Design (DDD) principles.

  • Logic is encapsulated within domain models, which categorize different aspects of the system.
  • Each Custom Resource Definition (CRD) naturally maps to a domain model, but we avoid fat domain models by further specializing models where appropriate.
    • Example: The module concept does not have a dedicated CRD, so we introduce distinct models such as Regular Module and Mandatory Module.
    • Instead of designing monolithic domain models with excessive behavior, we ensure that dependencies are structured properly to avoid creating a domain service with all dependencies.
  • This approach ensures better modularity and reusability, preventing bloated domain models while maintaining clear separation of concerns.

3. Data Tier

The data tier is strictly responsible for data access and persistence, ensuring domain models remain independent of direct API interactions.

  • All interactions with the API Server are encapsulated within repositories, which are designed specifically for each CRD.
  • This ensures domain models do not handle data access logic directly, reinforcing the principles of clean architecture.

Key Benefits of This Approach

Maintainability – Changes in one layer do not impact others directly.
Scalability – Easier to introduce new features and extend domain logic.
Testability – Each tier can be tested independently, improving reliability.
Clarity & Separation of Concerns – Avoids tightly coupled logic between reconciliation, business rules, and data access.

@ruanxin ruanxin requested a review from a team as a code owner February 27, 2025 09:58
@kyma-bot kyma-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cla: yes Indicates the PR's author has signed the CLA. labels Feb 27, 2025
@ruanxin ruanxin changed the title chore: add service repository chore: Refactor to layered Structure Feb 27, 2025
@kyma-bot kyma-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 27, 2025
@ruanxin ruanxin changed the title chore: Refactor to layered Structure chore: Refactor Mandatorymodule controller to 3 tier structure Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Indicates the PR's author has signed the CLA. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants