Skip to content

feat(config-dump): add --include/--exclude-resource-type flags#63

Open
shreemaan-abhishek wants to merge 1 commit into
masterfrom
feat/dump-resource-type-filters
Open

feat(config-dump): add --include/--exclude-resource-type flags#63
shreemaan-abhishek wants to merge 1 commit into
masterfrom
feat/dump-resource-type-filters

Conversation

@shreemaan-abhishek
Copy link
Copy Markdown
Contributor

@shreemaan-abhishek shreemaan-abhishek commented May 28, 2026

Summary

  • --include-resource-type and --exclude-resource-type (mutually exclusive, comma-separated) on a7 config dump.
  • Excluded endpoints are skipped entirely (no GET issued).
  • Refactor: FetchRemoteConfig now takes a *ResourceTypeFilter (nil = fetch all). diff and sync pass nil, preserving fetch-all behavior.

Part of the adc → a7 parity gap tracked in docs/adc-test-parity-plan.md.

Design note

When the user includes routes but not services, services are still fetched internally (the per-service route fetch requires service IDs for access-token auth) but stripped from the emitted ConfigFile so the output reflects the user's intent. Documented inline. Alternative was to error — happy to flip if you'd prefer.

Test plan

  • TestConfigDump_IncludeOnly_RoutesAndServices (other endpoints not registered; httpmock fails on stray calls)
  • TestConfigDump_ExcludeSSL_SkipsSSLEndpoint
  • TestConfigDump_IncludeAndExcludeBothSet_Errors
  • TestConfigDump_UnknownResourceType_Errors
  • go test ./pkg/... ./internal/... passes
  • go vet ./...; gofmt -l . clean
  • Smoke against a real API7 EE instance

Summary by CodeRabbit

  • New Features
    • Added resource-type filtering for configuration operations using --include-resource-type and --exclude-resource-type command flags.
    • Users can now selectively fetch specific API resource types (routes, services, consumers, SSL, global rules, stream routes, protos, secrets, plugin metadata) when syncing and dumping configurations.

Review Change Stack

Lets `a7 config dump` fetch a subset of resource types. The flags are
comma-separated and mutually exclusive; unknown types error out with
the list of valid names.

`FetchRemoteConfig` now takes a `*ResourceTypeFilter` (nil = fetch all)
so excluded endpoints are not even hit. When the user includes `routes`
but not `services`, services are still fetched internally (the per-
service route fetch requires service IDs) but stripped from the
emitted ConfigFile so output reflects the user's intent.

`diff` and `sync` continue to pass `nil`, preserving fetch-all behavior.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a9e5a31a-76a7-4a93-9876-e2864051161a

📥 Commits

Reviewing files that changed from the base of the PR and between d99f5fa and 042514d.

📒 Files selected for processing (5)
  • pkg/cmd/config/configutil/configutil.go
  • pkg/cmd/config/diff/diff.go
  • pkg/cmd/config/dump/dump.go
  • pkg/cmd/config/dump/dump_test.go
  • pkg/cmd/config/sync/sync.go

📝 Walkthrough

Walkthrough

This PR introduces a resource-type filtering mechanism that allows users to selectively fetch API7 EE resource categories instead of all resources. It adds validation and filtering logic to the config utility, exposes the feature through the dump command's CLI flags, and updates related commands to work with the new signature.

Changes

Config Resource-Type Filtering

Layer / File(s) Summary
Resource type filtering contracts and validation
pkg/cmd/config/configutil/configutil.go
Stable resource type identifier constants (ResourceTypeRoutes, ResourceTypeServices, etc.), ordered KnownResourceTypes list, ResourceTypeFilter type with NewResourceTypeFilter constructor that normalizes comma-separated inputs, enforces mutual exclusivity of include/exclude, and validates against known types; Includes method returns true for nil filter (include all) or when resource is in filter's include set.
FetchRemoteConfig filter integration
pkg/cmd/config/configutil/configutil.go
Updated FetchRemoteConfig signature adds optional *ResourceTypeFilter parameter; conditionally fetches routes, services, consumers, SSL, global rules, stream routes, protos, secrets, and plugin metadata based on filter; routes internally fetch services even when services are not explicitly included, but services are only emitted in returned ConfigFile when explicitly included.
Dump command resource-type filtering CLI and runtime wiring
pkg/cmd/config/dump/dump.go
Options struct gains IncludeResourceType and ExcludeResourceType slice fields; NewCmdDump registers --include-resource-type and --exclude-resource-type flags with mutual-exclusion semantics; dumpRun constructs a ResourceTypeFilter from options and returns cmdutil.FlagError on validation failure, then passes filter to FetchRemoteConfig.
Dump command filtering test coverage
pkg/cmd/config/dump/dump_test.go
Four new tests verify filtering behavior: include-only with routes,services returns only those resource sections; exclude SSL omits ssl section and never calls /apisix/admin/ssls endpoint; both include and exclude together produce error message with "mutually exclusive"; unknown resource type produces error mentioning the unknown value and at least one valid type.
Diff and sync command signature updates
pkg/cmd/config/diff/diff.go, pkg/cmd/config/sync/sync.go
Both diffRun and syncRun updated to pass nil as filter argument to FetchRemoteConfig, preserving existing fetch-all behavior while accommodating the new signature.

🎯 3 (Moderate) | ⏱️ ~20 minutes


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error, 1 warning)

Check name Status Explanation Resolution
Security Check ❌ Error Secret provider tokens exposed unredacted in dump output. RedactSecret() exists but not applied to secrets before serialization. Call api.RedactSecrets() on the secrets slice before returning in FetchRemoteConfig (line 360 of configutil.go).
E2e Test Quality Review ⚠️ Warning Missing E2E test: no test for routes-only inclusion where services are fetched internally but stripped from output, a documented critical scenario in FetchRemoteConfig. Add test with --include-resource-type routes (no services): verify services endpoint called, services omitted from output, routes included. Validates documented dependency handling.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding resource-type filtering flags to the config-dump command, which is the primary feature across all modified files.
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.
✨ 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 feat/dump-resource-type-filters

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

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

Actionable comments posted: 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant