Skip to content

Action plan render once - #2067

Open
erikasb wants to merge 1 commit into
Altinity:0.28.0from
erikasb:action-plan-render-once
Open

Action plan render once#2067
erikasb wants to merge 1 commit into
Altinity:0.28.0from
erikasb:action-plan-render-once

Conversation

@erikasb

@erikasb erikasb commented Aug 18, 2026

Copy link
Copy Markdown

Fixes #2066.

ActionPlan.String() is called on every status update attempt while building the status storage ConfigMap data. Each call re-renders the diff from scratch: reflection-dumps every diffed object (the full value is rendered, then truncated to 256 chars) and iterates the diff maps in random order, so the same plan produces different bytes on every call. During a scale-up of a large CHI this runs thousands of times per reconcile and dominates operator CPU (details and measurements in the issue).

This PR renders the plan once, eagerly in MakeActionPlan, and makes String() return that snapshot. The plan is immutable after construction, and every reconcile already renders it at least once for logging, so this adds no new work — it just stops repeating it. Before the plan was moved into the status path, it was rendered once per reconcile (LogActionPlan); this restores that frequency while keeping the storage feature.

Behavior notes:

  • String() now returns the same bytes on every call. The stored status-actionPlan text becomes a construction-time snapshot. It is write-only (never parsed back), so nothing consumes the difference.
  • Zero-value or JSON-unmarshaled plans (only unexported fields, so they unmarshal empty) render as "", same as before.

Measured on a 156-host CHI, scaling 2 clusters 20 → 39 shards each: 0.28.0 + this change completes in 18–21 min where 0.27.1 took ~1h41m with operator CPU pinned; status update conflict retries drop ~10x.

Since the action plan was added to the CR status write path, every status
update re-renders ActionPlan.String() while building the aux status ConfigMap
payload: each call reflection-dumps every diffed object (the full value is
rendered, then truncated to 256 chars) and iterates the diff maps in
randomized order, so the very same plan produces different bytes on every
call. During a horizontal expansion, status updates are issued several times
per host - thousands of renderings of a diff that lists every added shard,
where 0.25.x rendered the plan exactly once per reconcile (LogActionPlan).
This is a major CPU cost on the reconcile hot path (operator CPU observed
pinned for the duration of large expansions).

Render the plan exactly once, eagerly in MakeActionPlan, and make String()
return that stable snapshot. This restores the once-per-reconcile rendering
frequency that existed before the plan moved into the storage path, while
keeping the storage feature. The plan is immutable after construction and
every reconcile already renders it at least once for logs, so eager rendering
adds no new work. Repeated String() calls become byte-stable, which also
allows content comparison on the stored plan downstream. Zero-value or
JSON-unmarshaled plans render as "" exactly as before.

Signed-off-by: Erikas Balynas <ebalynas@paloaltonetworks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

planned for review This feature is planned for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants