Issue: rancher/rancher#49552. This commit significantly refactors `crd-swagger` to generate OpenAPI documentation beyond just user-provided CRD files. The tool can now document any Kubernetes resource type that is discoverable via the API server, including those exposed by Rancher's imperative API extension (via `imperative-api-extension` and Kubernetes API Aggregation). Key changes in the workflow: 1. **Input Method:** The tool no longer processes CRD YAML files directly. Instead, it accepts a list of target resources via the `--resources-file` flag. This file (local or URL) should contain `Kind.Group` identifiers (e.g., `RoleTemplate.management.cattle.io`, `Pod`). 2. **Environment Setup:** Starts a temporary Docker container using a Rancher image. This image bundles K3s, providing an immediate Kubernetes environment upon container startup. The tool then retrieves the Kubeconfig for this internal K3s cluster. 3. **API Discovery:** Using the fetched Kubeconfig, the tool connects to the K3s cluster and uses the Kubernetes Discovery API. It queries for the `Kind.Group`s specified in the input file to get their authoritative details (plural name, API version, namespaced scope). 4. **Filtering:** The full OpenAPI v2 spec is fetched from the K3s cluster. API paths and definitions are then filtered based on the details obtained from the Discovery API, matching against the structure of Kubernetes REST paths. This replaces the previous method of filtering based only on `x-kubernetes-group-version-kind` from input CRDs. Other changes: - Removed legacy logic for installing CRDs into the temporary cluster. - Updated CLI flags: `--files` is now `--resources-file`. - Revised README and usage examples to reflect the new workflow, input format, and CLI interface. - Improved logging and error handling related to input processing and API discovery. |
||
|---|---|---|
| .. | ||
| README.md | ||
| rancher-swagger.json | ||
| resources.sample.txt | ||
README.md
Example:
crd-swagger -f resources.sample.txt -o rancher-swagger.json