8000 fix(chi): recreate Services only for immutable type or headless changes (#2165 follow-up) by alex-zaitsev · Pull Request #2185 · Altinity/clickhouse-operator · GitHub
[go: up one dir, main page]

Skip to content

fix(chi): recreate Services only for immutable type or headless changes (#2165 follow-up) - #2185

Draft
alex-zaitsev wants to merge 5 commits into
0.28.0from
fix/2165-safe-service-recreation-20261203
Draft

alex-zaitsev wants to merge 5 commits into
0.28.0from
fix/2165-safe-service-recreation-20261203

Conversation

@alex-zaitsev
Copy link
Copy Markdown
Member

Summary

Follow-up implementation for #2165, addressing the last review comment: #2165 (comment)

This branch starts at #2165's head commit (2687ab5296ac457ee730525bc092f3c12af3ea9a), retaining its author's commit, then adds:

  • A dedicated errServiceHeadlessChanged sentinel returned from updateService() when spec.clusterIP switches between None and a regular ClusterIP (including an empty desired IP).
  • Recreate only on genuine NotFound, a Service type transition, or a headless/ClusterIP transition.
  • Remove broad apiErrors.IsInvalid(err) from the recreation decision. Invalid desired configuration now leaves a working Service in place and surfaces the failure.
  • Regression tests for both headless transitions, a normal ClusterIP update, type transitions, Invalid updates on a LoadBalancer, Conflict, and Forbidden errors.

Why a separate PR: The GitHub integration used for this fix could not push to the original contributor fork (403, despite maintainer_can_modify=true). The changes are on this Altinity branch so the author can cherry-pick the two follow-up commits into #2165, or maintainers can choose this branch as an alternative. This is not intended for merging alongside #2165 as an independent duplicate.

Validation

  • Checked the resulting branch diff contains only pkg/controller/chi/worker-service.go and the new pkg/controller/chi/worker-service_test.go.
  • The repository's Go tests and test_010012 should run in CI; they have not been run locally.

errServiceHeadlessChanged = errors.New("service headless mode changed")
)

func shouldRecreateService(err error) bool {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other immutable fields used to be fixed by the old delete+create fallback, for example switching ipFamilies / ipFamilyPolicy to a different primary family. Those now return Invalid on every reconcile and the Service never converges. If that's intended, could we at least say so in the error/event? Something like "immutable field changed, delete the Service manually".

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, agreed that Invalid can also arise from immutable fields such as the primary IP family. I kept the conservative behavior (do not delete a working Service on an ambiguous Invalid), and added an actionable failure event/log that says to validate the desired spec and manually delete/reconcile the Service for an intentional immutable-field transition. I also added a regression test for primary ipFamilies changes. See 3254455 and 6363391. I would prefer to handle automatic replacement only for specifically recognized transitions, not reintroduce IsInvalid as a blanket delete condition.

Comment thread pkg/controller/chi/worker-service.go Outdated
// Recreate is for the situations a recreate actually fixes, see shouldRecreateService. Any other
// error - a read that was Forbidden or spent its retry budget, an update that hit a Conflict or
// an admission webhook that is down - says nothing about whether the Service is healthy, so
// surface it and let the next pass re-read. Falling through would delete and create the Service,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"let the next pass re-read": I don't think there is a next pass here. Host and cluster callers only log the error or register it as failed, and the CR-level call runs from a defer that drops it. So a single Conflict leaves the Service stale until the CHI changes again. Maybe retry Get+Update once on Conflict?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed — the comment about the next pass was too optimistic. reconcileService() now retries once on Conflict: it fetches the live Service again, then updates using the refreshed resourceVersion. A repeated conflict or failed refresh returns an error without deleting the Service. Added tests for successful retry, bounded repeated conflict, and failed read. See 3254455 and 6363391. CI is running on the new head.

@devmalcevv
devmalcevv commented Dec 3, 2026 •
Copy link
Copy Markdown

@alex-zaitsev should I close my PR then? thx for picking this up

Copy link
Copy Markdown
Member Author

@devmalcevv Thanks! No need to close #2165 yet. #2185 now includes the additional review fixes and regression tests (CI is running). The two PRs contain overlapping changes, so only one should be merged. If we use #2185 as the replacement, #2165 can then be closed; alternatively, you can cherry-pick the follow-up commits into #2165 and we can close #2185.

if apiErrors.IsConflict(err) {
// A concurrent Service update may have changed resourceVersion. Re-read the
// live object and retry once. Do not delete it if the retry also conflicts.
latestService, getErr := w.c.getService(ctx, service)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hide comment

Nit: the retry has no tests for the re-Get returning NotFound or a changed type. Worth one case each?

This branch has not been deployed

No deployments
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.

3 participants

0