Feature/kubebuilder style versioning#27
Conversation
|
It looks like some of the main README documentation needs to be updated like the quickstart before merging. |
|
A couple of notes testing this PR at this commit: I went through the basic CRUD example and the basics seemed to work like expected and I'm able to add multiple versions of the API with Here's the ./client device create --spec '{
"description": "Core network switch",
"ipAddress": "192.168.1.10",
"location": "DataCenter A",
"rack": "R42"
}'
{
"apiVersion": "v1",
"kind": "Device",
"metadata": {
"name": "",
"uid": "device-f260b82a",
"createdAt": "2026-01-06T14:03:30.424022558-07:00",
"updatedAt": "2026-01-06T14:03:30.424022558-07:00"
},
"spec": {
"description": "Core network switch",
"ipAddress": "192.168.1.10",
"location": "DataCenter A",
"rack": "R42"
},
"status": {
"ready": false
}
}And the corresponding type DeviceSpec struct {
Description string `json:"description,omitempty" validate:"max=200"`
IPAddress string `json:"ipAddress,omitempty" validate:"omitempty,ip"`
Location string `json:"location,omitempty"`
Rack string `json:"rack,omitempty"`
}Here's the command again, but specifying the ./client device create --spec '{
"description": "Core network switch",
"ipAddress": "192.168.1.10",
"location": "DataCenter A",
"rack": "R42"
}' --version v2
{
"apiVersion": "v1",
"kind": "Device",
"metadata": {
"name": "",
"uid": "device-1ab74b62",
"createdAt": "2026-01-06T14:03:44.894932171-07:00",
"updatedAt": "2026-01-06T14:03:44.894932171-07:00"
},
"spec": {
"description": "Core network switch",
"ipAddress": "192.168.1.10",
"location": "DataCenter A",
"rack": "R42"
},
"status": {
"ready": false
}
}Here's the type DeviceSpec struct {
Description string `json:"description,omitempty" validate:"max=200"`
}I made sure to run I'm guessing that some of this field validation should probably be handled in I built the binary using I also had to add Edit 1: I noticed running fabrica add resource Device --version v1
Error: adding resource to non-alpha version v1 requires --force flag
Stable versions should not have new resources added after release.
Use --force if you understand the implications, or consider adding to an alpha version first.
Usage:
fabrica add resource [name] [flags]
Flags:
--force Force adding to non-alpha version
-h, --help help for resource
--package string Package name (defaults to lowercase resource name)
--version string API version (required for versioned projects, e.g., v1alpha1)
--with-status Include Status struct (default true)
--with-validation Include validation tags (default true)
--with-versioning Enable per-resource spec versioning (snapshots). Status is never versioned.
adding resource to non-alpha version v1 requires --force flag
Stable versions should not have new resources added after release.
Use --force if you understand the implications, or consider adding to an alpha version first.The cat apis.yaml
groups:
- name: example.fabrica.dev
storageVersion: v1
versions:
- v1Removing the |
|
From a usability standpoint, I find it a bit annoying and tedious having to list and then delete all of my devices individually with The current way looks something like this to delete multiple devices. ./client device list
# ...show list of devices...
./client device delete device-0fc0a34f
Device device-0fc0a34f deleted successfully
# ...scroll back up or run './client device list' again
./client device delete device-71ea3e92
Device device-71ea3e92 deleted successfully
# ...repeat...
./client device delete device-a305f539
Device device-a305f539 deleted successfully
# ...repeat...
./client device delete device-a9fc4c25
Device device-a9fc4c25 deleted successfully
# ...repeat...
./client device delete device-fa6b7ef7
Device device-fa6b7ef7 deleted successfully |
| storage_version: v1 | ||
| versions: | ||
| - v1 | ||
| resources: [] |
There was a problem hiding this comment.
Nitpick, but groups.resources was not generated with the above command.
|
I'm going to go ahead and resolve the documentation format issues for now and fix them in a future PR. |
|
Getting a device requires the UID in the URL params instead of the name like in the documentation. This command needs to be updated in API versioning example. Likewise, the delete example needs to be update to use the UID as well. For example, create a device. curl -X POST http://localhost:8080/devices \
-H "Content-Type: application/json" \
-d @data.jsonThis will give this output. Notice that the {"apiVersion":"v1","kind":"Device","metadata":{"name":"device-1","uid":"device-9e44d386","createdAt":"2026-01-16T14:57:15.816284969-07:00","updatedAt":"2026-01-16T14:57:15.816284969-07:00"},"spec":{"ipAddress":"192.168.1.100","location":"DataCenter A","deviceType":"server","tags":{"env":"prod"}},"status":{"ready":false}}With curl http://localhost:8080/devices/device-1
# ...
{"error":"Device not found: failed to load Device device-1: resource not found","code":404}With curl http://localhost:8080/devices/device-9e44d386
# ...
{"apiVersion":"v1","kind":"Device","metadata":{"name":"device-1","uid":"device-9e44d386","createdAt":"2026-01-16T14:57:15.816284969-07:00","updatedAt":"2026-01-16T14:57:15.816284969-07:00"},"spec":{"ipAddress":"192.168.1.100","location":"DataCenter A","deviceType":"server","tags":{"env":"prod"}},"status":{"ready":false}} |
|
I'm able to create a device with an arbitrary curl -X POST http://localhost:8080/devices \
-H "Content-Type: application/json" \
-d '{
"apiVersion": "infra.example.io/v2asdasda",
"kind": "Device",
"metadata": {"name": "device-100"},
"spec": {
"ipAddress": "192.168.1.100",
"location": "DataCenter A",
"deviceType": "server",
"tags": {"env": "prod"}
}
}'And the output: {"apiVersion":"v1","kind":"Device","metadata":{"name":"device-100","uid":"device-2e57421b","createdAt":"2026-01-20T13:20:23.289968826-07:00","updatedAt":"2026-01-20T13:20:23.289968826-07:00"},"spec":{"ipAddress":"192.168.1.100","location":"DataCenter A","deviceType":"server","tags":{"env":"prod"}},"status":{"ready":false}}I have a spec for both |
e4904c1 to
11117fb
Compare
d97a199 to
377500f
Compare
davidallendj
left a comment
There was a problem hiding this comment.
LGTM. Tried, tested, and worked like expected.
Add core infrastructure for hub/spoke API versioning: - pkg/apiversion: Registry for API groups and versions, Hub/Convertible interfaces - pkg/imports/catalog: Type metadata resolution for external imports These packages provide the runtime infrastructure needed for version negotiation and automatic conversion between hub (storage) and spoke (external) API versions. Part of: Hub/Spoke API Versioning feature Signed-off-by: Alex Lovell-Troy <alex@lovelltroy.org> Signed-off-by: David Allen <davidallendj@gmail.com>
Add code generation templates for hub/spoke versioning: - Hub (storage) version types with flattened envelopes - Spoke (external) version types with conversion functions - Version registry initialization Integrate into generator: - Load apiversion templates in LoadTemplates() - Implement GenerateAPIVersions() method with placeholder - Wire into GenerateAll() flow after models generation Templates generate explicit APIVersion, Kind, Metadata, Spec, Status fields instead of embedding resource.Resource, improving Go autodoc and navigation. Part of: Hub/Spoke API Versioning feature Signed-off-by: Alex Lovell-Troy <alex@lovelltroy.org> Signed-off-by: David Allen <davidallendj@gmail.com>
Add configuration support for hub/spoke API versioning: - APIsConfig struct with APIGroup, APIResource definitions - Field mapping structs for version-specific transformations - Import support for external type references - LoadAPIsConfig() function to read apis.yaml - ValidateAPIsConfig() with comprehensive validation rules Validation ensures: - At least one API group defined - Group name and storageVersion required - storageVersion must be in versions list - Versions list not empty This enables projects to declare multiple API versions via apis.yaml configuration file, supporting hub/spoke versioning pattern. Part of: Hub/Spoke API Versioning feature Signed-off-by: Alex Lovell-Troy <alex@lovelltroy.org> Signed-off-by: David Allen <davidallendj@gmail.com>
Add comprehensive documentation for hub/spoke API versioning: Documentation: - docs/versioning.md: Complete guide (400+ lines) covering model, usage, migration path, and best practices - README.md: Updated with versioning feature in Key Features - CHANGELOG.md: Documented breaking change (flattened envelope) - examples/README.md: Added "What's New in v0.4" section - examples/01-basic-crud/README.md: Added versioning migration note New Example: - examples/08-api-versioning: Complete walkthrough demonstrating hub/spoke versioning with v1alpha1, v1beta1, v1 versions - apis.yaml.example: Configuration template for multi-version APIs Integration Tests: - test/integration/versioning_test.go: 5 comprehensive test cases - Flattened envelope structure validation - apis.yaml placeholder functionality - Backward compatibility verification - Config validation - JSON format compatibility BREAKING CHANGE: Generated resource types now use flattened envelope structure with explicit APIVersion, Kind, Metadata, Spec, Status fields instead of embedding resource.Resource. JSON wire format unchanged. Migration guide: docs/versioning.md#migration-from-pre-flattening Part of: Hub/Spoke API Versioning feature Signed-off-by: Alex Lovell-Troy <alex@lovelltroy.org> Signed-off-by: David Allen <davidallendj@gmail.com>
…adata - Eliminate pkg/resources/ and apis/ redundancy in versioned mode - Merge apis.yaml into .fabrica.yaml (single config) - Add fabrica.Metadata type alias for cleaner imports - New commands: `fabrica add version`, versioned `fabrica init` - Generator discovers resources from apis/<group>/<storage-version>/ - Complete example 8 rewrite with working project structure - Flattened envelope: explicit APIVersion, Kind, Metadata fields Breaking: Versioned projects now define types directly, no generation Signed-off-by: Alex Lovell-Troy <alex@lovelltroy.org> Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: Alex Lovell-Troy <alex@lovelltroy.org> Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: Alex Lovell-Troy <alex@lovelltroy.org> Signed-off-by: David Allen <davidallendj@gmail.com>
- Deleted go.sum.license and storage.go files as they are no longer needed. - Enhanced code generation to support versioned projects by introducing a new `IsVersioned` flag. - Updated handler templates to differentiate between versioned and legacy modes for resource creation, updates, and deletions. - Added resource prefix registration to ensure proper UID generation for versioned resources. - Improved event publishing logic to accommodate versioned resources. Signed-off-by: Alex Lovell-Troy <alovelltroy@lanl.gov> Signed-off-by: David Allen <davidallendj@gmail.com>
…validation Signed-off-by: Alex Lovell-Troy <alovelltroy@lanl.gov> Signed-off-by: David Allen <davidallendj@gmail.com>
…initialization Signed-off-by: Alex Lovell-Troy <alovelltroy@lanl.gov> Signed-off-by: David Allen <davidallendj@gmail.com>
…rce management - Updated README.md to include a Quickstart guide and improved navigation links. - Refined usage instructions in USAGE.md for initializing projects with custom API groups. - Improved error messages in add.go for better clarity on versioning and resource addition. - Removed unnecessary versioning configuration from config.go. - Enhanced generate.go to check for existing generated handler files before performing version checks. - Updated init.go to provide clearer next steps for users after project initialization. - Expanded quickstart.md with optional API versioning customization and detailed steps for resource addition. - Adjusted storage-ent.md to clarify migration steps for existing projects. - Revised codegen.md to reflect changes in resource discovery and registration. - Updated versioning.md with detailed steps for adding new API versions and managing resource evolution. - Modified examples to reflect new directory structure and resource definition locations. - Improved main.go.tmpl to clarify reconciliation controller initialization and registration of reconcilers. Signed-off-by: Alex Lovell-Troy <alovelltroy@lanl.gov> Signed-off-by: David Allen <davidallendj@gmail.com>
…adability Signed-off-by: Alex Lovell-Troy <alovelltroy@lanl.gov> Signed-off-by: David Allen <davidallendj@gmail.com>
…ioned projects Signed-off-by: Alex Lovell-Troy <alovelltroy@lanl.gov> Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: Alex Lovell-Troy <alovelltroy@lanl.gov> Signed-off-by: David Allen <davidallendj@gmail.com>
…move deprecated device_types.go Signed-off-by: Alex Lovell-Troy <alovelltroy@lanl.gov> Signed-off-by: David Allen <davidallendj@gmail.com>
- Introduced quick-start and test scripts for the Ent Advanced example. - Implemented export and import commands in the server for resource management. - Added templates for generating query builders and transaction support. - Enhanced README documentation for examples and usage instructions. - Updated code generation to include new export/import commands and helpers. Signed-off-by: Alex Lovell-Troy <alovelltroy@lanl.gov> Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: Alex Lovell-Troy <alovelltroy@lanl.gov> Signed-off-by: David Allen <davidallendj@gmail.com>
…s with validation functions Signed-off-by: Alex Lovell-Troy <alovelltroy@lanl.gov> Signed-off-by: David Allen <davidallendj@gmail.com>
…versioning commands; add export/import integration tests Signed-off-by: Alex Lovell-Troy <alovelltroy@lanl.gov> Signed-off-by: David Allen <davidallendj@gmail.com>
…structure - Updated code generation documentation to reflect the transition from embedding `resource.Resource` to using a flattened envelope structure with explicit `APIVersion`, `Kind`, `Metadata`, `Spec`, and `Status` fields. - Revised status subresource documentation to import `fabrica.Condition` instead of `resource.Condition`. - Adjusted versioning documentation to redirect to the consolidated guide and removed deprecated content. - Modified examples to reference the new API structure and updated file paths accordingly. - Ensured all instances of `resource.Resource` are replaced with the new structure in example code. Signed-off-by: Alex Lovell-Troy <alovelltroy@lanl.gov> Signed-off-by: David Allen <davidallendj@gmail.com>
…mentation Signed-off-by: Alex Lovell-Troy <alovelltroy@lanl.gov> Signed-off-by: David Allen <davidallendj@gmail.com>
- Updated `export_import_test.go` to use Ent storage for project creation and adjusted assertions for file backend. - Enhanced `helpers.go` with server runtime management, including starting and stopping the server, and added HTTP call utilities. - Introduced `runtime_test.go` to validate generated API servers and client library functionality through runtime tests. - Created `test-lib.sh` for shared testing utilities, including HTTP request functions and validation checks. - Added `test_debug.sh` for manual testing and debugging of server functionality. Signed-off-by: Alex Lovell-Troy <alovelltroy@lanl.gov> Signed-off-by: David Allen <davidallendj@gmail.com>
…d update related documentation Signed-off-by: Alex Lovell-Troy <alovelltroy@lanl.gov> Signed-off-by: David Allen <davidallendj@gmail.com>
…metadata handling Signed-off-by: Alex Lovell-Troy <alovelltroy@lanl.gov> Signed-off-by: David Allen <davidallendj@gmail.com>
…metadata + spec) Signed-off-by: Alex Lovell-Troy <alovelltroy@lanl.gov> Signed-off-by: David Allen <davidallendj@gmail.com>
- Added new API definitions for Blade, BMC, Chassis, Node, Rack, and RackTemplate in the apis directory. - Updated README.md to reflect the new directory structure and added apis.yaml for API group/version configuration. - Refactored rack_reconciler to utilize new API types and updated resource creation logic. - Modified example commands in various README files to use the new server import/export commands. - Enhanced documentation to clarify the usage of apis.yaml and the versioning strategy. Signed-off-by: Alex Lovell-Troy <alex@lovelltroy.org> Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: Alex Lovell-Troy <alex@lovelltroy.org> Signed-off-by: David Allen <davidallendj@gmail.com>
…ning registration Signed-off-by: Alex Lovell-Troy <alex@lovelltroy.org> Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: Alex Lovell-Troy <alex@lovelltroy.org> Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: Alex Lovell-Troy <alex@lovelltroy.org> Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: Alex Lovell-Troy <alex@lovelltroy.org> Signed-off-by: David Allen <davidallendj@gmail.com>
- Create README.md for Example 09: Advanced Ent Storage Features, detailing query builders, transactions, and export/import capabilities. - Implement quick-start.sh script for automated setup of the Ent advanced example. - Add test-advanced.sh script to validate query builders, transactions, and export/import functionalities. - Create README.md for Example 10: Export/Import, outlining backup and restore workflows using generated server commands. - Update main examples README.md to include new examples and their descriptions. - Add copyright headers to middleware test file. Signed-off-by: Alex Lovell-Troy <alex@lovelltroy.org> Signed-off-by: David Allen <davidallendj@gmail.com>
…stency Signed-off-by: Alex Lovell-Troy <alex@lovelltroy.org> Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: Alex Lovell-Troy <alex@lovelltroy.org> Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
377500f to
cf4dddc
Compare
This pull request introduces a comprehensive hub/spoke API versioning system, major changes to the resource code generation flow, and updates to project configuration and documentation. The main focus is on enabling Kubebuilder-style API versioning, supporting automatic conversion between versions, and enforcing a new, explicit resource envelope structure. It also deprecates legacy, non-versioned resource management and updates legal metadata files for SPDX compliance.
API Versioning and Resource Generation:
Implements hub/spoke (Kubebuilder-style) API versioning:
apis.yamlconfiguration for managing groups, versions, and imports.apiVersion,kind,metadata,spec, andstatusfields, replacing the previous embeddedresource.Resourceapproach. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12]Updates the CLI:
Configuration and Validation:
.fabrica.yamlschema and validation:Documentation:
Legal and Metadata Updates:
.reuse/dep5with a new SPDX-compliantREUSE.tomlfile for better license tracking. [1] [2]Breaking Changes:
resource.Resource; any custom code referencing the embedded field must be updated to use explicit fields.References:
[1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] Fd5f02adL61R61, [14] [15] [16]
Checklist
make test(or equivalent) locally and all tests passgit commit -s) with my real name and emailDescription
Please include a summary of the change and which issue is fixed.
Also include relevant motivation and context.
Fixes #(issue)
Type of Change
For more info, see Contributing Guidelines.