Skip to content

Comments

[Core] Refactor InferenceService workload reconciliation#506

Open
bcfre wants to merge 1 commit intosgl-project:mainfrom
bcfre:workload
Open

[Core] Refactor InferenceService workload reconciliation#506
bcfre wants to merge 1 commit intosgl-project:mainfrom
bcfre:workload

Conversation

@bcfre
Copy link
Contributor

@bcfre bcfre commented Jan 18, 2026

What this PR does

This PR refactors the InferenceService controller's workload reconciliation logic by introducing a strategy pattern. The original tightly coupled component reconciliation logic has been extracted into a flexible, extensible workload strategy framework.

Why we need it

Motivation

#505

The original controller implementation had several limitations:

  • Component reconciliation logic was tightly coupled within the main controller
  • Difficult to extend for different deployment scenarios (e.g., All-in-One, RBG)
  • Hard to maintain and test individual reconciliation strategies

New Components

  1. Workload Strategy Framework (pkg/controller/v1beta1/inferenceservice/workload/)

    • strategy.go: Defines the WorkloadStrategy interface
    • manager.go: Implements WorkloadStrategyManager for strategy registration and selection
    • types.go: Defines WorkloadReconcileRequest and ComponentDeploymentModes data structures
    • single_component_strategy.go: Implements the default SingleComponentStrategy
  2. Strategy Interface Methods

    • GetStrategyName(): Returns strategy name
    • IsApplicable(): Determines if strategy applies to current InferenceService
    • ValidateDeploymentModes(): Validates component deployment modes
    • ReconcileWorkload(): Executes workload reconciliation

Modified Components

  1. InferenceService Controller (pkg/controller/v1beta1/inferenceservice/controller.go)
    • Added StrategyManager field to controller struct
    • Refactored reconciliation flow:
      • Strategy selection (Step 5)
      • Build WorkloadReconcileRequest (Step 7)
      • Execute workload reconciliation via strategy (Step 8)
    • Initialize and register strategies in SetupWithManager()

Fixes None

How to test

apiVersion: ome.io/v1beta1
kind: InferenceService
metadata:
  name: qwen3-0-6b
spec:
  model:
    name: qwen3-0-6b
  runtime:
    name: srt-qwen3-0-6b
  engine:
    minReplicas: 1
    maxReplicas: 1
NAMESPACE  NAME                                             READY  REASON  AGE
default    InferenceService/qwen3-0-6b                      True           4m38s
default    ├─ConfigMap/modelconfig-qwen3-0-6b             -              4m38s
default    ├─Deployment/qwen3-0-6b-engine                 -              4m38s
default    │ └─ReplicaSet/qwen3-0-6b-engine-5bf986dbc5   -              4m38s
default    │   └─Pod/qwen3-0-6b-engine-5bf986dbc5-dq6md  True           4m38s
default    ├─HorizontalPodAutoscaler/qwen3-0-6b-engine    -              4m38s
default    ├─PodDisruptionBudget/qwen3-0-6b-engine        -              4m38s
default    ├─Service/qwen3-0-6b                           -              4m38s
default    │ └─EndpointSlice/qwen3-0-6b-pf7dn            -              4m38s
default    └─Service/qwen3-0-6b-engine                    -              4m38s
default      └─EndpointSlice/qwen3-0-6b-engine-lx9dh      -              4m38s
apiVersion: ome.io/v1beta1
kind: InferenceService
metadata:
  name: qwen3-0-6b-mn-pd
spec:
  model:
    name: qwen3-0-6b
  runtime:
    name: srt-qwen3-0-6b-mn-pd
  router:
    minReplicas: 1
    maxReplicas: 1
  engine:
    minReplicas: 1
    maxReplicas: 1
  decoder:
    minReplicas: 1
    maxReplicas: 1
