Repository navigation
fix: Don't sync HPA spec from autoscaling policy for excluded Tortoises - #474
Draft
AdityaK011 wants to merge 1 commit into
Draft
AdityaK011 wants to merge 1 commit into
AdityaK011 wants to merge 1 commit into
Conversation
UpdateHPASpecFromTortoiseAutoscalingPolicy runs on every reconcile but only checked updateMode Off, so Tortoises in excluded namespaces, under global disable mode, or managed by ScaleOps still had their HPA metrics rewritten to match the autoscaling policy. The same path could also disable a user-provided HPA (metrics cleared, min=max=current replicas) or delete a Tortoise-created one. Gate it with IsChangeApplicationDisabled like the other HPA write paths. Also only mark the HPA as edited when a metric is actually added or removed. The keep branch set hpaEdited, so every reconcile issued an HPA Update and an HPAUpdated event even when nothing changed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does / why we need it:
Namespace exclusion, global disable mode and ScaleOps management are meant to stop Tortoise from changing a workload's HPA. One write path still ignores them.
UpdateHPASpecFromTortoiseAutoscalingPolicyruns on every reconcile and only checksupdateMode: Off. For an excluded Tortoise it still:spec.metricsto matchstatus.autoscalingPolicy, removing any container resource metric the policy doesn't mark Horizontal and adding missing ones at 70%disableHPAon a user-provided HPA when no policy is Horizontal, which clears the metrics and setsminReplicas = maxReplicas = current replicasWe saw the first case in one of our clusters. A team added
istio-proxymetrics to an HPA in an excluded namespace, and within about 80 seconds Tortoise removed them because its policy hasistio-proxyset toOff. The Tortoise's ownEffectiveModeOverriddencondition saidNamespaceExclusionat the time.This PR adds the same
IsChangeApplicationDisabledgate thatUpdateHPAFromTortoiseRecommendationand both webhooks already use.It also fixes
hpaEditedinsyncHPAMetricsWithTortoiseAutoscalingPolicy. It was set in the branch that keeps a metric, so any HPA with a kept container metric counted as edited. That meant every reconcile sent an HPAUpdateand emitted anHPAUpdatedevent ("because the autoscaling policy is changed in the tortoise") even when nothing had changed. Now it's only set when a metric is added or removed, including the existing removal ofResource-type metrics.Which issue(s) this PR fixes:
No issue filed. Happy to open one if you'd prefer to discuss it there first.
Special notes for your reviewer:
This reverses one part of #465, which removed this gate on purpose so the HPA spec would keep syncing in excluded namespaces for data collection and to avoid "metric not found" errors. cc @AVSBharadwaj, it'd be good to hear whether there's a case I'm missing.
My reasoning for adding it back:
calculateBestNewSizeandupdateHPATargetUtilizationRecommendationsnow skip instead of erroring), so an excluded Tortoise whose HPA lacks a metric no longer fails the reconcile. The whole suite passes with the gate, including the envtest controller tests.The trade-off is that an excluded Tortoise whose HPA is missing a Horizontal metric won't compute a target-utilization recommendation for that metric until it's un-excluded.
Tests:
TestService_UpdateHPASpecFromTortoiseAutoscalingPolicy_SkipAndNoopcovers excluded namespace (metrics kept, HPA not disabled), global disable mode, the no-op case (HPA not written when it already matches), and normal removal. The first four fail onmainand pass with this change. I rango testfor all packages except e2e against envtest 1.31.0.make testitself fails locally becausecontroller-genv0.16.1 doesn't build with Go 1.26, which doesn't affect this change.🤖 Generated with Claude Code