Skip to content

fix: upgrade documentdb_core before documentdb - #507

Merged
WentingWu666666 merged 5 commits into
documentdb:mainfrom
WentingWu666666:developer/wentingwu/issue-501-extension-dependency-upgrade
Nov 13, 2026
Merged

WentingWu666666 merged 5 commits into
documentdb:mainfrom
WentingWu666666:developer/wentingwu/issue-501-extension-dependency-upgrade

Conversation

@WentingWu666666

@WentingWu666666 WentingWu666666 commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Addresses #501 for future engine upgrades.

  • In ExtensionUpdateSQL, when the extension is documentdb, upgrade its fixed dependency documentdb_core first in one transaction.
  • auto uses each extension’s packaged default; an explicit schema version is applied to both extensions.
  • The reconciler is unchanged. No dependency configuration or generic dependency handling; other extensions retain their existing standalone SQL.
  • Existing schema-version gates and two-phase behavior are unchanged. Existing-mismatch repair is deferred.

Coverage and validation

  • SQL-helper tests cover default and explicit DocumentDB upgrades and standalone core upgrades; existing tests retain quoting and other-product coverage.
  • Controller tests assert core-first transactional SQL, including an explicit target below the binary version.
  • Passed: targeted tests and vet for internal/cnpg, internal/engine, internal/controller, and pkg/core; change-scoped lint with GODEBUG=gotypesalias=1.
  • E2E assertions read both installed extension versions. E2E compilation and vet passed; cluster E2E tests were not run.
  • Full repository lint has existing deprecation findings.

Upgrade co-versioned dependencies first in a single transaction and repair existing mismatches when schema upgrades are authorized. Preserve two-phase behavior and leave independently versioned extensions unmanaged.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 251a6aad-1c9b-4e75-9768-1d79b8eb8a7f
Signed-off-by: Wenting Wu <[email protected]>
@documentdb-triage-tool documentdb-triage-tool Bot added documentation Improvements or additions to documentation go Pull requests that update go code test labels Nov 11, 2026
@documentdb-triage-tool

Copy link
Copy Markdown

🤖 Auto-triaged by documentdb-triage-tool.

Applied: go, test, documentation
Project fields suggested: Component controllers · Priority P2 · Effort L · Status In Progress
Confidence: 0.95 (deterministic)

Reasoning

component from path globs (controllers, test, docs); effort from diff stats (330+34 LOC, 9 files)

If a label is wrong, ping @patty-chow so the rules can be tuned. Issues with component labels are left alone; PR component labels are reconciled from changed paths on every run.

wentingwu000 and others added 2 commits November 11, 2026 15:48
Limit the fix to upgrading documentdb_core before documentdb in the existing upgrade transaction. Remove dependency prechecks and existing-mismatch repair while retaining same-target upgrades, existing schema gates, and focused regression coverage.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 251a6aad-1c9b-4e75-9768-1d79b8eb8a7f
Signed-off-by: Wenting Wu <[email protected]>
Remove ExtensionDependencies and use the fixed documentdb-to-documentdb_core relationship only when the main extension is documentdb. Keep both upgrades in the same transaction and leave other products unchanged.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 251a6aad-1c9b-4e75-9768-1d79b8eb8a7f
Signed-off-by: Wenting Wu <[email protected]>
@WentingWu666666 WentingWu666666 changed the title fix: upgrade documentdb_core alongside documentdb fix: upgrade documentdb_core before documentdb Nov 11, 2026
wentingwu000 and others added 2 commits November 11, 2026 15:55
Remove the duplicate primary-pod listing found during self-review and use the existing CNPG helper with explicit missing-primary handling.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 251a6aad-1c9b-4e75-9768-1d79b8eb8a7f
Signed-off-by: Wenting Wu <[email protected]>
Move the fixed core-first transaction into ExtensionUpdateSQL and restore the reconciler unchanged. Auto upgrades use each packaged default; explicit upgrades use the same requested target for both extensions. Preserve standalone SQL for other extensions.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 251a6aad-1c9b-4e75-9768-1d79b8eb8a7f
Signed-off-by: Wenting Wu <[email protected]>
@WentingWu666666
WentingWu666666 marked this pull request as ready for review November 11, 2026 21:06
Copilot AI balanced review requested due to automatic review settings November 11, 2026 21:06

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.

🔵 Needs a closer look

Irreversible extension migrations lack cluster E2E validation of core-first upgrades and transaction rollback on failure against packaged old/new engine images.

No open issues 🎉

What changed in this PR

Updates DocumentDB schema upgrades to upgrade documentdb_core before documentdb in one transaction, without changing reconciliation gates or other products’ upgrade behavior.

Changes:

  • Applies explicit schema targets to both extensions; automatic upgrades use each extension’s packaged default.
  • Adds SQL and controller assertions for core-first upgrades, plus end-to-end checks of both installed versions.
  • Documents the behavior and the deferred repair of existing version mismatches.
File Description
test/​e2e/​tests/​upgrade/​upgrade_schema_test.go Checks both extension versions after finalizing an upgrade.
test/​e2e/​tests/​upgrade/​upgrade_schema_auto_test.go Checks both extension versions after an automatic upgrade.
test/​e2e/​tests/​upgrade/​helpers_test.go Adds primary-pod lookup and requires installed extension versions to agree.
operator/​src/​pkg/​core/​core.go Documents transactional, core-first upgrade behavior.
operator/​src/​internal/​product/​documentdb.go Defines the DocumentDB core extension name.
operator/​src/​internal/​controller/​documentdb_controller_test.go Verifies transactional SQL and explicit targets below the binary version.
operator/​src/​internal/​cnpg/​extension_sql.go Generates core-first transactional SQL for DocumentDB upgrades.
operator/​src/​internal/​cnpg/​extension_sql_test.go Covers default, explicit, and standalone extension upgrades.
docs/​designs/​product-neutral-core.md Explains upgrade semantics and mismatch-repair limitations.

Review effort: Balanced

@hossain-rayhan

Copy link
Copy Markdown
Collaborator

Verification on a local kind cluster

I tested on kind (Kubernetes 1.35, cert-manager 1.19.6) using the reproduction from #501 in ImageVolume mode, upgrading the engine from 0.117.0 to 1.0.0. The PR operator was built from a337827.

Cluster Operator documentdb documentdb_core status.schemaVersion
explicit schemaVersion: "1.0.0" 1.1.1 (current release) 1.0-0 ❌ 0.117-0 1.0.0
explicit schemaVersion: "1.0.0" this PR 1.0-0 ✅ 1.0-0 1.0.0
schemaVersion: "auto" this PR 1.0-0 ✅ 1.0-0 1.0.0
  • Two-phase mode is unchanged. After the binary moved to 1.0.0, both extensions stayed at 0.117-0 and the operator raised SchemaUpdateAvailable. Both moved to 1.0-0 only after spec.schemaVersion was set.
  • The upgrade is all-or-nothing. I ran the generated SQL shape through psql -c, the same way the operator does: BEGIN; ALTER EXTENSION "documentdb_core" UPDATE TO '1.0-0'; ALTER EXTENSION "documentdb" UPDATE TO '9.9-0'; COMMIT;. The second statement failed, psql exited 1, and documentdb_core was rolled back to 0.117-0, so nothing is half-applied and the reconciler sees an error.
  • Unit tests: make test passes, and go vet is clean for the operator packages and test/e2e/tests/upgrade.

Remaining gaps vs. #501 (non-blocking)

  1. Clusters that are already mismatched aren't repaired. A cluster upgraded with operator ≤ 1.1.1 keeps documentdb_core at the old version while status.schemaVersion reports the new one. It catches up at the next engine upgrade, when the core update runs. Until then, this fixes it (verified):
    ALTER EXTENSION documentdb_core UPDATE;
    Suggest keeping Engine upgrade doesn't update the documentdb_core extension #501 open, or posting this workaround there and in the upgrade docs.
  2. The E2E check probably won't run in CI. The new assertions are in the generic schema-upgrade specs, which run only when the E2E_UPGRADE_*_DOCUMENTDB_* variables are set (they were empty in recent CI runs). The combined-mode engine-upgrade check requested in Engine upgrade doesn't update the documentdb_core extension #501 isn't added.
  3. The dependency is hard-coded. documentdb_core is handled by name in ExtensionUpdateSQL rather than through the product profile, as Engine upgrade doesn't update the documentdb_core extension #501 suggested. That's fine for DocumentDB, but other products with dependent extensions won't get the same handling.

LGTM for the fix itself.

@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.

No new blocking findings at a337827.

Verified against packaged DocumentDB: an explicit 0.116-0 → 0.117-0 upgrade advances both extensions even with binary default 1.0-0; auto then advances both to 1.0-0. A failure in either statement returns nonzero from the single psql -c invocation, and a second-statement failure rolls back the core update. The inspected recent package defaults and upgrade edges agree between documentdb and documentdb_core.

Focused SQL/executor, engine/core, and controller upgrade tests passed; upgrade E2E compilation passed. No full cluster E2E run was performed in this review. The existing review already documents the CI execution gap and deferred repair of previously mismatched clusters.

@WentingWu666666
WentingWu666666 merged commit 15f82f5 into documentdb:main Nov 13, 2026
47 of 53 checks passed
hossain-rayhan added a commit to hossain-rayhan/documentdb-kubernetes-operator that referenced this pull request Nov 16, 2026
- Release date 2026-11-17.
- Add CHANGELOG entries for changes merged after the release PR was
  opened: OTel Collector outbound proxy (documentdb#476), documentdb_core upgraded
  with documentdb (documentdb#507), and stable documentation links and checks
  (documentdb#513, documentdb#514). documentdb#508 already added its own entry; documentdb#509 is internal.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 9f1a71b4-9969-4456-9f65-8d19dd550d8e
Signed-off-by: Rayhan Hossain <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation go Pull requests that update go code test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants