Skip to content

feat(admin): make /configs/validate available in all modes#13220

Open
nic-6443 wants to merge 10 commits intoapache:masterfrom
nic-6443:feat/config-validate-all-modes
Open

feat(admin): make /configs/validate available in all modes#13220
nic-6443 wants to merge 10 commits intoapache:masterfrom
nic-6443:feat/config-validate-all-modes

Conversation

@nic-6443
Copy link
Copy Markdown
Member

@nic-6443 nic-6443 commented Apr 14, 2026

Description

The POST /apisix/admin/configs/validate endpoint currently only works in standalone (YAML) mode. This PR makes it available in etcd mode as well, so clients can perform batch configuration validation that includes plugin check_schema() advanced checks regardless of the deployment mode.

Changes

New module: apisix/admin/config_validate.lua
Extracts the shared validation logic (validate_configuration, check_conf, check_duplicate, validate handler) from standalone.lua into a reusable module.

Modified: apisix/admin/standalone.lua
Delegates to the new config_validate module, removing ~140 lines of duplicated code while keeping standalone-specific logic (get/update/head, patch_schema, config sync).

Modified: apisix/admin/init.lua
Registers POST /apisix/admin/configs/validate in the etcd mode route table, placed before the wildcard route for correct matching priority.

Response Format

Success (200): {}

Failure (400):

{
  "error_msg": "Configuration validation failed",
  "errors": [
    {
      "resource_type": "routes",
      "resource_id": "route-1",
      "index": 0,
      "error": "failed to check the configuration of plugin cors err: ..."
    }
  ]
}

Each error object includes resource_type, resource_id, index (0-based), and error (raw validator message).

Why

Clients using etcd mode (e.g., ADC adc lint, Ingress Controller, CI pipelines) had no way to perform server-side batch validation that includes advanced plugin checks (cross-field constraints, regex compilation, expression parsing, recursive sub-plugin validation, etc.). The static JSON Schema from the schema API does not cover these checks, leading to situations where local lint passes but server-side sync fails.

This endpoint accepts the same declarative config format as standalone mode and returns all validation errors at once (collect-all mode), making it suitable for lint-style workflows.

Extract batch configuration validation logic from standalone.lua into
a new shared module (admin/config_validate.lua) and register the
POST /apisix/admin/configs/validate endpoint for etcd mode as well.

Previously this endpoint was only available in standalone (yaml) mode.
Clients using etcd mode (e.g., ADC, Ingress Controller) had no way to
perform batch validation that includes plugin check_schema() advanced
checks (cross-field constraints, regex compilation, expression parsing,
recursive sub-plugin validation, etc.).

Changes:
- New module: apisix/admin/config_validate.lua
  Owns validate_configuration(), check_conf(), check_duplicate(), and
  the validate() HTTP handler. Shared by both standalone and etcd modes.
- standalone.lua: delegates to config_validate module, removing ~140
  lines of duplicated logic while keeping standalone-specific code
  (get/update/head, patch_schema, config sync).
- init.lua: registers POST /apisix/admin/configs/validate in the etcd
  mode route table, placed before the wildcard route for correct
  matching priority.
Copilot AI review requested due to automatic review settings April 14, 2026 03:13
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. enhancement New feature or request labels Apr 14, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Enables POST /apisix/admin/configs/validate in etcd mode (in addition to standalone/YAML mode) by extracting the shared batch-validation logic into a reusable module and wiring the route in the etcd-mode Admin API router.

Changes:

  • Add apisix/admin/config_validate.lua to host shared declarative-config validation logic (schema + plugin check_schema() checks, duplicate detection, collect-all errors).
  • Refactor apisix/admin/standalone.lua to delegate validation to the new module.
  • Register POST /apisix/admin/configs/validate in apisix/admin/init.lua so it works in etcd mode; add a new test suite.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
apisix/admin/config_validate.lua New shared module implementing request parsing + batch validation across resource types.
apisix/admin/standalone.lua Removes duplicated validation code and calls into config_validate.
apisix/admin/init.lua Adds the validate endpoint route to etcd-mode router (before wildcard).
t/admin/config-validate.t Adds coverage for the validate endpoint success/error scenarios.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Apr 14, 2026
- Wrap check_conf in pcall to prevent checker crashes from returning 500
- Change invalid request body log level from error to warn
- Fix cors test assertion to match actual error message
- Simplify mixed resource test to avoid fragile assumptions
TEST 12 and 16 receive 500 HTML instead of expected 400 JSON.
Added defensive pcall around json.decode in tests plus warn-level
debug logging to capture the actual response when status != 400.
Also added JSON-serializable guard in validate() handler.
The upstream schema 'type' field has no enum constraint (just string
with default 'roundrobin'), so 'invalid_type' passes validation.
Use 'chash' type with missing key to trigger a real validation error.
- Return {} on success instead of empty body
- Add resource_id field to error objects
- Remove redundant 'invalid X at index N' prefix from error messages
  (index is already a separate field in the error object)
- Update test assertions accordingly
Remove 'invalid X at index N, err: ' prefix from expected error messages
in both PUT /configs and POST /configs/validate tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants