Repository navigation
Add DocumentDB upgrade support with configurable PostgresImage and ImageVolume extensions - #208
Conversation
433e80d to
1e6c870
Compare
1e6c870 to
ed68947
Compare
006724a to
a61d520
Compare
5144126 to
d6db610
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces DocumentDB upgrade capabilities by adding support for configurable PostgreSQL and DocumentDB extension images, along with automated extension upgrade logic. The changes enable rolling upgrades of DocumentDB clusters with minimal downtime.
Changes:
- Adds
postgresImagefield to DocumentDB CRD spec for configurable Postgres base image selection - Adds
documentDBVersionfield to DocumentDB status to track the currently installed extension version - Implements automated extension upgrade logic that updates the extension image and runs
ALTER EXTENSIONwhen needed - Upgrades CNPG dependency from 0.26.1 to 0.27.0 to support ImageVolume-based extension loading
- Adds E2E upgrade tests that verify version transitions
- Removes DocumentDB image build from CI pipeline (now using external registry)
- Migrates certificate tests from testify to Ginkgo/Gomega for consistency
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| operator/src/api/preview/documentdb_types.go | Adds PostgresImage spec field and DocumentDBVersion status field to DocumentDB CRD |
| operator/src/config/crd/bases/documentdb.io_dbs.yaml | Updates CRD schema with new postgresImage and documentDBVersion fields |
| operator/documentdb-helm-chart/crds/documentdb.io_dbs.yaml | Mirrors CRD schema changes in Helm chart |
| operator/src/internal/cnpg/cnpg_cluster.go | Configures CNPG cluster with ImageVolume extensions and uses postgresImage from spec |
| operator/src/internal/controller/documentdb_controller.go | Adds upgrade logic with upgradeDocumentDBExtensionIfNeeded and updateExtensionImageIfNeeded functions, plus version parsing |
| operator/src/internal/controller/documentdb_controller_test.go | Comprehensive unit tests for upgrade logic using Ginkgo/Gomega |
| operator/src/internal/controller/certificate_controller_test.go | Extracts certificate tests into separate file, maintaining testify framework |
| operator/documentdb-helm-chart/Chart.yaml | Bumps CNPG dependency from 0.26.1 to 0.27.0 |
| .github/workflows/test-E2E.yml | Adds upgrade test scenario that patches image and verifies version transition |
| .github/workflows/test-integration.yml | Updates to use hardcoded DocumentDB image instead of version parameter |
| .github/workflows/test-backup-and-restore.yml | Removes unused documentdb_version input parameter |
| .github/workflows/test-build-and-package.yml | Removes DocumentDB image build step (now using external images) |
| .github/actions/setup-test-environment/action.yml | Enables ImageVolume feature gate in kind cluster config, upgrades to kind v0.31.0 with K8s v1.35.0 |
13fad47 to
d6db610
Compare
3ff7c9f to
7f944e6
Compare
…QLExecutor - Add SQLExecutor function field to DocumentDBReconciler for testability - Default to executeSQLCommand in SetupWithManager (zero production changes) - Replace 4 executeSQLCommand call sites with SQLExecutor - Add 8 new upgradeDocumentDBIfNeeded tests covering Steps 4-7: SQL error, unparseable output, empty installed version, versions match, rollback detection with warning event, successful ALTER EXTENSION, ALTER EXTENSION failure, invalid version comparison - Add CompareExtensionVersions error-path tests for invalid inputs Signed-off-by: Wenting Wu <[email protected]>
Add 11 new targeted tests for uncovered error paths: - detectImageVolumeSupport: ServerVersion error, unparseable minor - upgradeDocumentDBIfNeeded: CNPG patch error, gateway restart annotation patch error, updateImageStatus failures, status update failures - updateImageStatus: status update error - SetupWithManager: initialization with nil manager, SQLExecutor preservation Patch coverage improved from 82.2% to 91.5% (195/213 statements). Signed-off-by: Wenting Wu <[email protected]>
…for extension image check With ImageVolume (K8s >= 1.35), the extension image is mounted as a Kubernetes volume, not as an init container. Updated the pod image verification in upgrade and rollback steps to query the correct path. Signed-off-by: Wenting Wu <[email protected]>
0d137dc to
a900223
Compare
… relation error The find() and findOne() operations cause 'pruned relation' errors after extension upgrade due to gateway/extension version mismatch. Use countDocuments() which works correctly for verifying data persistence. Changes: - Replace find().toArray() with countDocuments() in all verification steps - Simplified assertions to check document count only - Affected steps: after upgrade, after extension rollback, after gateway rollback Signed-off-by: Wenting Wu <[email protected]>
a900223 to
7903cd5
Compare
4ed6cda to
f6f49de
Compare
…nt panic Signed-off-by: Wenting Wu <[email protected]>
f6f49de to
a2557da
Compare
|
My Copiot says:
In documentdb.io_dbs.yaml (line ~422):
This appears in the preferredDuringSchedulingIgnoredDuringExecution section of podAntiAffinity. This is a description [Question] Was this generated via make manifests or manually edited? If generated, this is fine — it's upstream 🟠 Major Issues
The function does up to 3 separate Status().Update() calls within a single reconcile pass:
Each call refetches via r.Get() at the top, but between the refetch and the later status updates, another reconcile or [Required] Consolidate into a single status update at the end of the function, or re-fetch the resource before each // Re-fetch before status update to get latest resourceVersion
In ImageVolume mode, documentdbImage is the extension image reference. In combined mode, it's used as spec.ImageName [Suggestion] Consider a config struct to bundle related parameters: type CnpgClusterConfig struct {
If the operator is running during a K8s version upgrade (unlikely but possible in-place upgrades), or in tests where [Suggestion] This is fine for now, but document this as a known limitation: the operator must be restarted after a K8s 🟡 Minor Issues
The function parses the psql tabular output by splitting on \n and |. This is brittle if:
[Suggestion] Consider using -t (tuples only) and -A (unaligned) flags in the SQL executor to get a simpler format, or
The diff shows changes to both operator/documentdb-helm-chart/crds/documentdb.io_dbs.yaml and [Question] Is the helm chart CRD manually maintained or copied from the generated one? If copied, it looks out of sync.
The new postgresImage field accepts any string. There's no validation that it's a valid container image reference, or [Suggestion] Add a webhook or at minimum a reconcile-time validation that warns if the image doesn't match expected
[Nitpick] This is fine for now, but ensure it gets a version number before the release cut.
strings.LastIndex(v, "-") means a version like "0.110-beta-0" would produce "0.110-beta.0" which is incorrect. The [Nitpick] Add a comment noting the expected input format. |
6e5674a to
6515c6c
Compare
1. Rename status.documentDBVersion to status.schemaVersion to clarify that this field represents the installed extension schema version (after ALTER EXTENSION UPDATE), not the image version. 2. Update postgresImage comment to be more generic: 'defaults to the last stable PostgreSQL version compatible with DocumentDB'. Signed-off-by: Wenting Wu <[email protected]>
665c4bc to
e1dcd11
Compare
This was generated via
Will add re-fetch before each Status().Update() call.
The
When combined mode is deprecated,
Added TODO comment to improve it in the future.
Already synced via make manifests
Currently there's no validation for any image fields:
Image validation could be added for all image fields in the future.
Will be versioned at release time.
Will add comment. |
Signed-off-by: Wenting Wu <[email protected]>
Summary
This PR introduces DocumentDB upgrade capabilities by adding a configurable
PostgresImagefield to the DocumentDB CRD and enabling ImageVolume-based extension loading through CNPG.Key Changes
CRD Updates
postgresImagefield to DocumentDB spec for configurable postgres image selectionschemaVersionstatus field to track the current versionCNPG Integration
LD_LIBRARY_PATHfor extension loadinginitdb: could not look up effective user ID 105: user does not existerrorsCI/CD Updates
ImageVolumefeature gate in kind cluster configurationTesting
documentdb_controller_test.go