Skip to content

feat(library): split pkg/chop config machinery from the kube client wiring [stacked on #2160] - #2161

Open
sks wants to merge 2 commits into
Altinity:masterfrom
stackgenhq:chop-config-without-kube-client
Open

sks wants to merge 2 commits into
Altinity:masterfrom
stackgenhq:chop-config-without-kube-client

Conversation

@sks

@sks sks commented Nov 16, 2026

Copy link
Copy Markdown

Stacked PR — depends on #2158 ("fix(library): vendor the sunsingerus mergo fork so the operator imports as a Go module"). This branch contains #2160's commit underneath the config-split commit; it will rebase cleanly to a 1-commit diff the moment #2158 merges. Review #2160 first; the diff unique to this PR starts at 1608ba4.

What

Library consumers import the operator for its config generation, and today that drags the entire k8s.io/client-go surface through pkg/chop: the ConfigManager held *kube.Clientset and *chopclientset.Clientset fields, so any import of chop.Config() — the one accessor every consumer reads — compiled the full Kubernetes client machinery in.

The fix

Split the config machinery into pkg/chop/config, kube-free:

  • ConfigManager moves to pkg/chop/config behind two narrow function seams (the secretDataGetter pattern this codebase already established for the RootCA tests):
    • CRConfigLister — reads operator-configuration Custom Resources, answering specs + ResourceVersions (nil seam = file/env-only config, the library-consumer shape)
    • secretDataGetter — Kubernetes Secret reads (nil seam = secret refs log a warning and stay unresolved)
  • pkg/chop keeps New(), GetClientset, and the kube machinery, and adapts its clientsets to the seams — the operator binary's path is unchanged (same signature, same behavior, same logs)
  • ProvisionIPCToken stays exported from pkg/chop (thin wrapper over the config package's implementation)

Net effect

A consumer importing only pkg/chop/config has zero k8s.io/client-go modules in its dependency tree — verified with a scratch consumer (require → import → build; go list -deps shows only apimachinery types):

config manager built without any kube client: true
client-go modules in the consumer's tree: 0

Consumers of the operator outside Kubernetes — VM bootstrappers embedding the config/keeper model layer — no longer inherit the client surface they never call. Together with #2160, the operator's config machinery becomes consumable as a plain Go library.

Behavior

No behavior change: the CR listing, secret fetches, insecure-kube gate, and TLS min-version floor all run through the same logic — only the client boundary moved behind function seams. The in-tree package suite passes (pkg/chop, pkg/chop/config, pkg/apis/..., pkg/model/...); the only failing tests locally are pre-existing (macOS toolchain linker + vet warnings, identical on the base branch).

Happy to restructure (seam shapes, package name) to fit your review preferences.

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

(Supersedes the closed #2159 — same commits, moved to the org fork.)

sks and others added 2 commits November 16, 2026 11:29
…ts as a Go module

Upstream wires mergo.WithSliceDeepMerge (used by the exported API
packages - type_chi.go, type_templates.go, type_configuration_chop.go,
type_chk.go) through a replace directive:

    replace github.com/imdario/mergo => github.com/sunsingerus/mergo

Go replace directives do not propagate to consumers importing this
repository as a library module. Any downstream require of
clickhouse-operator fails at compile with:

    undefined: mergo.WithSliceDeepMerge

(Raised as Altinity#2150, closed without a fix.)

This vendors the sunsingerus fork's stdlib-only sources at
pkg/util/mergo (BSD-3-Clause, LICENSE included, provenance pinned to
fc6fffa94450) and swaps the four API packages' imports to it. The
non-propagating replace and the imdario require are gone from go.mod.

Net effect: a clean module consumer builds the exported API packages
with zero consumer-side replaces:

    require github.com/altinity/clickhouse-operator v0.27.4

No behavior change - the vendored sources are byte-identical to the
fork at the pinned commit (provenance.go documents the pin; do not
modify, re-vendor wholesale).

Context: chinit (the cloud-adaptive node bootstrapper for stateful
ClickHouse fleets on VMs) consumes the operator's config generation,
keeper machinery and API types as a library. The k8s-client wiring
stays upstream; the mergo vendoring is what makes that possible
without a fork.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…iring

Library consumers import the operator for its config generation, and
today that drags the entire k8s.io/client-go surface through pkg/chop:
the ConfigManager held *kube.Clientset and *chopclientset.Clientset
fields, so any import of chop.Config() - the one accessor every
consumer reads - compiled the full Kubernetes client machinery in.

This splits the config machinery into pkg/chop/config, kube-free:

- ConfigManager moves to pkg/chop/config with two narrow seams
  (the secretDataGetter pattern already established for the RootCA
  tests):
  - CRConfigLister - reads operator-configuration Custom Resources,
    answering specs + ResourceVersions (nil = file/env-only config,
    the library-consumer shape)
  - secretDataGetter - Kubernetes Secret reads (nil = secret refs
    log a warning and stay unresolved)
- pkg/chop keeps New(), GetClientset, and the kube machinery, and
  adapts its clientsets to the seams - the operator binary's path
  is unchanged (same signature, same behavior, same logs)
- ProvisionIPCToken stays exported from pkg/chop (wrapper over the
  config package's implementation)

Net effect: a consumer importing only pkg/chop/config has ZERO
k8s.io/client-go modules in its dependency tree (verified with a
scratch consumer: require -> import -> build; go list -deps shows
only apimachinery types). Consumers of the operator outside
Kubernetes (VM bootstrappers embedding the config/keeper model
layer) no longer inherit the client surface they never call.

No behavior change: the CR listing, secret fetches, insecure-kube
gate, and TLS min-version floor all run through the same logic -
only the client boundary moved behind function seams.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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.

1 participant