Skip to content

feat: using indexes to optimize Pod-VariantAutoscaling mapping#603

Merged
WheelyMcBones merged 17 commits intollm-d:mainfrom
WheelyMcBones:pod-va-indexer
Feb 6, 2026
Merged

feat: using indexes to optimize Pod-VariantAutoscaling mapping#603
WheelyMcBones merged 17 commits intollm-d:mainfrom
WheelyMcBones:pod-va-indexer

Conversation

@WheelyMcBones
Copy link
Copy Markdown
Collaborator

@WheelyMcBones WheelyMcBones commented Jan 18, 2026

This PR introduces a module that registers a custom field index to enable for faster look-ups for VariantAutoscalings.
Note: to avoid breaking changes, in case of missing spec.scaleTargetRef.apiVersion, a default to apps/v1 is added for Deployments or unsupported Kinds.

Closes #546.

@WheelyMcBones WheelyMcBones self-assigned this Jan 18, 2026
Copilot AI review requested due to automatic review settings January 18, 2026 00:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a module that registers custom field indexes to enable faster lookups for VariantAutoscalings and Pods, addressing issue #546. The optimization moves away from label-based list operations to owner reference traversal combined with indexed lookups.

Changes:

  • Added new indexers.go module with three custom field indexes (Pod-to-owner, ReplicaSet-to-Deployment, and VA-to-Deployment)
  • Updated handleDeploymentEvent in variantautoscaling_controller.go to use indexed VA lookup
  • Refactored pod_va_mapper.go to use owner reference traversal instead of label selector matching
  • Enhanced test coverage in pod_va_mapper_test.go with proper ReplicaSet owner references
  • Integrated index setup in main.go initialization

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
internal/controller/indexers.go New module defining three custom field indexes and helper functions for efficient lookup of Pods, ReplicaSets, VAs, and their relationships
internal/controller/variantautoscaling_controller.go Updated handleDeploymentEvent to use indexed FindVAsForDeployment lookup instead of listing all VAs
internal/collector/source/pod_va_mapper.go Refactored findDeploymentForPod to traverse owner references (Pod→ReplicaSet→Deployment) instead of using label selectors
internal/collector/source/pod_va_mapper_test.go Enhanced tests with helper functions for creating Pods and ReplicaSets with proper owner references; added tests for caching behavior and edge cases
cmd/main.go Added SetupIndexes call during initialization to register custom field indexes with the manager

Comment thread internal/controller/indexers.go Outdated

This comment was marked as outdated.

Copilot AI review requested due to automatic review settings January 18, 2026 11:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.

Comment thread internal/controller/variantautoscaling_controller.go Outdated
Comment thread internal/controller/indexers_test.go Outdated
Comment thread internal/collector/source/pod_va_mapper_test.go Outdated
Comment thread internal/collector/source/pod_va_mapper_test.go Outdated
Comment thread internal/controller/indexers.go Outdated
Comment thread internal/controller/indexers.go Outdated
Copilot AI review requested due to automatic review settings January 18, 2026 11:44
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

internal/collector/source/pod_va_mapper.go:99

  • The findVAForDeployment function matches VAs based only on ScaleTargetRef.Name and Namespace, without checking ScaleTargetRef.Kind. This means if a VariantAutoscaling targets a non-Deployment resource (e.g., StatefulSet) with the same name as a Deployment in the same namespace, it would be incorrectly matched. Consider adding a check for ScaleTargetRef.Kind == "Deployment" to ensure only VAs targeting Deployments are matched.
// findVAForDeployment finds the VariantAutoscaling object that targets a Deployment.
func (m *PodVAMapper) findVAForDeployment(
	deploymentName string,
	namespace string,
	variantAutoscalings map[string]*llmdv1alpha1.VariantAutoscaling,
) string {
	for vaName, va := range variantAutoscalings {
		if va == nil {
			continue
		}
		if va.Spec.ScaleTargetRef.Name == deploymentName &&
			va.Namespace == namespace {
			return vaName
		}
	}
	return ""

Comment thread internal/collector/source/pod_va_mapper_test.go Outdated
Comment thread internal/controller/indexers_test.go Outdated
Comment thread internal/controller/indexers_test.go Outdated
Copilot AI review requested due to automatic review settings January 18, 2026 12:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Comment thread internal/controller/indexers.go Outdated
Comment thread internal/controller/indexers_test.go Outdated
Copilot AI review requested due to automatic review settings January 18, 2026 23:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Comment thread internal/controller/indexers_test.go Outdated
@WheelyMcBones
Copy link
Copy Markdown
Collaborator Author

/ok-to-test

@github-actions
Copy link
Copy Markdown
Contributor

🚀 E2E tests triggered by /ok-to-test

View the OpenShift E2E workflow run

@WheelyMcBones WheelyMcBones marked this pull request as ready for review January 18, 2026 23:52
Copilot AI review requested due to automatic review settings January 18, 2026 23:52
@WheelyMcBones WheelyMcBones added ready-for-review Signal that changes are ready for review e2e passing Unit-tests passing and removed WIP labels Jan 18, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

@github-actions
Copy link
Copy Markdown
Contributor

🚀 E2E tests triggered by /ok-to-test

View the OpenShift E2E workflow run

@asm582
Copy link
Copy Markdown
Collaborator

asm582 commented Feb 2, 2026

@WheelyMcBones OpenShift E2E's fail ?

Copilot AI review requested due to automatic review settings February 3, 2026 16:21
@WheelyMcBones
Copy link
Copy Markdown
Collaborator Author

/ok-to-test

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 3, 2026

🚀 E2E tests triggered by /ok-to-test

View the OpenShift E2E workflow run

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

// Note: add other Kinds when support to other scaleTargetRefs is added
// By default, assume 'apps/v1' for unsupported Kinds
default:
logger := ctrl.LoggerFrom(context.TODO())
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

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

Using context.TODO() here to get a logger is problematic because this indexer function is called by the controller-runtime framework without a proper context attached. The logger retrieved from context.TODO() won't have request-scoped fields and may not be properly initialized. Consider using the global logger directly or removing the logging entirely since this is a fast-path index function that should avoid side effects.

Suggested change
logger := ctrl.LoggerFrom(context.TODO())
logger := ctrl.Log

Copilot uses AI. Check for mistakes.
}

// Verify the Deployment is in our map of tracked Deployments
deploymentKey := namespace + "/" + rsOwner.Name
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

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

The key format namespace + "/" + rsOwner.Name is hardcoded here, but there's a utility function utils.GetDeploymentKey(namespace, name) that should be used for consistency across the codebase. This ensures all deployment keys follow the same format and makes future changes easier to maintain.

Copilot uses AI. Check for mistakes.
Comment thread internal/utils/variant.go Outdated
Copy link
Copy Markdown
Collaborator

@asm582 asm582 left a comment

Choose a reason for hiding this comment

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

/lgtm

@WheelyMcBones
Copy link
Copy Markdown
Collaborator Author

/ok-to-test

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 6, 2026

🚀 E2E tests triggered by /ok-to-test

View the OpenShift E2E workflow run

@WheelyMcBones WheelyMcBones merged commit bcbf370 into llm-d:main Feb 6, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e2e passing ready-for-review Signal that changes are ready for review Unit-tests passing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimize computing mapping between pod and VA

5 participants