Skip to content

Add e2e test for external metrics#136799

Merged
k8s-ci-robot merged 1 commit intokubernetes:masterfrom
omerap12:external-metrics-e2e
Feb 16, 2026
Merged

Add e2e test for external metrics#136799
k8s-ci-robot merged 1 commit intokubernetes:masterfrom
omerap12:external-metrics-e2e

Conversation

@omerap12
Copy link
Member

@omerap12 omerap12 commented Feb 6, 2026

What type of PR is this?

/kind feature

What this PR does / why we need it:

Following the KEPs:
kubernetes/enhancements#5680 and kubernetes/enhancements#2022 we need a testing framework for HPA based on external metrics.
This PR introduces the necessary helper functions to enable those tests (based on #136721) and adds an initial basic test, since none currently exist.

Which issue(s) this PR is related to:

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

NONE

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. release-note-none Denotes a PR that doesn't merit a release note. kind/feature Categorizes issue or PR as related to a new feature. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. area/e2e-test-framework Issues or PRs related to refactoring the kubernetes e2e test framework area/test sig/autoscaling Categorizes an issue or PR as relevant to SIG Autoscaling. sig/testing Categorizes an issue or PR as relevant to SIG Testing. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Feb 6, 2026
@omerap12
Copy link
Member Author

omerap12 commented Feb 6, 2026

@johanneswuerbach, I think this provides the necessary pieces you can use to add end-to-end tests.
/cc @adrianmoisey
/sig autoscaling

ginkgo.It("should scale up and down based on external metric value", func(ctx context.Context) {
ginkgo.By("Creating the resource consumer deployment")
initPods := 1
rc = e2eautoscaling.NewDynamicResourceConsumer(ctx,
Copy link
Member

Choose a reason for hiding this comment

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

Unrelated to your change, but this seems to end up being using apiVersion: apps/v1beta2, we should fix that at some stage

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes - we can handle this in a follow-up PR. It will likely require updates across all tests.

Signed-off-by: Omer Aplatony <omerap12@gmail.com>
@omerap12 omerap12 force-pushed the external-metrics-e2e branch from bff232e to d712e0e Compare February 8, 2026 08:58
@adrianmoisey
Copy link
Member

This is awesome! Thanks for doing it!
I'm very surprised that we didn't have e2e tests for the HPA's external metrics

@omerap12
Copy link
Member Author

omerap12 commented Feb 8, 2026

/retest

1 similar comment
@omerap12
Copy link
Member Author

omerap12 commented Feb 8, 2026

/retest

@omerap12
Copy link
Member Author

omerap12 commented Feb 8, 2026

I'm very surprised that we didn't have e2e tests for the HPA's external metrics

Totally, when this merges I intend to open some good-first-issues to improve converge.

@adrianmoisey
Copy link
Member

I'm happy with this, it's adding a e2e test for a feature that's never been tested, which is amazing.
We also need this for 2 upcoming KEPs, so it's possible that we tweak and change it if needed for those.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 10, 2026
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

DetailsGit tree hash: 129265fafd5a4b704c7bbdfbd8ae5f905ad5020e

Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

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

/approve


func (emc *ExternalMetricsController) doRequestWithPortForward(ctx context.Context, action, metricName string, params url.Values) error {
// Find the pod
pods, err := emc.clientSet.CoreV1().Pods(emc.namespace).List(ctx, metav1.ListOptions{
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: you could replace this entire port-forward logic with directly invoking PortForwardOptions.RunPortForwardContext. We've written those commands such that they should be easily embedable anywhere where needed. Also, we're slowly switching again from SPDY, which you're using below, towards WebSockets. So using port-forward's code directly will give you the benefit that you don't have to think about it 😉

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that sounds good. will open an issue to address it ( I don't want to delay this PR since we need for other work ).

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: omerap12, soltysh

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 16, 2026
@soltysh
Copy link
Contributor

soltysh commented Feb 16, 2026

/triage accepted
/priority important-longterm

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Feb 16, 2026
@omerap12
Copy link
Member Author

/retest

1 similar comment
@omerap12
Copy link
Member Author

/retest

@k8s-ci-robot k8s-ci-robot merged commit c99adce into kubernetes:master Feb 16, 2026
14 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.36 milestone Feb 16, 2026
@omerap12 omerap12 deleted the external-metrics-e2e branch February 16, 2026 14:15
ibm-adarsh added a commit to ibm-adarsh/kubernetes that referenced this pull request Feb 19, 2026
This commit adds three new test cases to expand the HPA External Metrics
test coverage:

1. Multiple Metrics: Verifies that a single HPA can correctly handle two or
   more external metrics simultaneously, ensuring that the highest desired
   replica count from all metrics is used.

2. Stabilization Window: Ensures that the HPA does not scale too aggressively
   when metric values fluctuate rapidly by respecting the configured
   stabilization window.

3. Scaling Limits: Validates that the configured scaling limits
   (behavior.scaleUp and behavior.scaleDown) are enforced correctly,
   including policies for maximum pods per period.

Additionally, a new helper function CreateMultiMetricHorizontalPodAutoscalerWithBehavior
is added to the framework to support creating HPAs with multiple metrics and
custom behavior policies.

Fixes: kubernetes#137132
Related to: kubernetes#136799"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. area/e2e-test-framework Issues or PRs related to refactoring the kubernetes e2e test framework area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. release-note-none Denotes a PR that doesn't merit a release note. sig/autoscaling Categorizes an issue or PR as relevant to SIG Autoscaling. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants