Skip to content

MM-68316: add builtin DB readiness check mode#459

Open
nickmisasi wants to merge 3 commits into
masterfrom
MM-68316
Open

MM-68316: add builtin DB readiness check mode#459
nickmisasi wants to merge 3 commits into
masterfrom
MM-68316

Conversation

@nickmisasi
Copy link
Copy Markdown
Contributor

@nickmisasi nickmisasi commented May 4, 2026

Summary

Adds an opt-in spec.database.readinessCheck.mode field on the Mattermost CR. When set to builtin, the operator builds the DB-readiness init container from the same Mattermost image as the main container and runs mattermost db ping --timeout=... instead of pulling postgres:13. The default (external / unset) preserves today's postgres:13 + pg_isready behaviour, so existing CRs are unaffected.

This unblocks air-gapped deployments that cannot mirror postgres:13 into their internal registry — they can now reuse the Mattermost image they already have. A future operator release will deprecate, then flip, the default once the Mattermost floor version ships mattermost db ping. Companion change: mattermost/mattermost MM-68316.

Ticket Link

Fixes https://mattermost.atlassian.net/browse/MM-68316

Documentation

Release Note

Added `spec.database.readinessCheck.mode=builtin` to use the main Mattermost image for the database readiness init container instead of postgres:13. Requires a Mattermost release that ships the `mattermost db ping` command.

Adds an opt-in `spec.database.readinessCheck.mode` field on the
Mattermost CR. When set to "builtin", the operator constructs the
DB-readiness init container from the same Mattermost image as the
main container and runs `mattermost db ping --timeout=...` instead
of pulling postgres:13. The default ("external"/unset) preserves
today's postgres:13 + pg_isready behaviour.

This unblocks air-gapped deployments that cannot mirror postgres:13
into their internal registry. A future operator release will
deprecate and eventually flip the default once the Mattermost floor
version ships `mattermost db ping`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@mm-cloud-bot
Copy link
Copy Markdown

@nickmisasi: Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

I understand the commands that are listed here

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 4, 2026

📝 Walkthrough

Walkthrough

Adds configurable database readiness checks: new DatabaseReadinessCheck type (Mode: external|builtin, optional Timeout), CRD/schema updates, deepcopy support, init-container selection for builtin (in-image mattermost db ping) vs external checks, and corresponding tests and docs updates.

Changes

Database Readiness Check

Layer / File(s) Summary
Type Definition & Schema
apis/mattermost/v1beta1/mattermost_types.go, config/crd/bases/installation.mattermost.com_mattermosts.yaml
Adds ReadinessCheck *DatabaseReadinessCheck to Database; new DatabaseReadinessCheck type with Mode enum (external,builtin) and optional Timeout. CRD schema adds spec.database.operatorManaged.readinessCheck with enum and duration pattern.
Deep Copy Support
apis/mattermost/v1beta1/zz_generated.deepcopy.go
Autogenerated DeepCopyInto/DeepCopy for DatabaseReadinessCheck; Database.DeepCopyInto updated to deep-copy ReadinessCheck and its metav1.Duration timeout.
Implementation: init containers
pkg/mattermost/database_external.go
Introduces defaultBuiltinReadinessTimeout, dispatcher getDBCheckInitContainer honoring ReadinessCheck.Mode and timeout, adds builtinDBCheckInitContainer which uses the Mattermost image to run /mattermost/bin/mattermost db ping --timeout=<duration>. External-mode path preserved.
Integration: deployment wiring
pkg/mattermost/mattermost.go
When DB is external, use the external-only init-container helper (externalDBCheckInitContainer) for v1alpha1 compatibility; comments clarify v1alpha1 vs v1beta1 behavior.
Tests
pkg/mattermost/database_external_test.go, pkg/mattermost/mattermost_v1beta_test.go
Adds tests for builtin mode (TestGetDBCheckInitContainer_BuiltinMode) and ExternalDBConfig init-container behavior in builtin vs external modes; updates existing tests for new call signatures and cases.
Docs / CRD docs
docs/mattermost_v1beta1_crd.md
Updates CRD documentation and many field validations to mark optional fields; documents DatabaseReadinessCheck.mode enum and timeout optionality.
Minor CRD text fix
config/crd/bases/installation.mattermost.com_mattermosts.yaml
Fixes typo in spec.jobServer.dedicatedJobServer description (“recieve” → “receive”).

