You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SSABasedGenericKubernetesResourceMatcher: HorizontalPodAutoscaler target quantities never match (1000 vs 1k) #3681
A dependent HorizontalPodAutoscaler (autoscaling/v2) declares an external metric with target.averageValue: "1000". The API server stores this value in canonical form, as "1k". The default SSABasedGenericKubernetesResourceMatcher compares the two strings, so matches returns false on every reconcile and the operator re-applies the HPA each time.
PodTemplateSpecSanitizer already solves this class of problem for StatefulSet, Deployment, ReplicaSet and DaemonSet pod templates. sanitizeState has no branch for HorizontalPodAutoscaler, so HPA quantities are never normalised. This is the same root cause as #2509, for a different kind.
What did you expect to see?
A numerically equal stored quantity matches the desired quantity, as it does for container resources in pod templates.
What did you see instead?
The matcher reports a mismatch on every reconcile. The operator log shows the same diff each time: replace /spec/metrics/0/external/target/averageValue with value 1000.
I checked this against a real API server (k3s v1.31.4) with JOSDK 5.1.4 and fabric8 7.3.1. The desired object was applied with server-side apply. The stored object was then read back and compared with SSABasedGenericKubernetesResourceMatcher.getInstance():
Desired averageValue / value
Stored by the API server
Matcher result
1000
1k
no match
0.5
500m
no match
2000m
2
no match
1500
1500
match
sanitizeState on main still contains branches only for StatefulSet, Deployment, ReplicaSet and DaemonSet, so this appears to be unchanged in newer releases. I did not run 5.6.x.
Workaround
Subclass the matcher and override sanitizeState. When the stored and desired quantities are numerically equal (Quantity.equals), copy the desired string into actualMap. Register the subclass with KubernetesDependentResourceConfigBuilder.withSSAMatcher. This is the approach PodTemplateSpecSanitizer.sanitizeQuantities uses. With it, the HPA no longer re-applies, and a real change to the target is still detected and applied once.
Proposal
Add an HorizontalPodAutoscaler branch to sanitizeState. It would normalise value and averageValue in spec.metrics[*].{external,object,pods,resource,containerResource}.target. Would a PR for this be welcome?
Activity
fix: match HorizontalPodAutoscaler target quantities in SSA matcher
fix: match HorizontalPodAutoscaler target quantities in SSA matcher
fix: match HorizontalPodAutoscaler target quantities in SSA matcher
fix: match HorizontalPodAutoscaler target quantities in SSA matcher
fix: match HorizontalPodAutoscaler target quantities in SSA matcher (o…