* 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>
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.
* 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>
- 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
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.