Skip to content

Commit 06d3943

Browse files
bzp2010kayx23
andauthored
docs: add ADC user documentation (#524)
* docs draft * docs: restructure ADC documentation (#530) * docs: limit root README changes * docs: address ADC review comments * docs: fix ADC built-in variable example --------- Co-authored-by: Traky Deng <trakydeng@gmail.com>
1 parent 2ad107f commit 06d3943

8 files changed

Lines changed: 1323 additions & 0 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ The `lint` command verifies the provided ADC configuration file locally.
100100
adc lint -f adc.yaml
101101
```
102102

103+
## Documentation
104+
105+
See the [`docs/`](docs/README.md) folder for the CLI command reference, configuration file reference, and a full ADC workflow guide.
106+
103107
## Development
104108

105109
To build ADC from source, [install Nx](https://nx.dev/getting-started/installation) and run:

docs/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# ADC Documentation
2+
3+
API Declarative CLI (ADC) manages Apache APISIX and API7 Enterprise configuration from local YAML or JSON files. Use it to export existing gateway configuration, review drift, validate proposed changes, and apply the desired state through the gateway Admin API.
4+
5+
Start with the workflow guide if you are setting up ADC for the first time. Use the reference pages when you need exact command flags, configuration fields, or OpenAPI conversion behavior.
6+
7+
## Get Started
8+
9+
- [Use ADC for Declarative Configuration](./guides/workflow.md): configure a backend, write an `adc.yaml` file, lint it, preview changes, sync it, and export backups.
10+
- [Resource IDs](./guides/resource-ids.md): understand how ADC matches local resources to remote resources, especially before adopting resources that were created outside ADC.
11+
- [Label Selector](./guides/label-selector.md): split ownership by labels so multiple teams or pipelines can manage one backend safely.
12+
13+
## Reference
14+
15+
- [CLI Command Reference](./reference/cli.md): commands, flags, backend options, and examples.
16+
- [Configuration Reference](./reference/configuration.md): ADC configuration file structure, variables, resource fields, and links to the generated schema.
17+
- [OpenAPI Converter Reference](./reference/openapi-converter.md): `adc convert openapi`, supported `x-adc-*` extensions, merge rules, and examples.
18+
19+
## Component Notes
20+
21+
These files describe implementation-specific behavior for ADC backends and converters:
22+
23+
- [Apache APISIX backend](../libs/backend-apisix/README.md)
24+
- [API7 Enterprise backend](../libs/backend-api7/README.md)
25+
- [OpenAPI converter](../libs/converter-openapi/README.md)

docs/guides/label-selector.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Label Selector
2+
3+
`--label-selector` scopes ADC operations to resources with matching labels. Use it when multiple teams, applications, or CI pipelines manage separate parts of the same backend.
4+
5+
Without a selector, `adc sync` reconciles all resources in the command scope. If team A and team B sync separate files to the same backend without partitioning, one team can accidentally delete the other team's resources. A selector prevents that by making each run see only its own labeled resources.
6+
7+
## Basic Usage
8+
9+
```bash
10+
adc sync -f team-a.yaml --label-selector team=a
11+
```
12+
13+
You can provide multiple labels in one flag or repeat the flag:
14+
15+
```bash
16+
adc sync -f catalog.yaml --label-selector team=catalog,env=prod
17+
adc sync -f catalog.yaml --label-selector team=catalog --label-selector env=prod
18+
```
19+
20+
Matching uses exact string equality. Multiple labels are combined with AND, so a resource must match every key-value pair to be included.
21+
22+
ADC does not support wildcards, OR expressions, or key-exists selectors. There is no `ADC_*` environment variable for label selectors; pass them as command-line flags.
23+
24+
## How Remote Filtering Works
25+
26+
For `dump`, and for the remote side of `diff` and `sync`, ADC filters remote resources by label.
27+
28+
Remote filtering applies to top-level resource collections that carry labels, such as:
29+
30+
- `services`
31+
- `consumers`
32+
- `consumer_groups`
33+
- `ssls`
34+
- other label-bearing top-level resource collections supported by the backend
35+
36+
Remote filtering does not apply to `global_rules` or `plugin_metadata`. These resources are keyed by plugin name and are treated as global configuration.
37+
38+
Filtering does not independently select nested resources. If a service matches the selector, its routes and stream routes are included with the service. If a consumer group matches the selector, its nested consumers are included with the group.
39+
40+
For API7 Enterprise, ADC passes label filters to the Admin API so the backend can filter matching top-level resources. For Apache APISIX, ADC fetches the remote configuration and applies the same label filtering client-side.
41+
42+
## How Local Label Injection Works
43+
44+
ADC also applies the selector to the local file. It merges the selector labels into each local top-level resource and selected nested resources. For `diff` and `sync`, this happens before ADC compares the local file with the backend. For `validate`, this happens before ADC sends the local resources for backend validation.
45+
46+
For example, this command:
47+
48+
```bash
49+
adc sync -f catalog.yaml --label-selector team=catalog
50+
```
51+
52+
turns a local service like this:
53+
54+
```yaml
55+
services:
56+
- name: catalog
57+
routes:
58+
- name: list-products
59+
uris:
60+
- /products
61+
```
62+
63+
into an in-memory configuration equivalent to:
64+
65+
```yaml
66+
services:
67+
- name: catalog
68+
labels:
69+
team: catalog
70+
routes:
71+
- name: list-products
72+
labels:
73+
team: catalog
74+
uris:
75+
- /products
76+
```
77+
78+
If the file already has the same label key, the selector value wins.
79+
80+
This behavior keeps future runs stable. Resources created under a selector remain visible to that selector, and nested resources do not produce repeated diffs just because the backend copy has labels added by an earlier sync.
81+
82+
## Share One Backend Across Teams
83+
84+
Team A and team B can manage separate files against the same backend:
85+
86+
```bash
87+
# Team A
88+
adc sync -f team-a.yaml --label-selector team=a
89+
90+
# Team B
91+
adc sync -f team-b.yaml --label-selector team=b
92+
```
93+
94+
Team A sees and reconciles only resources labeled `team=a`. Team B sees and reconciles only resources labeled `team=b`.
95+
96+
To inspect one partition:
97+
98+
```bash
99+
adc dump -o team-a.yaml --label-selector team=a
100+
```
101+
102+
## Important Limits
103+
104+
- Do not use label selectors to split ownership of routes inside one shared service. A service is the top-level unit for filtering, so its nested routes move with it.
105+
- Use `--gateway-group` for API7 Enterprise gateway group isolation. Use `--label-selector` when teams share a gateway group or when the backend is Apache APISIX.
106+
- Be careful with `global_rules` and `plugin_metadata`. They are global and are not filtered by label selector.
107+
108+
## Related
109+
110+
- [Resource IDs](./resource-ids.md)
111+
- [CLI Command Reference](../reference/cli.md#common-backend-options)

docs/guides/resource-ids.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Resource IDs
2+
3+
ADC matches local resources to remote resources by resource ID. Names are used to generate IDs only when an explicit `id` is not present in the local configuration.
4+
5+
This matters most when adopting resources that already exist on the backend. A resource created through a UI or Admin API may have a server-generated ID that does not match the ID ADC would derive from its name. If ADC cannot match the IDs, it treats the local resource and remote resource as different resources.
6+
7+
## Why IDs Matter
8+
9+
`adc sync` is a reconciliation operation. For each resource in scope, ADC compares the local desired state with the remote state and computes create, update, and delete events.
10+
11+
If an existing remote resource has ID `abc123`, but the local file describes a similar resource with generated ID `def456`, ADC does not treat that as an in-place update. It sees:
12+
13+
- one remote resource to delete
14+
- one local resource to create
15+
16+
Depending on the resource, that replacement can cause traffic disruption, break references that use the old ID, or create unnecessary audit history.
17+
18+
## Generated IDs
19+
20+
When no explicit `id` is set, ADC derives IDs deterministically.
21+
22+
| Resource type | Generated ID |
23+
| ------------------- | ----------------------------------------------- |
24+
| Consumer | `username` |
25+
| Global rule | Plugin name |
26+
| Plugin metadata | Plugin name |
27+
| Service | `sha1(name)` |
28+
| SSL | `sha1(snis.join(','))` |
29+
| Upstream | `sha1("<service-name>.<upstream-name>")` |
30+
| Route | `sha1("<service-name>.<route-name>")` |
31+
| Stream route | `sha1("<service-name>.<stream-route-name>")` |
32+
| Consumer credential | `sha1("<consumer-username>.<credential-name>")` |
33+
34+
For resources that ADC created and continues to manage, you normally do not need to write IDs by hand. ADC will generate the same ID from the same names on every run.
35+
36+
## Rename Behavior
37+
38+
If a resource uses a generated ID, renaming it changes the generated ID. ADC will treat that as deleting the old resource and creating a new one.
39+
40+
To rename a resource without changing its backend ID:
41+
42+
1. Export the resource with explicit IDs.
43+
2. Keep the `id` field in the file.
44+
3. Change the display name or resource name while preserving the `id`.
45+
4. Run `adc diff` and confirm the change is an update, not a delete and create.
46+
47+
## Adopt Existing Resources
48+
49+
Before pointing ADC at resources that were created outside ADC, export the current backend state with IDs:
50+
51+
```bash
52+
adc dump --with-id -o adc.yaml
53+
```
54+
55+
Then confirm that ADC sees no changes:
56+
57+
```bash
58+
adc diff -f adc.yaml
59+
```
60+
61+
If the diff is empty, commit the file and use it as the starting point for ADC-managed configuration.
62+
63+
Keep the exported `id` fields. Removing them later can cause ADC to fall back to generated IDs and replace the resources on the next sync.
64+
65+
## Related
66+
67+
- [Use ADC for Declarative Configuration](./workflow.md)
68+
- [CLI Command Reference](../reference/cli.md#adc-dump)
69+
- [Configuration Reference](../reference/configuration.md)

0 commit comments

Comments
 (0)