Sequence Diagram

sequenceDiagram
    participant Operator as Operator / Controller
    participant Spec as Mattermost Spec
    participant Secret as DB Secret
    participant Pod as Deployment / Pod
    participant Init as Init Container
    participant DB as Database

    Operator->>Spec: Read spec.database.readinessCheck.mode
    alt mode == "builtin"
        Operator->>Secret: Read MM_CONFIG and datasource
        Operator->>Pod: Create init container using Mattermost image
        Pod->>Init: Start /mattermost/bin/mattermost db ping --timeout=<duration>
        Init->>DB: Connect and ping database
    else mode == "external" or unset
        Operator->>Secret: Check DB_CONNECTION_CHECK_URL
        alt DB_CONNECTION_CHECK_URL present
            Operator->>Pod: Create external readiness-check init container
            Pod->>Init: Run external check image
            Init->>DB: Check via URL
        else DB_CONNECTION_CHECK_URL absent
            Operator->>Pod: Do not add readiness-check init container
        end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding a builtin mode for database readiness checks, which aligns with the core objective of the PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The pull request description clearly relates to the changeset, explaining the addition of an opt-in database readiness check mode feature.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch MM-68316

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@config/crd/bases/installation.mattermost.com_mattermosts.yaml`:
- Around line 247-253: Add a validation schema for readinessCheck.timeout so
invalid duration strings are rejected at CRD validation time: update the CRD's
schema for the readinessCheck object (the readinessCheck.timeout property) to
include a validation pattern (regex) and/or minLength that matches the expected
Kubernetes duration format (e.g., number+unit like "5m", "30s", "1h") and set
type: string; this will ensure invalid values are rejected by the API server
instead of failing later during reconciliation. Reference the
readinessCheck.timeout property in the CRD schema and add the pattern constraint
and an appropriate description update.

In `@docs/mattermost_v1beta1_crd.md`:
- Line 232: Fix the typo in the CRD docs for the `dedicatedJobServer` field by
replacing "recieve" with the correct spelling "receive" in the description text
for `dedicatedJobServer` in docs/mattermost_v1beta1_crd.md (look for the table
row containing `dedicatedJobServer` and the phrase "will recieve no user
traffic"). Ensure the updated sentence reads "will receive no user traffic"
exactly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1cb4ca0d-1d4b-497d-a4c2-46c1f9d4e615

📥 Commits

Reviewing files that changed from the base of the PR and between 95f6b8a and 3fd33cb.

📒 Files selected for processing (9)
  • apis/mattermost/v1beta1/mattermost_types.go
  • apis/mattermost/v1beta1/zz_generated.deepcopy.go
  • config/crd/bases/installation.mattermost.com_mattermosts.yaml
  • docs/mattermost-operator/mattermost-operator.yaml
  • docs/mattermost_v1beta1_crd.md
  • pkg/mattermost/database_external.go
  • pkg/mattermost/database_external_test.go
  • pkg/mattermost/mattermost.go
  • pkg/mattermost/mattermost_v1beta_test.go

Comment thread config/crd/bases/installation.mattermost.com_mattermosts.yaml
Comment thread docs/mattermost_v1beta1_crd.md Outdated
- Add kubebuilder pattern validation to readinessCheck.timeout so invalid
  duration strings are rejected at CRD admission rather than at reconcile
  time.
- Fix "recieve" -> "receive" typo in JobServer.DedicatedJobServer godoc;
  regenerated CRD docs and bundled YAMLs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@mm-cloud-bot mm-cloud-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed labels May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note Denotes a PR that will be considered when it comes time to generate release notes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants