Skip to content

Extract variant branches into a generic extension mechanism#4871

Draft
caseydavenport wants to merge 16 commits into
tigera:masterfrom
caseydavenport:casey-variant-extensions
Draft

Extract variant branches into a generic extension mechanism#4871
caseydavenport wants to merge 16 commits into
tigera:masterfrom
caseydavenport:casey-variant-extensions

Conversation

@caseydavenport
Copy link
Copy Markdown
Member

@caseydavenport caseydavenport commented May 29, 2026

This is phase 1 of prepping the operator for the monorepo merge. The goal is to get the variant branches (the IsEnterprise() checks) out of the core operator render code and into a generic extension mechanism, so enterprise can self-register its modifications instead of core code having to know about them.

Description

Adds the extension primitives in pkg/extensions:

  • A modifier registry - enterprise registers a function keyed by component name, applied at the componentHandler chokepoint after a component's objects are built.
  • An image-override registry - lets enterprise swap the image a component resolves without core branching. It lives in a small pkg/imageoverride leaf package to avoid an import cycle; pkg/extensions delegates to it.
  • A render context factory - the installation controller builds the RenderContext handed to modifiers through a registered factory, which also does the per-controller side-effecting work (cert creation, bundle assembly, validation). The core operator default does nothing variant-specific.

Enterprise wiring lives in pkg/enterprise, which self-registers all of this through enterprise.Register().

De-varianting progress

The metric is zero IsEnterprise() branches left in the core render/controller code for each component - they all move into pkg/enterprise:

  • typha
  • node
  • guardian
  • windows
  • apiserver

typha and node are done. Image selection routes through the override registry, and all of node's variant branches (RBAC for node and the CNI plugin, volumes, CNI env, Felix env, readiness probe, the metrics service, and the prometheus cert/bundle setup) now live in enterprise modifiers. The calico log directory is mounted for both variants so the modifier doesn't have to special-case it.

Still deferred

  • The kube-controllers TLS setup and the remaining value-selection branches in the installation controller.

Behavior is preserved. The test gate is the union of the existing core tests plus the relocated enterprise assertions, all passing.

None

Add WithContext/ComponentHandlerOption to NewComponentHandler (variadic,
backward-compatible) and call operator.ApplyPatches in
CreateOrUpdateOrDelete for components implementing render.Named.
Pulls the enterprise RBAC extra-rules and MULTI_INTERFACE_MODE env branches out of pkg/render/typha.go into a new pkg/enterprise package. The enterprise package registers a patch via operator.Patch on startup; pkg/render/typha.go now has zero IsEnterprise branches.
Calls enterprise.Register() at startup so the typha modifier is wired in.
Builds an operator.Context in the installation reconciler and passes it to
the component handler so registered modifiers receive reconcile-derived state.
Extracts the image override registry into a leaf pkg/imageoverride
package (no render/operator transitive deps) to avoid the render→operator
import cycle. operator.OverrideImage/ResolveImage now delegate there.
Registers the enterprise node image override in pkg/enterprise. Removes
the IsEnterprise image switch from render/node.go; FIPS handling is
preserved via a post-resolve check.
…sion

The OSS installation controller no longer directly creates the node-prometheus
keypair or fetches the prometheus/esgw certs. Those are now handled by a
registered InstallationExtension in pkg/enterprise. Port value derivation and
the kube-controller TLS block remain in the OSS controller unchanged.
Moves the calico-node-metrics Service out of OSS node render and into
the enterprise node modifier, where it derives ports from
ctx.FelixConfiguration. Also exports NodeBGPReporterPort so the modifier
can reference it.
# Conflicts:
#	pkg/controller/installation/core_controller_test.go
#	pkg/controller/utils/component.go
#	pkg/render/node.go
Comment thread pkg/controller/utils/component.go Outdated
Comment thread pkg/enterprise/installation.go Outdated
Comment thread pkg/operator/context.go Outdated
Comment thread pkg/operator/extension.go Outdated
Comment thread pkg/operator/extension.go Outdated
Comment thread pkg/enterprise/installation.go Outdated
Comment thread pkg/operator/patch.go Outdated
Comment thread pkg/enterprise/node.go
Comment thread pkg/render/enterprise_setup_test.go Outdated
Comment thread cmd/main.go
The registry package is renamed to extensions. The installation controller builds the render context through a registered factory, and the componentHandler applies registered modifiers to component output. The node and typha variant branches now live in enterprise modifiers, and the calico log directory is mounted for both variants.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants