Commit graph

475 commits

Author SHA1 Message Date
Omer Aplatony
93a2605ee3 removed runTest from replica calculator test
Signed-off-by: Omer Aplatony <omerap12@gmail.com>
2026-05-20 18:33:40 +00:00
Kubernetes Prow Robot
ad8c9819a2
Merge pull request #139061 from omerap12/refactor-replica-calc-test
HPA: refactor replica_calculator_test: consolidate metric case tests
2026-05-20 20:31:54 +05:30
Mike Fedosin
86f94fda0c
Fix error formatting and use proper error wrapping in HPA controller (#139029)
* Fix format-string argument order in object metric error messages

The error format strings in GetObjectMetricReplicas and
GetObjectPerPodMetricReplicas had the arguments in the wrong order,
causing objectRef.Kind to be printed where the error should appear
and vice versa.

Signed-off-by: Mikhail Fedosin <mfedosin@redhat.com>

* Use %w for error wrapping in fmt.Errorf calls in podautoscaler

Replace %v with %w for error arguments in fmt.Errorf throughout the
HPA controller, replica calculator, and metrics client. This enables
proper error wrapping so that callers can use errors.Is and errors.As
to inspect underlying errors.

Signed-off-by: Mikhail Fedosin <mfedosin@redhat.com>

---------

Signed-off-by: Mikhail Fedosin <mfedosin@redhat.com>
2026-05-18 20:47:54 +05:30
Kubernetes Prow Robot
a4aee62c39
Merge pull request #139025 from omerap12/hpaConsistency
Add the ability for the hpa controller to read its own writes
2026-05-18 19:56:02 +05:30
Omer Aplatony
09b3daa521 refactor replica_calculator_test: consolidate metric case tests
Signed-off-by: Omer Aplatony <omerap12@gmail.com>
2026-05-14 15:24:56 +00:00
Kubernetes Prow Robot
f39965b62c
Merge pull request #138858 from omerap12/refactor-TestReplicasCalcResourceScale
HPA: refactor replica_calculator_test GetResourceReplicas
2026-05-14 14:36:28 +05:30
Omer Aplatony
9b2b31c3c5 Add the ability for the hpa controller to read its own writes
Signed-off-by: Omer Aplatony <omerap12@gmail.com>
2026-05-14 08:34:39 +00:00
Omer Aplatony
41d10bc9e0 refactor replica_calculator_test GetResourceReplicas
Signed-off-by: Omer Aplatony <omerap12@gmail.com>
2026-05-14 08:11:10 +00:00
Joe Betz
119a1460c1
Generate deepcopy 2026-05-11 12:27:56 -04:00
Mikhail Fedosin
10742ec428 hpa: eliminate reconciliation delay on HPA creation and spec changes
Previously, creating or updating an HPA always went through
AddRateLimited, delaying reconciliation by the full resync period
(default 15s). This causes a noticeable lag between applying an HPA
and seeing it take effect, and grows worse with longer resync
intervals (e.g. 60s).

Switch enqueueHPA from queue.AddRateLimited to queue.Add so that
newly created HPAs are processed immediately. In updateHPA, compare
the Generation field (gated behind the HPAGeneration feature) to
distinguish spec changes from status-only updates: spec changes
trigger immediate reconciliation via queue.Add, while status-only
changes remain rate-limited to avoid the hot-loop from
kubernetes#42715 where the controller's own status writes would
re-trigger continuous reconciliation. When HPAGeneration is disabled,
all updates fall back to rate-limited enqueue (the original behavior).

Type-assertion fallbacks in updateHPA (e.g. DeletedFinalStateUnknown)
now also use rate-limited enqueue to prevent any theoretical hot-loop.

The periodic resync cadence is unaffected: processNextWorkItem
continues to call AddRateLimited after every reconciliation cycle.
2026-04-27 10:15:58 +02:00
Kubernetes Prow Robot
301f9afd23
Merge pull request #138228 from adrianmoisey/hpa-generation
Handle HPA generation fields
2026-04-24 21:04:46 +05:30
Adrian Moisey
2c4064f31c
Handle HPA generation fields 2026-04-24 14:41:49 +02:00
Omer Aplatony
ae0a48e142 Remove duplicated ut
Signed-off-by: Omer Aplatony <omerap12@gmail.com>
2026-04-23 22:07:42 +00:00
Kubernetes Prow Robot
ad1c87b481
Merge pull request #138397 from omerap12/cleanup-hpa
HPA: Clean up duplicate unit tests
2026-04-23 07:21:19 +05:30
Omer Aplatony
62ce934202 removed TestScaleDownWithScalingRules (duplicate of TestScaleDown )
Signed-off-by: Omer Aplatony <omerap12@gmail.com>
2026-04-15 13:20:54 +00:00
Omer Aplatony
a6dce1229b removed unused testThis var and its unit test case
Signed-off-by: Omer Aplatony <omerap12@gmail.com>
2026-04-15 13:09:46 +00:00
Omer Aplatony
8a887a11db removed TestScaleUpHotCpuNoScaleWouldScaleDown (identical to TestScaleUpCMUnreadyandCpuHot)
Signed-off-by: Omer Aplatony <omerap12@gmail.com>
2026-04-15 13:08:14 +00:00
Omer Aplatony
f1f94dd037 removed duplicated unit test case ( same as 'scaleDown with spec MinReplicas limitation with large pod policy') 2026-04-15 12:51:58 +00:00
Omer Aplatony
0455d9c0c3 removed TestScaleUpBothMetricsEmpty since we have TestConditionInvalidSourceType
Signed-off-by: Omer Aplatony <omerap12@gmail.com>
2026-04-15 12:19:53 +00:00
Omer Aplatony
cfe5b54d0a
Adds polling for HPA reconciliation_duration unit test (#138059)
* Adds polling for HPA reconciliation_duration unit test

Signed-off-by: Omer Aplatony <omerap12@gmail.com>

* using struct name

Signed-off-by: Omer Aplatony <omerap12@gmail.com>

---------

Signed-off-by: Omer Aplatony <omerap12@gmail.com>
2026-04-07 21:45:33 +05:30
Johannes Würbach
6bebe8d3a2
KEP-2021: HPA condition based scaling to zero 2026-03-17 09:18:18 +01:00
Kubernetes Prow Robot
3d6026d2fd
Merge pull request #136178 from omerap12/promote-hpa-metrics
promote HPA metrics to beta
2026-03-10 01:19:13 +05:30
Omer Aplatony
3799fc9942
Add unit tests for HPA metrics (#136670)
* Add unit tests for HPA metrics

Signed-off-by: Omer Aplatony <omerap12@gmail.com>

* removed mock monitor

Signed-off-by: Omer Aplatony <omerap12@gmail.com>

* fmt

Signed-off-by: Omer Aplatony <omerap12@gmail.com>

* spelling

Signed-off-by: Omer Aplatony <omerap12@gmail.com>

* lint

Signed-off-by: Omer Aplatony <omerap12@gmail.com>

* lint

Signed-off-by: Omer Aplatony <omerap12@gmail.com>

---------

Signed-off-by: Omer Aplatony <omerap12@gmail.com>
2026-03-05 19:10:26 +05:30
Omer Aplatony
064a8ec1f8 promote HPA metrics to beta
Signed-off-by: Omer Aplatony <omerap12@gmail.com>
2026-01-12 17:03:39 +00:00
Kubernetes Prow Robot
df9a0bda18
Merge pull request #133797 from tico88612/cleanup/new-fake-with-options
Replace apimachinery/pkg/watch.NewFake with NewFakeWithOptions in pkg/controller
2026-01-08 03:01:38 +05:30
Kubernetes Prow Robot
d6aa2db57e
Merge pull request #135027 from omerap12/remove-reactor-hpa
Remove unused delete reactor
2025-11-04 01:30:10 -08:00
Omer Aplatony
264eab46db Remove unused delete reactor
Signed-off-by: Omer Aplatony <omerap12@gmail.com>
2025-11-01 06:13:40 +00:00
Ondra Kupka
5f423d7ba8 controller/podautoscaler: Improve goroutine mgmt
Make sure all threads are terminated when Run returns.
2025-10-29 19:04:38 +01:00
Omer Aplatony
4f8757b4c0 Remove flaky HPA deletion assertion in TestMultipleHPAs
Signed-off-by: Omer Aplatony <omerap12@gmail.com>
2025-10-10 12:00:35 +00:00
Adrian Moisey
ae25979790
Use a dedicated delete channel in HPA test
This is an attempt to fix a flake
2025-10-02 21:22:10 +02:00
Omer Aplatony
7af3377900 Add desired_replicas histogram metric to HPA controller
Signed-off-by: Omer Aplatony <omerap12@gmail.com>
2025-09-27 09:30:03 +00:00
Omer Aplatony
a8a21aaf85
Add hpa object count metric (#134140)
* Add hpa object count metrics

Signed-off-by: Omer Aplatony <omerap12@gmail.com>

* change name to num_horizontal_pod_autoscalers

Signed-off-by: Omer Aplatony <omerap12@gmail.com>

* remove log line

Signed-off-by: Omer Aplatony <omerap12@gmail.com>

---------

Signed-off-by: Omer Aplatony <omerap12@gmail.com>
2025-09-22 06:10:19 -07:00
Kubernetes Prow Robot
69e92c6827
Merge pull request #134022 from aditigupta96/cleanup-waitfornamedcachesync
refactor(controller): Use context-aware WaitForNamedCacheSync in resourcequota and HPA tests
2025-09-16 17:18:16 -07:00
Aditi Gupta
af231d2153 Replace WaitForNamedCacheSync with WaitForNamedCacheSyncWithContext in pkg/controller/ 2025-09-16 14:51:34 -07:00
Aditi Gupta
1ce12710ec refactor(controller): Use context-aware WaitForNamedCacheSync in resourcequota and HPA tests 2025-09-12 12:37:54 -07:00
ChengHao Yang
ef96d9cbd2
Replace NewFake with NewFakeWithOptions in pkg/controller
CreateTestClient add the argument logger for support contextual logging

Signed-off-by: ChengHao Yang <17496418+tico88612@users.noreply.github.com>
2025-09-11 08:39:49 +08:00
Omer Aplatony
fbd33bd6b3 hpa: prevent integer overflow in external metrics sum
Signed-off-by: Omer Aplatony <omerap12@gmail.com>
2025-09-04 08:36:53 +00:00
Kubernetes Prow Robot
1bcfd5cee7
Merge pull request #133741 from kincoy/hpa-cleanup-redundant-casts
cleanup: remove redundant type conversions in podautoscaler
2025-09-01 04:35:20 -07:00
Kubernetes Prow Robot
5c107f08e9
Merge pull request #133708 from ingvagabund/podautoscaler-dont-print-panic
fix(controller/podautoscaler): do not print panic when .status.lastScaleTime is not set
2025-09-01 04:35:13 -07:00
kincoy
12a784b46b cleanup: remove redundant type conversions in podautoscaler
Signed-off-by: kincoy <kincoyao@gmail.com>
2025-08-28 14:28:57 +08:00
Kubernetes Prow Robot
5742171781
Merge pull request #133415 from AadiDev005/optimize-calculate-pod-requests
HPA: optimize calculatePodRequests for specific container lookups
2025-08-27 17:18:34 -07:00
Kubernetes Prow Robot
1c778ab972
Merge pull request #132503 from LoganGoogle/remove-redundant-code
Remove redundant MilliValue call in GetRawMetric for podautoscaler
2025-08-27 14:53:58 -07:00
Omer Aplatony
b9a8dffa51
Fix replicaCount calculation exceeding max int32 (#126979)
* Fix replicaCount calculation exceeding max int32

Signed-off-by: Omer Aplatony <omerap12@gmail.com>

* Add test for scaling up with overflow

Signed-off-by: Omer Aplatony <omerap12@gmail.com>

---------

Signed-off-by: Omer Aplatony <omerap12@gmail.com>
2025-08-27 14:53:15 -07:00
Jan Chaloupka
83da6f1a87 fix(controller/podautoscaler): do not print panic when .status.lastScaleTime is not set 2025-08-26 14:18:54 +02:00
aditya
bb6a0ea6b2 HPA: optimize calculatePodRequests for specific container lookups
- Add early exit when specific container is found in calculatePodRequestsFromContainers
- Add error handling for non-existent containers following existing patterns
- Maintain all existing functionality for pod-level resources and feature gates
- Include comprehensive function documentation

The optimization eliminates unnecessary container iterations when HPA targets
specific containers, providing significant performance improvements for pods
with many containers while preserving full backward compatibility
2025-08-20 19:13:00 +05:30
Luiz Oliveira
7fbf63a23f
HPA support for pod-level resource specifications (#132430)
* HPA support for pod-level resource specifications

* Add e2e tests for HPA support for pod-level resource specifications
2025-07-29 09:02:26 -07:00
googs1025
b50d508176 bugfix(hpa): introduce buildQuantity helper for consistent resource quantity creation
Signed-off-by: googs1025 <googs1025@gmail.com>
2025-06-25 08:23:53 +08:00
Logan Zhai
a352bf8815 Remove redundant MilliValue call in GetRawMetric for podautoscaler,
which has no functional impact.
2025-06-24 14:06:21 +00:00
aumpatel
db2555628c Fix: HPA suppresses FailedRescale event on successful conflict retry
This change modifies the HPA controller to use retry.RetryOnConflict when updating a scale subresource. This prevents the controller from emitting a FailedRescale event on transient API conflicts if a subsequent retry succeeds. If the retry is successful, a SuccessfulRescale event is emitted. If all retries are exhausted and the conflict persists, the original FailedRescale event is emitted. This reduces event noise caused by race conditions where the scale subresource is updated by another process.
2025-06-12 07:35:07 -04:00
Kubernetes Prow Robot
fa10ea63a6
Merge pull request #127050 from omerap12/podautoscaler-ExternalPerpodMetricReplicas-intmax
HPA: Fix int overflow in GetExternalPerPodMetricReplicas
2025-05-09 13:37:14 -07:00