Skip to content

[WIP] Adding Support For Configurable Optimizer Config#83

Draft
shekhar316 wants to merge 17 commits into
kruize:mvp_demofrom
shekhar316:optimizer2
Draft

[WIP] Adding Support For Configurable Optimizer Config#83
shekhar316 wants to merge 17 commits into
kruize:mvp_demofrom
shekhar316:optimizer2

Conversation

@shekhar316
Copy link
Copy Markdown
Contributor

@shekhar316 shekhar316 commented Apr 13, 2026

Summary by Sourcery

Introduce a configurable Kruize Optimizer component and integrate it into the operator’s deployment flow alongside existing Kruize services.

New Features:

  • Add Kruize Optimizer deployment and service generation with configurable image and runtime settings via the Kruize custom resource.
  • Expose optimizer-specific configuration and image fields in the Kruize CRD and sample manifest, including environment-driven defaults for the optimizer image.
  • Provide separate generation paths for core Kruize resources and optimizer resources for both OpenShift and Kubernetes clusters.

Enhancements:

  • Extend the resource generator and reconciler logic to deploy components in phases and wait for all Kruize-related pods, including the optimizer, to be ready.

Tests:

  • Update controller unit tests to cover optimizer-aware resource generation and phased core/optimizer resource handling.
  • Extend end-to-end tests to verify that the Kruize Optimizer deployment becomes ready after installation.

Signed-off-by: SHEKHAR SAXENA <shekhar.saxena@ibm.com>
Signed-off-by: Shekhar Saxena <shekhar.saxena@ibm.com>
Signed-off-by: SHEKHAR SAXENA <shekhar.saxena@ibm.com>
Signed-off-by: SHEKHAR SAXENA <shekhar.saxena@ibm.com>
Signed-off-by: SHEKHAR SAXENA <shekhar.saxena@ibm.com>
Signed-off-by: SHEKHAR SAXENA <shekhar.saxena@ibm.com>
Signed-off-by: SHEKHAR SAXENA <shekhar.saxena@ibm.com>
Signed-off-by: SHEKHAR SAXENA <shekhar.saxena@ibm.com>
Signed-off-by: SHEKHAR SAXENA <shekhar.saxena@ibm.com>
Signed-off-by: SHEKHAR SAXENA <shekhar.saxena@ibm.com>
Signed-off-by: SHEKHAR SAXENA <shekhar.saxena@ibm.com>
Signed-off-by: SHEKHAR SAXENA <shekhar.saxena@ibm.com>
Signed-off-by: SHEKHAR SAXENA <shekhar.saxena@ibm.com>
Signed-off-by: SHEKHAR SAXENA <shekhar.saxena@ibm.com>
Signed-off-by: SHEKHAR SAXENA <shekhar.saxena@ibm.com>
Signed-off-by: SHEKHAR SAXENA <shekhar.saxena@ibm.com>
Signed-off-by: SHEKHAR SAXENA <shekhar.saxena@ibm.com>
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Apr 13, 2026

Reviewer's Guide

Adds first-class support for a configurable Kruize Optimizer component (image + config), splits resource generation into core vs optimizer phases, wires it into the reconciler and readiness logic, and updates tests, CRD, types, constants, and sample/e2e configs accordingly.

Sequence diagram for phased deployment of core and optimizer resources

sequenceDiagram
    participant R as KruizeReconciler
    participant G as KruizeResourceGenerator
    participant K8s as KubernetesAPI
    participant OPTD as kruize-optimizer Deployment
    participant INIT as wait-for-kruize init container
    participant KR as kruize Service

    R->>G: NewKruizeResourceGenerator(namespace, autotuneImage, autotuneUIImage, optimizerImage, clusterType, kruizeSpec, ctx)
    activate G
    G-->>R: KruizeResourceGenerator instance
    deactivate G

    R->>G: CoreNamespacedResources() or CoreKubernetesNamespacedResources()
    G-->>R: coreResources (DB, kruize, UI)
    loop each core resource
        R->>K8s: apply core resource
        K8s-->>R: core resource created/updated
    end

    R->>G: OptimizerNamespacedResources() or OptimizerKubernetesNamespacedResources()
    G-->>R: optimizerResources (kruize-optimizer Deployment, Service)

    loop each optimizer resource
        R->>K8s: apply optimizer resource
        K8s-->>R: optimizer resource created/updated
    end

    Note over OPTD,INIT: Pod start for kruize-optimizer
    OPTD->>INIT: start init container wait-for-kruize
    loop until kruize health ready
        INIT->>KR: HTTP GET /health or /
        KR-->>INIT: 503 or connection error
    end
    INIT->>KR: HTTP GET /health
    KR-->>INIT: 200 OK
    INIT-->>OPTD: init complete, start optimizer container
Loading

Sequence diagram for optimizer environment configuration resolution

sequenceDiagram
    participant R as KruizeReconciler
    participant G as KruizeResourceGenerator
    participant Spec as KruizeSpec
    participant OCfg as OptimizerConfig
    participant D as kruize-optimizer Pod

    R->>G: NewKruizeResourceGenerator(..., kruizeSpec, ...)
    G-->>R: generator with KruizeSpec reference

    R->>G: kruizeOptimizerDeployment()
    activate G
    G->>G: getOptimizerEnvVars()
    alt Optimizer config provided
        G->>Spec: read Optimizer
        Spec-->>G: OptimizerConfig pointer
        G->>OCfg: read fields (KruizeURL, intervals, webhookURL, labels, profiles)
        OCfg-->>G: values or empty strings
        G->>G: override defaults where non-empty
    else No Optimizer config
        G->>G: use all default values
    end
    G-->>R: Deployment with env vars
    deactivate G

    R->>D: create Pod with resolved env
    D-->>R: running with configured optimizer behavior
Loading

Class diagram for updated KruizeSpec and OptimizerConfig models

classDiagram
    class KruizeSpec {
        string Autotune_image
        string Autotune_ui_image
        string Optimizer_image
        string Namespace
        string Cluster_type
        KruizeAppConfig Kruize
        OptimizerConfig Optimizer
    }

    class KruizeAppConfig {
        string Autotune_image
        string Autotune_ui_image
        string Namespace
        KubernetesResourceRequirements Resources
    }

    class OptimizerConfig {
        KubernetesResourceRequirements Resources
        string KruizeURL
        string StateRefreshInterval
        string BulkSchedulerInterval
        string BulkSchedulerStartupDelay
        string BulkMeasurementDuration
        string WebhookURL
        string TargetLabelLimit
        string TargetLabels
        string DefaultDatasource
        string DefaultMetadataProfile
        string DefaultMetricProfile
    }

    class KubernetesResourceRequirements {
        string Requests_cpu
        string Requests_memory
        string Limits_cpu
        string Limits_memory
    }

    KruizeSpec --> KruizeAppConfig : has optional
    KruizeSpec --> OptimizerConfig : has optional
    KruizeAppConfig --> KubernetesResourceRequirements : uses optional
    OptimizerConfig --> KubernetesResourceRequirements : uses optional
Loading

Class diagram for KruizeResourceGenerator and optimizer resource generation

classDiagram
    class KruizeResourceGenerator {
        string Namespace
        string Autotune_image
        string Autotune_ui_image
        string Optimizer_image
        string ClusterType
        KruizeSpec KruizeSpec
        context.Context Ctx
        +NewKruizeResourceGenerator(namespace string, autotuneImage string, autotuneUIImage string, optimizerImage string, clusterType string, kruizeSpec *KruizeSpec, ctx context.Context) KruizeResourceGenerator
        +CoreNamespacedResources() []client.Object
        +OptimizerNamespacedResources() []client.Object
        +CoreKubernetesNamespacedResources() []client.Object
        +OptimizerKubernetesNamespacedResources() []client.Object
        +getOptimizerEnvVars() []corev1.EnvVar
        +kruizeOptimizerDeployment() *appsv1.Deployment
        +kruizeOptimizerService() *corev1.Service
    }

    class KruizeReconciler {
        client.Client Client
        +deployKruizeComponents(ctx context.Context, namespace string, kruize *Kruize) error
        +waitForKruizePods(ctx context.Context, namespace string, timeout time.Duration) error
        +checkKruizePodsStatus(ctx context.Context, namespace string) (int, int, map[string]string, error)
    }

    KruizeReconciler --> KruizeResourceGenerator : creates and uses
    KruizeResourceGenerator --> KruizeSpec : reads configuration
    KruizeResourceGenerator --> OptimizerConfig : reads optimizer config
    KruizeResourceGenerator --> appsv1.Deployment : generates
    KruizeResourceGenerator --> corev1.Service : generates
    KruizeResourceGenerator --> corev1.EnvVar : populates optimizer env
Loading

File-Level Changes

Change Details Files
Introduce configurable Kruize Optimizer image and config in the API/CRD and wire them into the resource generator and reconciler.
  • Extend KruizeSpec with Optimizer_image and OptimizerConfig fields with detailed configuration knobs and update CRD schema to match, including optimizer image field.
  • Update deployKruize/deployKruizeComponents to pass optimizer image into the KruizeResourceGenerator and to log it.
  • Add getOptimizerEnvVars helper that builds optimizer env var set from OptimizerConfig with sensible defaults.
api/v1alpha1/kruize_types.go
config/crd/bases/kruize.io_kruizes.yaml
internal/controller/kruize_controller.go
internal/utils/kruize_generator.go
Add optimizer-specific Kubernetes resources and split namespaced resources into core vs optimizer for both OpenShift and Kubernetes paths.
  • Extend KruizeResourceGenerator to hold Optimizer_image resolved via a new DEFAULT_OPTIMIZER_IMAGE env var and corresponding constants helper.
  • Split NamespacedResources/KubernetesNamespacedResources into CoreNamespacedResources/CoreKubernetesNamespacedResources and OptimizerNamespacedResources/OptimizerKubernetesNamespacedResources.
  • Implement kruizeOptimizerDeployment with an init container that waits on Kruize service readiness and kruizeOptimizerService as a ClusterIP service.
  • Change controller deployment flow to reconcile core namespaced resources and optimizer resources in two phases while still using the optimizer pod init container for readiness ordering.
internal/utils/kruize_generator.go
internal/constants/kruize_images.go
internal/controller/kruize_controller.go
Update readiness logic and tests to account for the optimizer component and refactor tests to use the new core/optimizer split APIs.
  • Adjust waitForKruizePods to require four pods (kruize, kruize-ui-nginx, kruize-db, kruize-optimizer).
  • Update unit tests in kruize_controller_test.go to use the new NewKruizeResourceGenerator signature, Core*/Optimizer*NamespacedResources methods, and to verify custom optimizer image wiring.
  • Extend e2e tests to assert kruize-optimizer deployment becomes ready.
  • Update sample CR to include optimizer_image and an example optimizer config block.
internal/controller/kruize_controller.go
internal/controller/kruize_controller_test.go
test/e2e/e2e_test.go
config/samples/v1alpha1_kruize.yaml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@shreyabiradar07
Copy link
Copy Markdown
Contributor

@shekhar316 is PR 83 targeted for 0.0.5 or next release?

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

Labels

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

3 participants