Skip to content

Commit a078d90

Browse files
Refactor: Remove unused files and implement versioning support
- 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>
1 parent c471927 commit a078d90

File tree

17 files changed

+323
-1296
lines changed

17 files changed

+323
-1296
lines changed

cmd/fabrica/add.go

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -116,20 +116,19 @@ func runAddResource(resourceName string, opts *addOptions) error {
116116
if config.Features.Versioning.Enabled && len(config.Features.Versioning.Versions) > 0 {
117117
isVersioned = true
118118

119+
// Require group to be set for versioned projects
120+
if config.Features.Versioning.Group == "" {
121+
return fmt.Errorf("versioning is enabled but features.versioning.group is not set in .fabrica.yaml.\nPlease set the API group (e.g., 'infra.example.io') in your configuration")
122+
}
123+
119124
// Version is required for versioned projects
120125
if opts.version == "" {
121-
// Auto-select first alpha version
122-
for _, v := range config.Features.Versioning.Versions {
123-
if strings.Contains(v, "alpha") {
124-
opts.version = v
125-
fmt.Printf("No version specified, using first alpha version: %s\n", opts.version)
126-
break
127-
}
128-
}
129-
130-
// If no alpha version, require explicit version with --force
131-
if opts.version == "" {
132-
return fmt.Errorf("no --version specified and no alpha version found.\nPlease specify a version with --version (use --force to add to stable version)")
126+
// Auto-select storage version (hub) if no version specified
127+
if config.Features.Versioning.StorageVersion != "" {
128+
opts.version = config.Features.Versioning.StorageVersion
129+
fmt.Printf("No version specified, using storage hub version: %s\n", opts.version)
130+
} else {
131+
return fmt.Errorf("no --version specified and no storage_version configured.\nPlease specify a version with --version or set features.versioning.storage_version in .fabrica.yaml")
133132
}
134133
} else {
135134
// Validate version exists in config
@@ -152,12 +151,8 @@ func runAddResource(resourceName string, opts *addOptions) error {
152151

153152
targetDir = filepath.Join("apis", config.Features.Versioning.Group, opts.version)
154153
} else {
155-
// Legacy mode: pkg/resources/
156-
isVersioned = false
157-
if opts.packageName == "" {
158-
opts.packageName = strings.ToLower(resourceName)
159-
}
160-
targetDir = filepath.Join("pkg", "resources", opts.packageName)
154+
// Legacy mode is deprecated
155+
return fmt.Errorf("legacy mode (pkg/resources/) is deprecated.\nPlease enable versioning in .fabrica.yaml:\n\nfeatures:\n versioning:\n enabled: true\n group: your.api.group\n storage_version: v1\n versions:\n - v1")
161156
}
162157

163158
fmt.Printf("📦 Adding resource %s", resourceName)

cmd/fabrica/init.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ or by providing the name of an existing directory.`,
105105
opts.storageType = "ent"
106106
}
107107

108+
// If group is specified but no versions, default to storage version
109+
if opts.apiGroup != "" && len(opts.apiVersions) == 0 {
110+
opts.apiVersions = []string{opts.storageVersion}
111+
}
112+
108113
if opts.interactive {
109114
return runInteractiveInit(projectName, opts)
110115
}
@@ -511,7 +516,7 @@ func createFabricaConfig(targetDir string, opts *initOptions) error {
511516
ETagAlgorithm: "sha256",
512517
},
513518
Versioning: VersioningConfig{
514-
Enabled: len(opts.apiVersions) > 0, // Enable if versions specified
519+
Enabled: opts.apiGroup != "", // Enable if group specified
515520
Group: opts.apiGroup,
516521
StorageVersion: opts.storageVersion,
517522
Versions: opts.apiVersions,

examples/08-api-versioning/.fabrica.yaml

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)