Skip to content

Comments

Add runtime CRD validation for database-type-specific fields in controller#73

Closed
Copilot wants to merge 2 commits intomainfrom
copilot/add-crd-validations-controller
Closed

Add runtime CRD validation for database-type-specific fields in controller#73
Copilot wants to merge 2 commits intomainfrom
copilot/add-crd-validations-controller

Conversation

Copy link
Contributor

Copilot AI commented Feb 23, 2026

Description

Database CRD configs were not validated at the controller level, allowing Redis-specific fields (e.g. mode, rdb_path, invoke_save) to be set on non-Redis databases, and invalid mode values to be accepted for Redis.

Changes

  • internal/controller/database_validator.go — new file with two functions:
    • validateDatabaseConfig(dbType, config): enforces that Redis mode is copy or sync if set, and that Redis-only fields are not present on non-Redis database types
    • validateDatabaseRefs(ctx, backup): fetches each referenced Database CRD via the dynamic client and runs validateDatabaseConfig against its config
  • internal/controller/backup_controller.go — calls validateDatabaseRefs in both handleBackupCreate and handleBackupUpdate, after validateBackupSpec and before secret creation

Example: rejected configurations

# postgresql with a Redis-only field — rejected
type: postgresql
config:
  mode: copy       # ❌ field 'mode' is only valid for Redis databases, not for 'postgresql'

# redis with an invalid mode — rejected
type: redis
config:
  mode: dump       # ❌ redis 'mode' must be 'copy' or 'sync', got 'dump'
  • internal/controller/database_validator_test.go — 25 unit tests covering valid and invalid configs for all supported database types

Related Issues

Checklist

  • Your go code is formatted. Your IDE should do it automatically for you.
  • New configuration options are reflected in CRD validation, helm charts and sample manifests.
  • New functionality is covered by unit and/or e2e tests.
  • You have checked existing open PRs for possible overlay and referenced them.
Original prompt

This section details on the original issue you should resolve

<issue_title>Add crd validations in controller</issue_title>
<issue_description>In crds (e.g. database) some fields most be validated. For example for Redis mode field one of sync or copy is valid that should be checked in the controller. Or checking not to set mode for Postgresql which is a Redis field. etc.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: payamQorbanpour <25246658+payamQorbanpour@users.noreply.github.com>
Copilot AI changed the title [WIP] Add CRD validations in controller Add runtime CRD validation for database-type-specific fields in controller Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Add crd validations in controller

2 participants