Fix CRD parameterization: package naming, Value path, and array flattening#4261
Fix CRD parameterization: package naming, Value path, and array flattening#4261guineveresaenger wants to merge 7 commits intomasterfrom
Conversation
Replace the hardcoded "mycrd" package name with a name derived from the CRD API groups. Users can also specify a name explicitly via -n/--name. - Add -n/--name flag to parseCrdArgs - derivePackageName() strips k8s suffixes (.k8s.io, .x-k8s.io, .io) and joins group prefixes with hyphens (e.g. gateway.networking.k8s.io → gateway-networking) - Falls back to "crds" if no groups can be extracted - Add tests for parseCrdArgs, derivePackageName, and stripK8sSuffix Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…t runs The engine calls Parameterize(Value) on subsequent `pulumi up` runs to reconstruct the CRD schema from the parameters persisted in Pulumi.yaml. Previously this was a stub returning nil, meaning parameterized CRD programs would fail on any run after the initial `pulumi package add`. The Value message carries Name, Version, and the serialized OpenAPI spec (stored as the Parameter field in ParameterizationSpec during the Args path). We deserialize it and regenerate the Pulumi schema via the same generateSchema() function used by the Args path. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
flattenOpenAPI only handled direct object properties, missing objects nested inside arrays (e.g., spec.listeners, spec.rules[].backendRefs). These array-of-object fields ended up as generic StringMapArrayInput in the generated SDK, losing all type safety. Now when a property is an array whose items schema is an object with properties, the inner object is hoisted to a top-level definition and the items schema is replaced with a $ref — the same treatment direct object properties already received. This works recursively, so deeply nested structures like rules[].matches[].path are also flattened. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Does the PR have any schema changes?Looking good! No breaking changes found. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #4261 +/- ##
==========================================
+ Coverage 44.47% 44.73% +0.25%
==========================================
Files 93 93
Lines 10393 10478 +85
==========================================
+ Hits 4622 4687 +65
- Misses 5241 5261 +20
Partials 530 530 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
|
||
| func TestFlattenOpenAPINestedArrayOfObjects(t *testing.T) { | ||
| // Simulate rules[].backendRefs[] — nested array-of-objects inside array-of-objects. | ||
| sw := &spec.Swagger{ |
There was a problem hiding this comment.
(minor/nitpick) I wonder if it's possible creating the nested objects using temporary variables to have this flatter (so it's a bit more legible for humans).
|
@claude please review this PR as well 🙏 Specially, around k8s and comprehensive Golang aspects (which are not my forte). |
|
/review-again |
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
/review-again |
|
/review-again |
There was a problem hiding this comment.
No actionable issues found after checking for bugs and CLAUDE.md compliance (no CLAUDE.md files exist in this repo).
Reviewed the three core changes:
- Package naming:
derivePackageName/stripK8sSuffixlogic is correct; suffix ordering (.x-k8s.iobefore.k8s.iobefore.io) is intentional and tested. parameterizeRequestValue: Correctly deserializes fromParameterizationSpec.Parameterbytes (set ingenerateSchemaviamarshaledOpenAPISchema). The serialization contract between the Args and Value paths is sound.flattenOpenAPIarray-of-objects: The shallow copy + shared Properties map pattern is correct — the parent'sItems.Schemais replaced with a new$refschema before the hoisted definition is processed, so no aliasing corruption occurs. Recursive flattening (e.g.,rules[].backendRefs[]) is confirmed byTestFlattenOpenAPINestedArrayOfObjects.
The prior open nitpick on test readability (line 313) was addressed by commit 9874ea0ac.
Reviewed by Internal PR Re-Review (Slash Command)
To install this agentic workflow, run
gh aw add pulumi-labs/gh-aw-internal/.github/workflows/gh-aw-pr-rereview.md@734ef41746387a6818fd8ac3e619c9fd81ac6957
Thread packageName through gen.PulumiSchema and gen/typegen.go so that parameterized CRD packages get distinct token prefixes, import paths, and schema metadata from the start — no post-processing rewrite needed. This lets a program import both the base @pulumi/kubernetes SDK and a CRD-generated SDK (e.g., gateway-networking) side by side without Go module path collisions. Also teach the provider runtime to accept resource tokens with the parameterized package prefix by checking crdSchemas.hasPackage() in gvkFromURN, so that resources like gateway-networking:gateway.networking.k8s.io/v1:Gateway are handled correctly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
Fixes three issues blocking end-to-end
pulumi package add kubernetes -- -c crds.yamlusage:"mycrd". Adds-n/--nameflag for explicit naming, falls back to first CRD group name (e.g.,gateway.networking.k8s.io→gateway-networking), or"crds"as default.Parameterize(Value)so subsequentpulumi upruns can reconstruct the CRD schema from saved state inPulumi.yaml. Previously this was a stub returningnil.flattenOpenAPIonly handled direct object properties, missing objects nested inside arrays (e.g.,spec.listeners,spec.rules[].backendRefs). These ended up as untypedStringMapArrayInputinstead of typed structs likeGatewaySpecListenersArgs.Tested end-to-end with Gateway API CRDs —
pulumi package addgenerates typed SDKs andpulumi upsuccessfully creates resources.Known limitations
pulumi/pulumiand will be resolved by extension parameterization.Test plan
derivePackageName,stripK8sSuffix,parseCrdArgsflattenOpenAPIwith array-of-objects and nested arrayspulumi package add kubernetes -- -v 1.2.1 -c gateway-api-crds.yaml→ typed Go SDK →pulumi up🤖 Generated with Claude Code