NAMESPACE  NAME                                                                       READY  REASON  AGE
default    InferenceService/qwen3-0-6b-mn-pd                                          True           94s
default    ├─ConfigMap/modelconfig-qwen3-0-6b-mn-pd                                 -              94s
default    ├─Deployment/qwen3-0-6b-mn-pd-router                                     -              94s
default    │ └─ReplicaSet/qwen3-0-6b-mn-pd-router-567ddd9c9                        -              94s
default    │   └─Pod/qwen3-0-6b-mn-pd-router-567ddd9c9-9bwlz                       True           94s
default    ├─HorizontalPodAutoscaler/qwen3-0-6b-mn-pd-router                        -              94s
default    ├─LeaderWorkerSet/lws-qwen3-0-6b-mn-pd-decoder                           -              94s
default    │ ├─ControllerRevision/lws-qwen3-0-6b-mn-pd-decoder-57bc5b599-1         -              94s
default    │ ├─Service/lws-qwen3-0-6b-mn-pd-decoder                                -              94s
default    │ │ └─EndpointSlice/lws-qwen3-0-6b-mn-pd-decoder-trdsj                 -              94s
default    │ └─StatefulSet/lws-qwen3-0-6b-mn-pd-decoder                            -              94s
default    │   ├─ControllerRevision/lws-qwen3-0-6b-mn-pd-decoder-7647777b9f        -              94s
default    │   └─Pod/lws-qwen3-0-6b-mn-pd-decoder-0                                True           94s
default    │     └─StatefulSet/lws-qwen3-0-6b-mn-pd-decoder-0                      -              94s
default    │       ├─ControllerRevision/lws-qwen3-0-6b-mn-pd-decoder-0-5b5fc6d558  -              94s
default    │       └─Pod/lws-qwen3-0-6b-mn-pd-decoder-0-1                          True           94s
default    ├─LeaderWorkerSet/lws-qwen3-0-6b-mn-pd-engine                            -              94s
default    │ ├─ControllerRevision/lws-qwen3-0-6b-mn-pd-engine-74749ccbc9-1         -              94s
default    │ ├─Service/lws-qwen3-0-6b-mn-pd-engine                                 -              94s
default    │ │ └─EndpointSlice/lws-qwen3-0-6b-mn-pd-engine-kwdfk                  -              94s
default    │ └─StatefulSet/lws-qwen3-0-6b-mn-pd-engine                             -              94s
default    │   ├─ControllerRevision/lws-qwen3-0-6b-mn-pd-engine-7c756577b          -              94s
default    │   └─Pod/lws-qwen3-0-6b-mn-pd-engine-0                                 True           94s
default    │     └─StatefulSet/lws-qwen3-0-6b-mn-pd-engine-0                       -              94s
default    │       ├─ControllerRevision/lws-qwen3-0-6b-mn-pd-engine-0-674d8c78cb   -              94s
default    │       └─Pod/lws-qwen3-0-6b-mn-pd-engine-0-1                           True           94s
default    ├─PodDisruptionBudget/qwen3-0-6b-mn-pd-router                            -              94s
default    ├─Role/qwen3-0-6b-mn-pd-router                                           -              94s
default    ├─RoleBinding/qwen3-0-6b-mn-pd-router                                    -              94s
default    ├─Service/qwen3-0-6b-mn-pd                                               -              94s
default    │ └─EndpointSlice/qwen3-0-6b-mn-pd-82l4j                                -              94s
default    ├─Service/qwen3-0-6b-mn-pd-decoder                                       -              94s
default    │ └─EndpointSlice/qwen3-0-6b-mn-pd-decoder-zp7qp                        -              94s
default    ├─Service/qwen3-0-6b-mn-pd-engine                                        -              94s
default    │ └─EndpointSlice/qwen3-0-6b-mn-pd-engine-bd5lz                         -              94s
default    ├─Service/qwen3-0-6b-mn-pd-router                                        -              94s
default    │ └─EndpointSlice/qwen3-0-6b-mn-pd-router-m898l                         -              94s
default    └─ServiceAccount/qwen3-0-6b-mn-pd-router                                 -              94s

Checklist

  • Tests added/updated (if applicable)
  • Docs updated (if applicable)
  • make test passes locally

@github-actions github-actions bot added inferenceservice InferenceService controller changes controller Controller changes tests Test changes labels Jan 18, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @bcfre, 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 significantly refactors the InferenceService controller by implementing a strategy pattern for workload reconciliation. The change decouples the component-specific reconciliation logic from the main controller, making the system more modular and adaptable. This new architecture allows for easier integration of diverse deployment strategies and enhances the overall maintainability and extensibility of the InferenceService controller.

Highlights

  • Strategy Pattern Implementation: Introduced a strategy pattern for InferenceService workload reconciliation, moving from tightly coupled component logic to a flexible and extensible framework.
  • New Workload Package: Added a new workload package containing the WorkloadStrategy interface, WorkloadStrategyManager for managing strategies, WorkloadReconcileRequest for encapsulating reconciliation parameters, and a default SingleComponentStrategy.
  • Controller Refactoring: The main InferenceServiceReconciler has been refactored to utilize the new WorkloadStrategyManager for selecting and executing the appropriate workload reconciliation strategy, significantly simplifying its core logic.
  • Improved Extensibility and Maintainability: This refactoring aims to make the controller easier to extend for different deployment scenarios (e.g., All-in-One, RBG) and improve the maintainability and testability of individual reconciliation strategies.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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.

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.

Copy link
Contributor

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

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 is a great refactoring that introduces a strategy pattern for workload reconciliation, making the controller more flexible and extensible. The separation of concerns is well-executed with the new workload package.

My review includes a few points of feedback:

  • A critical issue in the WorkloadStrategyManager where using a map for strategies breaks the intended selection order.
  • A medium-severity suggestion to improve context propagation through the new strategy framework.
  • A recommendation to enhance test coverage for the new SingleComponentStrategy.

@bcfre bcfre force-pushed the workload branch 2 times, most recently from f71e6a6 to 8b52252 Compare January 19, 2026 03:14
@bcfre
Copy link
Contributor Author

bcfre commented Jan 19, 2026

/gemini review

Copy link
Contributor

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

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 significant and valuable refactoring of the InferenceService controller by implementing a strategy pattern for workload reconciliation. This change greatly improves the modularity, extensibility, and testability of the controller logic. The introduction of the WorkloadStrategyManager and the SingleComponentStrategy effectively decouples the core reconciliation loop from the specific deployment logic. The new components are well-structured and the accompanying tests are thorough. I have a couple of suggestions to further improve the robustness and clarity of the new implementation.

@bcfre
Copy link
Contributor Author

bcfre commented Jan 26, 2026

@slin1237 Could you please review this PR. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

controller Controller changes inferenceservice InferenceService controller changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant