Skip to content

Find the latest GitHub status per context - #1434

Open
schdief wants to merge 1 commit into
fluxcd:mainfrom
schdief:github-status-per-context
Open

schdief wants to merge 1 commit into
fluxcd:mainfrom
schdief:github-status-per-context

Conversation

@schdief

@schdief schdief commented Nov 16, 2026

Copy link
Copy Markdown

GitHub.Post skips a status when the context's latest status has the same state and description.
It looks for that latest status among the commit's 50 newest statuses
(github.go#L83-L90).
That list is the commit's status history, newest first, not one entry per context. On a commit with
more than 50 contexts, the context's latest status is usually further back, the check finds nothing,
and the unchanged status is posted again.

This happens on every interval when many Kustomizations report to one repository:

  • kustomize-controller emits its commit status event on every successful reconciliation
    (kustomization_controller.go#L171-L187).
  • The event server's rate limit doesn't drop these events. Its key includes the message
    (eventkey.go#L35-L42),
    and the message contains the reconciliation's duration.

Observed with about 200 Kustomizations at interval: 5m reporting to one repository, so about 200
contexts on its head commit: the commit received about 23,000 statuses in 10.5 hours, nearly all of
them repeating the context's previous state and description. At one write per context every
5 minutes, a commit that stays at the head reaches GitHub's limit of 1000 statuses per SHA and
context (docs) after
about 3.5 days. From then on every post for that context fails with 422, including a later failure.

Post now reads the context's latest status from the combined status
(GET /repos/{owner}/{repo}/commits/{ref}/status),
which has one entry per context. It reads 100 per page and follows the pages until it finds the
context. Both endpoints need pull access.

  • Up to 100 contexts, an event still costs one read. With n contexts it costs up to ⌈n/100⌉ reads,
    and no write when nothing changed. In the setup above that is 2 reads per event instead of 1 read
    and 1 write.
  • duplicateGithubStatus and the error message are unchanged. A context without a status is posted,
    as before.

Tests: TestGitHubPostDuplicateBehindOtherContexts puts the own context on page 2 of the combined
status, behind 150 other contexts, with 50 statuses of other contexts on page 1 of the history. Its
unchanged case fails without this change. The test servers of TestGitHubWrappedErrors and
TestFactoryHTTPTransport now answer the combined status endpoint.

kustomize-controller's DisableCommitStatusEvent feature gate also avoids the writes, but it removes
the success status that CI may wait for.

The same approach was proposed in #1387, which its author closed before review. Related: #977. The
GitLab, Gitea and Azure DevOps notifiers also check a single page of statuses; they are not changed
here.

Post looked for a duplicate only among the 50 newest statuses of the
commit. On commits with more than 50 contexts, the latest status of a
context is often further back, so an unchanged status was posted again
on every reconciliation. Read the combined status instead, which holds
the latest status of each context, and page through it until the
context is found.

Signed-off-by: Steve Lohr <schdief.law@gmail.com>
Assisted-by: copilot/claude-opus-5.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant