Skip to content

feat: fall back to a combined PostgreSQL + DocumentDB image when ImageVolume is unavailable  - #487

Merged
hossain-rayhan merged 4 commits into
documentdb:mainfrom
hossain-rayhan:rayhan/combined-image-fallback
Oct 30, 2026
Merged

hossain-rayhan merged 4 commits into
documentdb:mainfrom
hossain-rayhan:rayhan/combined-image-fallback

Conversation

@hossain-rayhan

Copy link
Copy Markdown
Collaborator

Summary

Today the operator only works where Kubernetes ImageVolume is usable. That needs both an API server with the ImageVolume feature gate on (GA in 1.35, beta and off by default in 1.33/1.34) and a node runtime that supports image volumes (containerd ≥ 2.1 or CRI-O ≥ 1.33). On other clusters the webhook rejects DocumentDB creation. Clusters with containerd 1.7 are worse: the API server accepts image volumes, so creation passes the webhook and the pods then hang.

This PR adds a combined-image fallback. When ImageVolume isn't usable, the operator runs PostgreSQL from one image that already contains the DocumentDB extension, documentdb-combined:18-<version>. ImageVolume stays the preferred layout wherever it works.

How it works

  • New Helm value imageMode:
    • auto (default): decide per new cluster.
    • imageVolume: always use ImageVolume. The webhook rejects creation when it's unavailable, which is the previous behavior.
    • combined: always use the combined image.
  • Detection in auto mode. It runs once, when the CNPG Cluster is first created:
    1. Node runtimes: every schedulable node must run containerd ≥ 2.1 or CRI-O ≥ 1.33.
    2. API server: a server-side dry-run probe checks whether pods with an image volume are accepted. If the probe is inconclusive, Kubernetes ≥ 1.35 counts as supported.
    3. If either check fails, the operator uses combined. Transient API errors make it retry instead of picking a mode.
  • The mode never changes. The choice is stored in the documentdb.io/image-mode annotation on the CNPG Cluster. Clusters created by earlier operator versions have no annotation and keep the ImageVolume layout.
  • Visibility: an ImageModeSelected event on the DocumentDB explains which mode was chosen and why.
  • Combined image: built from .github/dockerfiles/Dockerfile_combined on the CNPG postgresql:18-minimal-trixie base, with the same pinned postgresql-18-documentdb package as the extension image. It runs as UID 26. The tag 18-<version> follows the extension version, so engine upgrades in combined mode roll the image through CNPG's normal spec.imageName update.
  • Engine integration: the fallback plugs into the product-neutral engine.ClusterReconciler (refactoring: product neutral operator core #482) through an optional ImageModeDetector hook. Only DocumentDB uses it.

Changes

  • Operator: new internal/imagemode package (runtime parsing, node check, API probe, Detector), and cnpg.ApplyCombinedImageMode / IsCombinedImageMode. The engine selects the mode before creating the cluster, keeps existing combined clusters combined, and reports the combined image in status.documentDBImage. The webhook rejects only when imageMode=imageVolume, with a hint to switch to auto or combined.
  • Bug fix: the DocumentDB controller now has an event recorder, so its events are actually emitted. These include ImageModeSelected, PVsRetained, ExtensionRollback and SchemaUpdateAvailable; before this fix they were silently dropped.
  • Helm:
    • new values imageMode (validated) and image.documentdbCombined.repository
    • get/list on nodes in the operator ClusterRole
    • kubeVersion floor lowered from >= 1.33.0-0 to >= 1.32.0-0
  • Pipelines: build_documentdb_images.yml builds, signs and verifies documentdb-combined:18-<candidate> from the same verified .deb. release_documentdb_images.yml promotes it to 18-<version>.
  • CI: imagevolume-preflight asserts the ImageVolume layout was selected. imagevolume-block forces imageMode=imageVolume so it still covers the rejection path.
  • Docs: design doc docs/designs/combined-image-fallback.md, plus updates to the FAQ, Before You Start, image-management and the CHANGELOG.

Compatibility

  • Default behavior changes: on clusters without ImageVolume, DocumentDB creation now succeeds in combined mode instead of being rejected. Set imageMode: imageVolume to keep the old fail-fast behavior.
  • Existing clusters are never switched between modes.
  • Ignored in combined mode: spec.image.postgres and the change-stream images. Only the release tag of spec.image.documentDB is used.
  • Kubernetes 1.32 is the oldest version tested with the combined image. CloudNativePG tests 1.31/1.32 but officially supports only 1.33+.

Testing

Unit and Helm tests

  • make test: all operator packages pass, including the new imagemode package, the engine tests for mode selection, combined rendering and sync, and the webhook behavior per mode.
  • helm unittest: 113/113 pass, including the new env-var wiring, imageMode validation and the nodes RBAC rule.
  • kubeVersion: the chart renders on 1.32 and is refused on 1.31.

kind compatibility matrix

Each case ran on a fresh kind cluster with operator and sidecar images built locally from this branch. The combined image was built from Dockerfile_combined with the official PGDG postgresql-18-documentdb 1.0-0-1.pgdg13+1 package, and the chart was installed with default values plus imageMode where noted. Every case checked:

  • the mode recorded on the CNPG Cluster and the reason in the ImageModeSelected event
  • the pod's PostgreSQL image and image volumes
  • pg_extension version 1.0-0
  • a Mongo wire-protocol insert, index and query
# Kubernetes containerd ImageVolume gate imageMode Result Operator's reason
1 1.35.0 2.2.0 on by default auto ✅ imageVolume all node runtimes and the API server support image volumes
2 1.33.4 2.1.3 on auto ✅ imageVolume all node runtimes and the API server support image volumes
3 1.33.4 2.1.3 off auto ✅ combined API server does not accept image volumes (gate disabled)
4 1.32.0 1.7.24 n/a (off) auto ✅ combined node runs containerd 1.7.24; needs ≥ 2.1
5 1.33.4 1.7.24 ¹ on auto ✅ combined node runs containerd 1.7.24; needs ≥ 2.1
6 1.35.0 1.7.24 ¹ on by default auto ✅ combined node runs containerd 1.7.24; needs ≥ 2.1
7 1.32.5 2.1.1 off by default auto ✅ combined API server does not accept image volumes (gate disabled)
8 1.33.4 2.1.3 off imageVolume ✅ rejected webhook denies creation and points to auto or combined
9 1.35.0 2.2.0 on by default combined ✅ combined set by operator configuration

¹ A kind node image with the containerd 1.7.24 binaries from kindest/node:v1.32.0. No stock kind image pairs Kubernetes 1.33 or 1.35 with containerd 1.7.

Cases 5 and 6 show the runtime check works independently of the API probe: even when the API server supports ImageVolume, an old containerd still gets combined mode.

e2e in combined mode (Kubernetes 1.32.0, containerd 1.7.24)

  • lifecycle: 3 passed, 2 skipped
  • status: 3/3 passed
  • data: 26/26 passed

All 6 clusters created by the suites used combined mode, and the operator logged no errors or restarts. An earlier run on the pre-rebase branch also upgraded the database version in combined mode (0.117.0 → 1.0.0); the rolling update and ALTER EXTENSION worked and data was preserved.

Release steps (after merge)

documentdb-combined:18-1.0.0 isn't published yet. Until it is, auto mode on clusters without ImageVolume would hang pulling a missing image.

  1. Run RELEASE - Build DocumentDB Candidate Images with version: 1.0.0 and package_source: apt. This only creates new candidate tags.
  2. Promote only the combined image, so the released documentdb:1.0.0 and gateway:1.0.0 tags stay as they are:
    R=ghcr.io/documentdb/documentdb-kubernetes-operator/documentdb-combined
    docker buildx imagetools create -t $R:18-1.0.0 $R:18-<candidate-tag>
  3. Make sure the new documentdb-combined GHCR package is public, so an anonymous pull works.
  4. Release the operator.

Later database releases promote the combined image automatically.

Known limitations / follow-ups

  • No CI e2e job runs combined mode yet; it needs the combined image built in the e2e build stage.
  • With mixed node pools, a single unsupported schedulable node selects combined for the whole new cluster. Node affinity isn't considered.
  • There's no in-place migration from combined to imageVolume.
  • Cross-region replication between a combined cluster and an ImageVolume cluster is untested.
  • internal/imagemode has its own copy of the ImageVolume probe, separate from internal/validation. Merging them is a follow-up.

…ume is unavailable

Add an imageMode setting (auto | imageVolume | combined). In auto mode the
operator inspects node container runtimes and probes the API server when a
CNPG cluster is first created; when ImageVolume is not usable (e.g.
containerd 1.7, or ImageVolume gate disabled) it renders the cluster with a
combined documentdb-combined:18-<version> image instead of an extension
image volume. The selected mode is persisted in the documentdb.io/image-mode
annotation and reported via an ImageModeSelected event.

- New Dockerfile_combined and build/release pipeline entries
- Webhook only rejects when imageMode=imageVolume
- Helm: imageMode, image.documentdbCombined.repository, nodes RBAC,
  kubeVersion >= 1.32
- Fix: wire an event recorder into the DocumentDB controller
- Design doc: docs/designs/combined-image-fallback.md

Co-authored-by: Copilot <[email protected]>
Copilot-Session: a381594c-340d-4439-8e1f-0388d38a3c61
Signed-off-by: Rayhan Hossain <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 29, 2026 22:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Image-version inconsistencies can bypass rollback protection and deploy older binaries against newer schemas, while an unguarded Helm value can block upgrades of existing releases.

4 open issues
What changed in this PR

Adds a combined PostgreSQL + DocumentDB image fallback through the existing product-neutral reconciliation engine, allowing new clusters to run without ImageVolume while preserving existing clusters’ layouts.

Changes:

  • Detects ImageVolume support, persists the selected mode, and exposes configuration through Helm.
  • Adds combined-image rendering, status reporting, build and release pipelines, and controller event recording.
  • Lowers the chart’s Kubernetes minimum to 1.32 and updates tests and compatibility documentation.
File Description
operator/​src/​internal/​webhook/​imagevolume.go Limits ImageVolume admission checks to forced mode.
operator/​src/​internal/​webhook/​imagevolume_test.go Tests admission behavior for each mode.
operator/​src/​internal/​webhook/​documentdb_webhook_test.go Tests default acceptance and forced rejection.
operator/​src/​internal/​utils/​util.go Resolves combined-image references and tags.
operator/​src/​internal/​utils/​image_source_test.go Tests combined-image version and repository selection.
operator/​src/​internal/​utils/​constants.go Defines combined-image configuration constants.
operator/​src/​internal/​product/​intent.go Adds the combined image to cluster intent.
operator/​src/​internal/​product/​documentdb.go Supplies DocumentDB’s combined-image reference.
operator/​src/​internal/​product/​documentdb_test.go Tests adapter image resolution.
operator/​src/​internal/​imagemode/​suite_test.go Registers the image-mode test suite.
operator/​src/​internal/​imagemode/​probe.go Adds the differential API capability probe.
operator/​src/​internal/​imagemode/​imagemode.go Implements runtime checks and mode selection.
operator/​src/​internal/​imagemode/​imagemode_test.go Tests detection and configuration behavior.
operator/​src/​internal/​engine/​image_mode_test.go Tests initial mode selection and error handling.
operator/​src/​internal/​engine/​extension.go Reports the combined image in status.
operator/​src/​internal/​engine/​cluster_reconciler.go Selects and preserves cluster image mode.
operator/​src/​internal/​controller/​documentdb_controller.go Wires detection and declares node-read permissions.
operator/​src/​internal/​controller/​documentdb_controller_test.go Tests combined-image status reporting.
operator/​src/​internal/​cnpg/​image_mode.go Applies and identifies combined-image rendering.
operator/​src/​internal/​cnpg/​image_mode_test.go Tests rendering and image upgrade synchronization.
operator/​src/​cmd/​main.go Enables DocumentDB controller events.
operator/​documentdb-helm-chart/​values.yaml Adds mode and combined-repository settings.
operator/​documentdb-helm-chart/​tests/​09_operator_deployment_test.yaml Tests environment wiring and mode validation.
operator/​documentdb-helm-chart/​tests/​05_clusterrole_test.yaml Tests node-read permissions.
operator/​documentdb-helm-chart/​templates/​09_documentdb_operator.yaml Passes image settings to the operator.
operator/​documentdb-helm-chart/​templates/​05_clusterrole.yaml Grants node-read permissions.
operator/​documentdb-helm-chart/​Chart.yaml Lowers the Kubernetes floor to 1.32.
docs/​operator-public-documentation/​preview/​getting-started/​before-you-start.md Updates prerequisites and fallback configuration.
docs/​operator-public-documentation/​preview/​faq.md Explains revised compatibility and fallback behavior.
docs/​designs/​image-management.md Adds the combined image to the database track.
docs/​designs/​combined-image-fallback.md Documents detection, persistence, upgrades, and limitations.
CHANGELOG.md Records fallback support and event-recorder wiring.
.github/​workflows/​test-e2e.yml Asserts ImageVolume selection and forces rejection mode.
.github/​workflows/​release_documentdb_images.yml Promotes combined-image release tags.
.github/​workflows/​build_documentdb_images.yml Builds, signs, and verifies combined images.
.github/​dockerfiles/​Dockerfile_combined Packages PostgreSQL and DocumentDB together.

Review effort: Balanced

- name: DOCUMENTDB_EXTENSION_IMAGE_REPO
value: "{{ include "documentdb.imageRef" (dict "name" "image.documentdb.repository" "registry" .Values.image.registry "repo" .Values.image.documentdb.repository "tag" "") }}"
{{- end }}
{{- if .Values.image.documentdbCombined.repository }}

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.

Independently reproduced against an installed pre-change release with helm upgrade documentdb-operator . -n documentdb-operator --reuse-values --dry-run=client: rendering fails at line 124 with nil pointer evaluating interface {}.repository. All 113 normal Helm tests pass, so an upgrade/reused-values regression case is needed in addition to guarding this new parent map. No cluster resources were changed by the dry-run.

Comment thread operator/src/internal/utils/util.go Outdated
Comment on lines +593 to +595
version := ImageTag(explicitExtensionImage)
if !combinedVersionTagPattern.MatchString(version) {
version = specVersion

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.

Confirmed with a focused regression test on c532370. With combined mode configured, old schema/status 1.0.0, spec.documentDBVersion retained at 1.0.0, and a new explicit extension reference tagged 0.117.0 plus a SHA-256 digest, DocumentDBAdapter.CombinedImage renders documentdb-combined:18-0.117.0 while resolveBinaryVersion returns 1.0.0; validateImageRollback returns zero errors. This is a real rollback-guard bypass, not only inconsistent reporting. Please share effective binary-version resolution between rendering and admission, including tag+digest and fallback inputs.

Comment on lines +318 to +319
if currentExtImage == "" && cnpg.IsCombinedImageMode(cluster) {
currentExtImage = cluster.Spec.ImageName
Comment on lines +63 to +66
returned, err := dryRunProbePod(ctx, c, namespace, imageProbeVolume())
if err != nil {
logger.Info("ImageVolume API probe: image-volume probe pod rejected while baseline passed; feature unavailable", "error", err)
return ProbeUnsupported

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.

Confirmed with focused tests injecting Kubernetes NewTimeoutError into each dry-run request independently. With a capable containerd 2.1.3 node and Kubernetes 1.34, a baseline timeout returns combined with nil error via the version fallback; an image-probe timeout also returns combined with nil error and incorrectly reports the feature gate disabled. Both outcomes permanently select a mode instead of retrying. Node-list transient errors are covered, but transient errors from both probe requests need the same treatment.

@xgerman xgerman left a comment

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.

Reviewed c532370. The combined-image rendering and fixed per-cluster mode are a useful approach, but the four existing findings should be addressed before merging. I added independent reproduction evidence to the relevant inline threads rather than opening duplicate findings.

Severity Issue Verification
High Combined-image rendering and admission disagree on the effective binary version, allowing a downgrade below the installed schema. A focused test with installed schema 1.0.0, spec.documentDBVersion 1.0.0, and explicit image 0.117.0 plus a digest rendered combined:18-0.117.0 while admission resolved 1.0.0 and returned no rollback errors. #487 (comment)
High A normal upgrade with --reuse-values fails on the new missing image.documentdbCombined map. Reproduced using a client dry-run against an installed pre-change release; template line 124 raises a nil-pointer error. #487 (comment)
Medium Transient failures in either API dry-run can permanently select combined mode. Injected Kubernetes timeout errors into baseline and image requests independently; both returned combined with nil error on a capable 1.34 setup instead of retrying. #487 (comment)
Medium Long-haul upgrade completion compares an image tag prefixed with the PostgreSQL major against an unprefixed DocumentDB version. Traced GetCurrentDocumentDBImageTag through upgrade precondition and polling: 18-1.0.0 never equals target 1.0.0, so completed upgrades time out and remain eligible. #487 (comment)

The existing focused Go suites (imagemode, cnpg, engine, product, utils, webhook, controller) and all 113 Helm tests pass, but miss the reproduced regression cases. CI E2E jobs are still in progress at review time. I did not deploy this PR or build the combined image locally; the only cluster interaction was a non-mutating Helm upgrade dry-run. Temporary reproduction tests were removed and no source changes remain.

hossain-rayhan and others added 3 commits October 30, 2026 09:39
- Admission and combined-image rendering now share util.ReleaseVersionTag,
  which ignores the tag of digest-qualified references. Previously
  "repo:0.117.0@sha256:..." rendered documentdb-combined:18-0.117.0 while
  admission validated spec.documentDBVersion, bypassing the image-rollback
  guard. Regression tests assert both resolve the same version.
- The ImageVolume API probe returns retryable failures of either dry-run
  (timeouts, throttling, 5xx, transport errors) as errors, so Detect requeues
  instead of permanently selecting combined mode. Only definitive 4xx
  rejections count as unsupported or inconclusive.
- Helm: guard image.documentdbCombined so `helm upgrade --reuse-values` from a
  release without the new values renders; add a regression test.
- Long-haul: GetCurrentDocumentDBImageTag strips the combined image's
  PostgreSQL major prefix (18-1.0.0 -> 1.0.0) so upgrade checks compare
  DocumentDB versions.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 6c85cd4b-f086-46f7-8823-7e63c33e4de7
Signed-off-by: Rayhan Hossain <[email protected]>
Follow-up from a pre-review pass on PR documentdb#487.

- release_operator.yml: a verify-combined-image job anonymously inspects
  documentdb-combined:18-<documentDbVersion> before promoting operator images,
  so a release fails while the fallback image is missing or private.
- Probe pods carry minimal CPU/memory requests and limits, so namespaces whose
  quota or policy requires limits no longer make the probe inconclusive (which
  selected combined permanently below 1.35). 401 is retried.
- CheckNodes only checks schedulable Linux nodes that report a runtime; with no
  such node (scale-to-zero, cordoned upgrade) the API server decides alone.
- Combined-image rendering uses ExtractSemver (moved to utils and shared with
  admission) to recognize a release tag, so tags like ":0.110" fall back to
  documentDBVersion exactly as admission does.
- IsCombinedImageMode also recognizes a combined cluster whose annotation was
  removed, so CNPG syncing does not wedge.
- Move the nodes RBAC marker to a package-level block so controller-gen
  emits it; remove the unused webhook probeImageVolume helper.
- Docs: detection details, release gate, minimum combined version (1.0.0),
  unsupported downgrade, recreating clusters stuck on containerd 1.7, frozen
  base image, and that forced imageVolume mode cannot check node runtimes.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 6c85cd4b-f086-46f7-8823-7e63c33e4de7
Signed-off-by: Rayhan Hossain <[email protected]>
The long-haul lint job runs actionlint (with shellcheck) through reviewdog on
the workflow files a PR changes. Touching release_operator.yml surfaced its
existing SC2129 (error level) and SC2086/SC2035 findings and failed the gate.
Quote expansions, group the step-summary redirects, use ./*glob for the chart
lookup, and pass docker build args as an array. No behaviour change.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 6c85cd4b-f086-46f7-8823-7e63c33e4de7
Signed-off-by: Rayhan Hossain <[email protected]>
@WentingWu666666

Copy link
Copy Markdown
Collaborator

Could we add a CI E2E case with ImageVolume disabled and imageMode=auto, asserting combined mode is selected, the database becomes healthy, and a write/read succeeds? The current negative-path job forces imageVolume, so it does not exercise the new fallback end to end.

@hossain-rayhan

Copy link
Copy Markdown
Collaborator Author

Could we add a CI E2E case with ImageVolume disabled and imageMode=auto, asserting combined mode is selected, the database becomes healthy, and a write/read succeeds? The current negative-path job forces imageVolume, so it does not exercise the new fallback end to end.

It's the first follow-up item I believe. Additionally, I verified in local kind cluater and uploaded the test metrics here. Once I publish the combined image, I will add the e2e test.

@hossain-rayhan
hossain-rayhan merged commit f636cf5 into documentdb:main Oct 30, 2026
78 of 79 checks passed
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.

5 participants