-
Notifications
You must be signed in to change notification settings - Fork 17
ROSAENG-61801: feat: adding passthrough types /api/v1alpha1 #193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
cdoan1
wants to merge
13
commits into
openshift-online:main
from
cdoan1:ROSAENG-61801-passthrough-types
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
725085f
ROSAENG-62606: port codegen tools into hack/api-codegen/
cdoan1 6b123a7
ROSAENG-62606: harden codegen generators and update Go to 1.26.5
cdoan1 3de2745
ROSAENG-62606: fix passthrough loader FieldPrefix and typeToString
cdoan1 aff9b78
ROSAENG-61801: add passthrough types with markers and runtime libraries
cdoan1 86920bb
ROSAENG-61801: fix codegen-passthrough to resolve source via go.mod
cdoan1 fc70161
ROSAENG-61801: sort imports in passthrough-gen for deterministic output
cdoan1 ed73f2f
ROSAENG-61801: regenerate deepcopy for new passthrough and envelope t…
cdoan1 18f1b26
ROSAENG-61801: tidy hack/api-codegen go.mod dependencies
cdoan1 4e7544f
ROSAENG-61801: single source of truth for field_metadata.json
cdoan1 e505a6e
ROSAENG-61801: gitignore generated passthrough raw files
cdoan1 f6cf272
ROSAENG-61801: remove tracked passthrough raw file
cdoan1 d2defd4
ROSAENG-61801: scan passthrough types as root entries in marker-scanner
cdoan1 564560e
ROSAENG-61801: fix GOCACHE permission in operator Containerfile
cdoan1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # api-codegen | ||
|
|
||
|  | ||
|
|
||
| Build-time code generators for the ROSA Hyperfleet API. These tools scan Go types with markers and generate passthrough types, OpenAPI schemas, CRD variants, conversion functions, and field validation metadata. | ||
|
|
||
|
|
||
| ## Generators | ||
|
|
||
| | Command | Purpose | | ||
| |---------|---------| | ||
| | `passthrough-gen` | Generate passthrough struct types from HyperShift API types | | ||
| | `marker-scanner` | Extract `+hyperfleet:` marker metadata from Go types | | ||
| | `openapi-gen` | Generate OpenAPI schemas from annotated Go types | | ||
| | `conversion-gen` | Generate conversion functions between API versions | | ||
| | `crd-variants` | Produce CRD variants filtered by feature gates | | ||
| | `featuregate-info` | Emit feature gate metadata for CRD fields | | ||
| | `verify-configuration` | Validate marker consistency across types | | ||
|
|
||
| ## Usage | ||
|
|
||
| ```bash | ||
| make build-api-codegen # Build all 7 generator binaries | ||
| make test-api-codegen # Run tests | ||
| make coverage-api-codegen # Generate coverage report | ||
| ``` | ||
|
|
||
| ## Reference | ||
|
|
||
| [api-management](./docs/api/api-management.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "flag" | ||
| "fmt" | ||
| "log" | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
|
|
||
| "github.com/openshift-online/rosa-hyperfleet-api/hack/api-codegen/pkg/conversion" | ||
| ) | ||
|
|
||
| func main() { | ||
| var ( | ||
| apiVersion string | ||
| crdPackage string | ||
| inputDirs string | ||
| outputDir string | ||
| ) | ||
|
|
||
| flag.StringVar(&apiVersion, "api-version", "v1alpha1", "API version to generate for") | ||
| flag.StringVar(&crdPackage, "crd-package", "", "Import path to CRD types (required)") | ||
| flag.StringVar(&inputDirs, "input-dirs", "", "Comma-separated list of directories containing CRD source files (required)") | ||
| flag.StringVar(&outputDir, "output-dir", "", "Output directory for generated code (required)") | ||
| flag.Parse() | ||
|
|
||
| if crdPackage == "" || inputDirs == "" || outputDir == "" { | ||
| flag.Usage() | ||
| fmt.Fprintf(os.Stderr, "\nError: Missing required flags\n\n") | ||
| fmt.Fprintf(os.Stderr, "Example usage:\n") | ||
| fmt.Fprintf(os.Stderr, " %s \\\n", os.Args[0]) | ||
| fmt.Fprintf(os.Stderr, " --api-version=v1alpha1 \\\n") | ||
| fmt.Fprintf(os.Stderr, " --crd-package=github.com/openshift-online/rosa-hyperfleet-api/hack/api-codegen/api/v1alpha1 \\\n") | ||
| fmt.Fprintf(os.Stderr, " --input-dirs=./api/v1alpha1 \\\n") | ||
| fmt.Fprintf(os.Stderr, " --output-dir=./pkg/conversion/v1alpha1\n") | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| // Split input directories | ||
| dirs := strings.Split(inputDirs, ",") | ||
| for i, dir := range dirs { | ||
| // Convert to absolute path | ||
| absDir, err := filepath.Abs(dir) | ||
| if err != nil { | ||
| log.Fatalf("Failed to resolve directory %s: %v", dir, err) | ||
| } | ||
| dirs[i] = absDir | ||
| } | ||
|
|
||
| // Create generator | ||
| gen := conversion.NewGenerator(apiVersion, crdPackage, dirs, outputDir) | ||
|
|
||
| log.Printf("Conversion code generator") | ||
| log.Printf(" API Version: %s", apiVersion) | ||
| log.Printf(" CRD Package: %s", crdPackage) | ||
| log.Printf(" Input Dirs: %s", strings.Join(dirs, ", ")) | ||
| log.Printf(" Output Dir: %s", outputDir) | ||
| log.Println() | ||
|
|
||
| // Generate | ||
| if err := gen.Generate(); err != nil { | ||
| log.Fatalf("Generation failed: %v", err) | ||
| } | ||
|
|
||
| log.Println("✓ Successfully generated:") | ||
| log.Println(" - REST types (rest/)") | ||
| log.Println(" - ServiceSetFields (../types.go)") | ||
| log.Println(" - Conversion functions (cluster.go, nodepool.go)") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "flag" | ||
| "fmt" | ||
| "log" | ||
| "os" | ||
|
|
||
| "github.com/openshift-online/rosa-hyperfleet-api/hack/api-codegen/pkg/featuregate" | ||
| ) | ||
|
|
||
| func main() { | ||
| var ( | ||
| inputFile = flag.String("input", "", "Input CRD YAML file") | ||
| outputDir = flag.String("output-dir", "config/crd/variants", "Output directory for CRD variants") | ||
| baseName = flag.String("base-name", "", "Base name for output files (e.g., 'cluster' produces cluster_default.yaml)") | ||
| featureSet = flag.String("feature-set", "", "Generate only one feature set variant (default, techpreview, devpreview)") | ||
| ) | ||
|
|
||
| flag.Parse() | ||
|
|
||
| if *inputFile == "" { | ||
| fmt.Fprintln(os.Stderr, "Error: --input is required") | ||
| flag.Usage() | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| if *baseName == "" { | ||
| fmt.Fprintln(os.Stderr, "Error: --base-name is required") | ||
| flag.Usage() | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| // Create output directory | ||
| if err := os.MkdirAll(*outputDir, 0755); err != nil { | ||
| log.Fatalf("Creating output directory: %v", err) | ||
| } | ||
|
|
||
| g := featuregate.NewCRDVariantGenerator() | ||
|
|
||
| if *featureSet != "" { | ||
| // Generate single variant | ||
| var fs featuregate.FeatureSet | ||
| switch *featureSet { | ||
| case "default": | ||
| fs = featuregate.Default | ||
| case "techpreview": | ||
| fs = featuregate.TechPreviewNoUpgrade | ||
| case "devpreview": | ||
| fs = featuregate.DevPreviewNoUpgrade | ||
| default: | ||
| log.Fatalf("Invalid feature set: %s (must be default, techpreview, or devpreview)", *featureSet) | ||
| } | ||
|
|
||
| outputPath := fmt.Sprintf("%s/%s_%s.yaml", *outputDir, *baseName, *featureSet) | ||
| fmt.Printf("Generating %s variant: %s\n", *featureSet, outputPath) | ||
|
|
||
| if err := g.GenerateVariant(*inputFile, outputPath, fs); err != nil { | ||
| log.Fatalf("Generating variant: %v", err) | ||
| } | ||
|
|
||
| fmt.Printf("✓ Generated %s variant\n", *featureSet) | ||
| } else { | ||
| // Generate all variants | ||
| fmt.Printf("Generating all CRD variants from %s to %s/\n", *inputFile, *outputDir) | ||
|
|
||
| if err := g.GenerateAllVariants(*inputFile, *outputDir, *baseName); err != nil { | ||
| log.Fatalf("Generating variants: %v", err) | ||
| } | ||
|
|
||
| fmt.Printf("✓ Generated default variant: %s/%s_default.yaml\n", *outputDir, *baseName) | ||
| fmt.Printf("✓ Generated techpreview variant: %s/%s_techpreview.yaml\n", *outputDir, *baseName) | ||
| fmt.Printf("✓ Generated devpreview variant: %s/%s_devpreview.yaml\n", *outputDir, *baseName) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Run the configuration verifier in this target.
codegen-verifyonly compiles packages; it never executesverify-configuration, so missing write-mode markers pass this pipeline. Invoke it with$(V1ALPHA1_DIR)/configuration.go.Proposed fix
codegen-verify: build-api-codegen + ./bin/verify-configuration $(V1ALPHA1_DIR)/configuration.go cd hyperfleet-operator/api && go build ./... cd platform-api && go build ./internal/codegen/...📝 Committable suggestion
🤖 Prompt for AI Agents