Skip to content

feat: block DocumentDB creation when ImageVolume is unavailable (#431) - #437

Merged
WentingWu666666 merged 10 commits into
documentdb:mainfrom
WentingWu666666:developer/wenting-imagevolume-preflight
Jul 30, 2026
Merged

WentingWu666666 merged 10 commits into
documentdb:mainfrom
WentingWu666666:developer/wenting-imagevolume-preflight

Conversation

@WentingWu666666

@WentingWu666666 WentingWu666666 commented Jul 29, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The operator hard-depends on the Kubernetes ImageVolume feature
(corev1.ImageVolumeSource) to mount the DocumentDB extension into PostgreSQL
pods. Previously, on a cluster lacking that feature the pods would simply hang
with no clear signal, and a coarse "k8s ≥ 1.35" startup gate blocked otherwise-
capable 1.33/1.34 clusters.

This PR makes the operator fail fast with an actionable error at
DocumentDB creation, and replaces the version gate with a capability probe
so any cluster that actually has ImageVolume — including 1.33/1.34 with the beta
gate enabled — is admitted.

Closes #431.

How it works

Detection is capability-based, not version-based: the validating webhook
runs a differential server-side dry-run — an emptyDir baseline Pod plus an
identical ImageVolumeSource Pod:

baseline image volume verdict
accepted accepted supported → admit
accepted rejected unsupported → block (403 Forbidden, actionable message)
rejected — inconclusive (PSA/quota/other webhook) → admit (fail-open)

Only positive results are cached (atomic.Bool), so steady-state create latency
is ~0, and enabling the gate later works without restarting the operator. No new
RBAC — the operator ClusterRole already grants create on pods.

Changes

  • internal/webhook/imagevolume.go — capability probe
    (ensureImageVolumeSupported + probeImageVolume) with an actionable error
    message.
  • internal/webhook/documentdb_webhook.go — ValidateCreate runs the
    preflight first (create-only; it's a cluster capability, not a per-spec
    property), returning apierrors.NewForbidden on failure. Kept separate from
    spec validation (v.validate), which stays pure and returns 422 Invalid.
  • Replaced the coarse k8s ≥ 1.35 gate with the probe as the single source of
    truth: removed validateK8sVersion() + its SetupWithManager call and the
    util.MinK8sMinorVersion constant; relaxed Chart.yaml kubeVersion from
    >= 1.35.0-0 to >= 1.33.0-0.
  • Unit tests (imagevolume_test.go) covering supported / unsupported /
    inconclusive / cache-short-circuit + admission-handler coverage.
  • CI — setup-test-environment gains an opt-in enable-image-volume-gate
    input (writes a kind config with featureGates: {ImageVolume: true}), and a
    standalone imagevolume-preflight job (k8s 1.33.7 and 1.34.3, gate on)
    proves the operator admits a DocumentDB and reaches Healthy — i.e. the
    extension image mounts at runtime. The gate-off/blocked path is covered by the
    unit tests.
  • Docs — before-you-start.md + faq.md now describe the capability-based
    requirement: 1.35+ recommended (GA, on by default); 1.33/1.34 supported with
    the gate enabled (containerd ≥ 2.1 / CRI-O ≥ 1.33); managed offerings generally
    can't toggle the gate.

Behavior matrix

K8s ImageVolume Result
≥ 1.35 on (default) admitted ✅
1.33–1.34 gate enabled admitted ✅ (CI-verified)
any unavailable blocked with actionable error ❌
any probe inconclusive (PSA/quota) admitted (fail-open)

Testing

  • go build ./..., go vet ./... — clean
  • go test ./internal/webhook/... — pass
  • helm lint — pass
  • New imagevolume-preflight CI job exercises k8s 1.33/1.34 with the gate on.

Co-authored-by: Copilot [email protected]

wentingwu000 and others added 3 commits July 29, 2026 10:12
The operator mounts the DocumentDB extension into the PostgreSQL pod via
a corev1.ImageVolumeSource. On a cluster where the Kubernetes ImageVolume
feature is unavailable (feature gate off on <1.35, or an unsupported
runtime) the CNPG pods can never mount the extension and the cluster
silently hangs with no clear signal.

Add a capability-based preflight to the validating webhook's
ValidateCreate: a differential server-side dry-run submits an emptyDir
baseline Pod and an identical ImageVolumeSource Pod. If the baseline is
admitted but the image-volume Pod is rejected, ImageVolume is
unavailable and creation is blocked with an actionable error. The check
is capability-based (not version-based) so it admits 1.33/1.34 clusters
that have the beta gate enabled, and fails open when the probe is
inconclusive (PSA/quota/other webhooks rejecting the baseline). Only
positive results are cached, so enabling the gate later needs no
operator restart. No new RBAC is required.

Refs documentdb#431

Co-authored-by: Copilot <[email protected]>
Copilot-Session: bb9586dd-7b58-4da3-8375-ebc7d44cccf1
Signed-off-by: Wenting Wu <[email protected]>
… probe

The operator previously hard-blocked clusters below Kubernetes 1.35 in
two places: validateK8sVersion() failed operator startup, and the Helm
chart's kubeVersion floor blocked installation. Both gate on version
even though 1.33/1.34 work fine once the ImageVolume beta feature gate
is enabled (containerd >= 2.1 / CRI-O >= 1.33).

Replace the coarse version gate with the webhook capability probe added
in the previous commit, which is the single source of truth:

- Remove validateK8sVersion() and its SetupWithManager call (and tests).
- Remove the now-unused util.MinK8sMinorVersion constant.
- Relax Chart.yaml kubeVersion from ">= 1.35.0-0" to ">= 1.33.0-0"
  (older releases lack ImageVolume entirely).

The probe's per-CR granularity also improves UX: a misconfigured
cluster gets a clear DocumentDB admission error instead of a
crash-looping operator.

Refs documentdb#431

Co-authored-by: Copilot <[email protected]>
Copilot-Session: bb9586dd-7b58-4da3-8375-ebc7d44cccf1
Signed-off-by: Wenting Wu <[email protected]>
Drop the speculative AKS/EKS/GKE claim and reframe the container runtime
requirement (containerd >= 2.1 / CRI-O >= 1.33) as something the dry-run
preflight cannot verify, so users know it is a real prerequisite the
webhook does not check.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: bb9586dd-7b58-4da3-8375-ebc7d44cccf1
Signed-off-by: Wenting Wu <[email protected]>
@documentdb-triage-tool documentdb-triage-tool Bot added enhancement New feature or request go Pull requests that update go code test labels Jul 29, 2026
@documentdb-triage-tool

Copy link
Copy Markdown

🤖 Auto-triaged by documentdb-triage-tool.

Applied: go, test, enhancement
Project fields suggested: Component controllers · Priority P2 · Effort L · Status In Progress
Confidence: 0.82 (mixed)

Reasoning

component from path globs (controllers, test); effort from diff stats (320+164 LOC, 8 files); LLM: Adds capability-based ImageVolume preflight detection to the validating webhook, replacing a coarse version gate — multi-file change touching webhook logic, unit tests, and chart metadata with a meaningful UX improvement but no data-loss or security risk.

If a label is wrong, remove it manually and ping @patty-chow so the rules can be tuned. The bot will not re-label items that already have component labels.

wentingwu000 and others added 6 commits July 29, 2026 11:04
…bled

Prove the operator works on Kubernetes versions below the 1.35 ImageVolume
GA when the feature gate is turned on. Two pieces:

- setup-test-environment composite action gains an opt-in
  enable-image-volume-gate input that writes a kind config with a
  top-level featureGates: {ImageVolume: true} block (applied to the
  apiserver and every kubelet) and passes it to helm/kind-action. When
  the input is left at its 'false' default the step is skipped and the
  kind config is empty, so existing callers are unaffected.

- test-e2e.yml gains a standalone imagevolume-preflight job with a
  k8s 1.33.7 / 1.34.3 matrix that reuses the composite action with the
  gate enabled. The action already deploys a DocumentDB and waits for
  Healthy during setup, so a green setup is the end-to-end assertion:
  the webhook capability probe admits the CR and the extension image
  mounts at runtime (containerd >= 2.1 in kind's 1.33/1.34 node images).
  No Ginkgo specs run; the gate-off/blocked path stays covered by the
  webhook unit tests.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: bb9586dd-7b58-4da3-8375-ebc7d44cccf1
Signed-off-by: Wenting Wu <[email protected]>
…pported)

Replace the hard 'Kubernetes 1.35+ required' wording with the actual
capability-based requirement: 1.35+ is the recommended baseline (ImageVolume
GA, on by default), and 1.33/1.34 also work when the ImageVolume feature gate
is enabled on the apiserver and kubelets with a supporting runtime
(containerd >= 2.1 / CRI-O >= 1.33). Note that the admission webhook now
rejects DocumentDB creation with an actionable error when the feature is
unavailable, and that managed offerings generally cannot toggle the gate.

Updates the prerequisites table and admonitions in before-you-start.md and
the corresponding FAQ answers. The quickstart pages intentionally keep 1.35
as the simple happy path.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: bb9586dd-7b58-4da3-8375-ebc7d44cccf1
Signed-off-by: Wenting Wu <[email protected]>
Collapse the two stacked warning/note blocks in before-you-start.md into a
single concise warning. The separate 'Advanced: 1.33/1.34' step-by-step
duplicated the prerequisites table and was overly verbose; the essential
facts (containerd/CRI-O runtime requirement, 1.35+ baseline, 1.33/1.34 with
the gate enabled, and the webhook's fail-fast rejection) are retained.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: bb9586dd-7b58-4da3-8375-ebc7d44cccf1
Signed-off-by: Wenting Wu <[email protected]>
… inputs

Add a negative CI check that proves the operator fails fast: on a k8s 1.33
cluster with the ImageVolume gate left off, the admission webhook must reject
DocumentDB creation with an actionable ImageVolume error.

Rather than baking ImageVolume-specific assertion logic into the shared
setup-test-environment composite action, keep the action generic and move the
specifics to the workflow:

- Generalize the composite action inputs: replace the ImageVolume-specific
  'enable-image-volume-gate' boolean with a reusable 'kind-feature-gates'
  comma-separated list, and add a general 'deploy-documentdb' toggle (default
  true) that lets a caller provision the cluster + operator without deploying a
  DocumentDB. The action no longer contains any ImageVolume-specific steps.

- test-e2e.yml: the positive imagevolume-preflight job now passes
  kind-feature-gates: ImageVolume; a new imagevolume-block job provisions with
  deploy-documentdb: false and then asserts, in a workflow step, that
  'kubectl apply' of a DocumentDB fails with a message mentioning ImageVolume.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: bb9586dd-7b58-4da3-8375-ebc7d44cccf1
Signed-off-by: Wenting Wu <[email protected]>
The negative imagevolume-block job admitted the DocumentDB instead of
rejecting it: on kind's v1.33.7 node a pod with an ImageVolumeSource is
accepted at dry-run even when we don't enable the gate, so the webhook
probe correctly concluded ImageVolume was supported.

Rather than depend on the version's default (which is inconsistent across
node images), explicitly disable the gate. Generalize the composite
action's kind-feature-gates input to accept per-gate values
("Name", "Name=true", or "Name=false") and set 'ImageVolume=false' in
the block job so the cluster deterministically lacks the feature.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: bb9586dd-7b58-4da3-8375-ebc7d44cccf1
Signed-off-by: Wenting Wu <[email protected]>
The ImageVolume capability probe (probeImageVolume) previously relied
only on whether a server-side dry-run Pod create succeeded or errored.
On Kubernetes 1.33/1.34 with the ImageVolume beta feature gate OFF, the
apiserver does NOT reject a Pod carrying an ImageVolumeSource: it
silently prunes the disabled field and returns success. The old probe
therefore false-positived as "supported" and admitted the DocumentDB,
leading to the silent-hang failure mode this preflight is meant to
prevent (postgres initdb crash-loops because the extension image volume
was never mounted).

dryRunProbePod now returns the server-processed Pod, and probeImageVolume
inspects whether the ImageVolumeSource survived via a new hasImageVolume
helper. If the image volume was pruned from the returned spec, the
feature is treated as unavailable and creation is blocked with the
existing actionable error.

Added unit tests: a pruneImageVolume fake createFn modeling a gate-off
1.33 apiserver, plus probeImageVolume and ensureImageVolumeSupported
specs asserting the pruned case is detected and blocked.

Verified locally on a real kind 1.33.4 cluster (gate off): before the
fix the DocumentDB was admitted and pods hung; after the fix it is
rejected with the ImageVolume error. Unit tests, go build, and go vet
all pass.

Refs documentdb#437

Co-authored-by: Copilot <[email protected]>
Copilot-Session: true
Signed-off-by: Wenting Wu <[email protected]>
@WentingWu666666
WentingWu666666 marked this pull request as ready for review July 29, 2026 17:13
Copilot AI review requested due to automatic review settings July 29, 2026 17:13

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.

Pull request overview

This PR replaces the operator’s coarse Kubernetes version gate with a capability-based admission preflight that detects whether the cluster supports corev1.ImageVolumeSource (ImageVolume) and fails fast at DocumentDB creation time when it’s unavailable. This prevents “stuck” clusters on unsupported environments while allowing 1.33/1.34 clusters that have the feature gate enabled.

Changes:

  • Added an ImageVolume capability probe in the validating webhook (dry-run baseline Pod vs ImageVolume Pod) with positive-result caching and fail-open behavior when inconclusive.
  • Wired the preflight into ValidateCreate (403 Forbidden on unsupported clusters) and removed the controller startup Kubernetes version gate + related constant/tests.
  • Updated Helm chart kubeVersion constraints, docs, and CI to exercise both the positive (gate enabled) and negative (gate disabled) paths on 1.33/1.34 kind clusters.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
operator/src/internal/webhook/imagevolume.go Implements the differential dry-run ImageVolume capability probe and positive-result cache.
operator/src/internal/webhook/imagevolume_test.go Adds unit tests for supported/unsupported/inconclusive outcomes and cache short-circuiting.
operator/src/internal/webhook/documentdb_webhook.go Runs ImageVolume preflight during ValidateCreate and returns 403 Forbidden on failure.
operator/src/internal/webhook/documentdb_webhook_test.go Updates admission tests to account for the new preflight and adds a blocked-creation case.
operator/src/internal/utils/constants.go Removes the minimum Kubernetes minor version constant used by the old version gate.
operator/src/internal/controller/documentdb_controller.go Removes the controller startup-time Kubernetes version validation logic.
operator/src/internal/controller/documentdb_controller_test.go Removes tests for the deleted Kubernetes version validation behavior.
operator/documentdb-helm-chart/Chart.yaml Relaxes chart kubeVersion to >=1.33.0-0 and updates comments to reflect capability gating.
docs/operator-public-documentation/preview/getting-started/before-you-start.md Updates prerequisites to describe ImageVolume requirements and 1.33/1.34 gate-enabled support.
docs/operator-public-documentation/preview/faq.md Updates version requirement explanation to be capability-based and actionable.
.github/workflows/test-e2e.yml Adds ImageVolume preflight (gate enabled) and block (gate disabled) CI jobs for k8s 1.33/1.34.
.github/actions/setup-test-environment/action.yml Adds kind feature-gate config generation and optional “deploy DocumentDB” behavior for CI scenarios.
Comments suppressed due to low confidence (1)

operator/src/internal/webhook/imagevolume.go:103

  • Logging the error value as err.Error() loses structured error details and prevents log processors from handling errors consistently. Pass the error itself as the field value.
	returned, err := v.dryRunProbePod(ctx, namespace, imageProbeVolume())
	if err != nil {
		documentdbLog.Info("ImageVolume preflight: image-volume probe pod rejected while baseline passed; feature unavailable", "error", err.Error())
		return false, true

Comment on lines +22 to 24
| **Kubernetes cluster** | 1.35+ (or 1.33/1.34 with the ImageVolume gate enabled) | Container orchestration platform | See [Cluster Options](#kubernetes-cluster-options) |
| **kubectl** | 1.33+ | Kubernetes command-line tool | [Install kubectl](https://kubernetes.io/docs/tasks/tools/) |
| **Helm** | 3.x | Package manager for Kubernetes | [Install Helm](https://helm.sh/docs/intro/install/) |

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 1e51a62 — bumped the minimum kubectl to 1.34+, the earliest supported within ±1 minor of the 1.35 baseline, with a clarifying note in the table.

Comment on lines +95 to +98
if _, err := v.dryRunProbePod(ctx, namespace, baselineProbeVolume()); err != nil {
documentdbLog.Info("ImageVolume preflight inconclusive: baseline probe pod rejected", "error", err.Error())
return false, false
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 1e51a62 — both probe log lines now pass the error value directly ("error", err) instead of err.Error(), preserving structured error details for log processors.

Comment on lines +5 to +9
# The operator requires the Kubernetes ImageVolume feature (GA in 1.35, beta and
# opt-in via feature gate in 1.33/1.34). The operator's validating webhook performs
# a capability probe at DocumentDB creation time rather than gating on version, so
# the chart only requires 1.33+ (older releases lack ImageVolume entirely).
kubeVersion: ">= 1.33.0-0"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 1e51a62 — reworded the comment to note that 1.31/1.32 had ImageVolume as alpha (not usable with these operator images) rather than the feature being entirely absent, while keeping kubeVersion: ">= 1.33.0-0".

|-----------|-----------------|---------|-------------------|
| **Kubernetes cluster** | 1.35+ | Container orchestration platform | See [Cluster Options](#kubernetes-cluster-options) |
| **kubectl** | 1.35+ | Kubernetes command-line tool | [Install kubectl](https://kubernetes.io/docs/tasks/tools/) |
| **Kubernetes cluster** | 1.35+ (or 1.33/1.34 with the ImageVolume gate enabled) | Container orchestration platform | See [Cluster Options](#kubernetes-cluster-options) |

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.

Should we update changelog for the next release? This is a major capability change.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good call — added an [Unreleased] › Major Features entry to CHANGELOG.md in 1e51a62 describing the fail-fast ImageVolume capability check and the relaxed kubeVersion >= 1.33.0-0 floor.

- imagevolume.go: log the error value directly instead of err.Error() so
  structured logging is preserved (Copilot review).
- Chart.yaml: reword the kubeVersion comment; ImageVolume existed as alpha
  in 1.31/1.32 rather than being entirely absent (Copilot review).
- before-you-start.md: bump the minimum kubectl to 1.34+, the earliest
  version supported within one minor of the 1.35 baseline (Copilot review).
- CHANGELOG.md: add an Unreleased entry for the fail-fast ImageVolume
  capability check (maintainer request).

Co-authored-by: Copilot <[email protected]>
Copilot-Session: bb9586dd-7b58-4da3-8375-ebc7d44cccf1
Signed-off-by: Wenting Wu <[email protected]>
@WentingWu666666
WentingWu666666 merged commit e569542 into documentdb:main Jul 30, 2026
102 of 103 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update go code test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Block DocumentDB creation when the ImageVolume feature is unavailable (fail fast via webhook)

5 participants