Visitar URL original
CRD schema gen: Fix nullable types by guineveresaenger · Pull Request #4590 · pulumi/pulumi-kubernetes · GitHub
Skip to content

CRD schema gen: Fix nullable types - #4590

Merged
guineveresaenger merged 1 commit into
masterfrom
worktree-fix-nullable-crd-panic
Sep 8, 2026
Merged

guineveresaenger merged 1 commit into
masterfrom
worktree-fix-nullable-crd-panic

Conversation

@guineveresaenger

Copy link
Copy Markdown
Contributor

When a CRD field is marked nullable: true, the OpenAPI v2 conversion clears its type, items and properties, which causes schemagen to panic.
This pull request sets StripNullable to true, which removes the marker and allows the conversion to run.
Pulumi does not have a concept of nullability, so this change is correct for schema shape.

A test to prove this behavior was added.

Fixes #4588.

Co-Authored-By: Claude Opus 5 (1M context) noreply@anthropic.com

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Does the PR have any schema changes?

Generated by schema-tools v0.8.1.

Looking good! No breaking changes found.
No new resources/functions/types.

@guineveresaenger
guineveresaenger requested a review from a team September 8, 2026 17:50
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BvG2Zy3kBnnqjikcEoz77t
@codecov

codecov Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 51.94%. Comparing base (27fc005) to head (024ddd8).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4590      +/-   ##
==========================================
+ Coverage   51.76%   51.94%   +0.18%     
==========================================
  Files          94       94              
  Lines       10855    10855              
==========================================
+ Hits         5619     5639      +20     
+ Misses       4784     4764      -20     
  Partials      452      452              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@guineveresaenger
guineveresaenger force-pushed the worktree-fix-nullable-crd-panic branch from d3ae10a to 024ddd8 Compare September 8, 2026 17:55
@guineveresaenger

Copy link
Copy Markdown
Contributor Author

@pulumi-eon please review

@eon-pulumi

eon-pulumi Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Review Verdict: Approved

Root-caused and reproduced: the vendored k8s.io/apiextensions-apiserver builder unconditionally strips Type/Items/Properties from any schema node with Nullable=true during OpenAPI v2 conversion, and StripNullable:true is the correct, minimal fix (it neutralizes Nullable before that conversion runs, without touching Type/Items/Properties itself). Confirmed the new test fails pre-fix and passes post-fix, verified nullable object/nested/array-of-object cases all work correctly, and confirmed this is the single call site of BuildOpenAPIV2 in the repo. All reported CI checks are green (a few still in progress, none failing). This is an automated low-risk assessment, not a human review.


View session · Was this review helpful? Yes · No

@eon-pulumi-agent eon-pulumi-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the fix for the CRD schemagen panic on nullable: true fields (issue #4588).

Root cause verification: I traced this through the vendored k8s.io/apiextensions-apiserver builder. openapiv2.ToStructuralOpenAPIV2 unconditionally clears Type, Items, and Properties on any structural schema node where Nullable is still true at conversion time. Flipping StripNullable to true makes crdToOpenAPI call schema.StripNullable() beforehand, which only zeroes the Nullable bool (it does not touch Type/Items/Properties), so the destructive clearing in the v2 conversion never triggers. This is a correct, minimal fix for the reported crash.

Confirmed by reproduction: I reverted the flag locally and reran the new test (TestCRDToOpenAPIPreservesNullableFieldTypes) — it fails on the pre-fix code (nullable scalar/array lost its type) and passes on the PR's code, so it genuinely pins the regression. I also independently checked nullable object-type properties, nullable fields nested under non-nullable parents, and nullable elements inside arrays-of-objects — all are handled correctly by the fix as committed.

Blast radius: builder.BuildOpenAPIV2 has exactly one call site in the repo, so the change is fully scoped. Pulumi's own codegen (provider/pkg/gen) never reads an OpenAPI "nullable" flag, consistent with the PR's claim that Pulumi has no concept of nullability, so no information the generator actually consumes is lost by stripping it.

Evidence: clear PR description explaining root cause, linked issue reproduces the exact panic, all currently-reported CI checks are green (a few test (*) jobs were still in progress at review time, none failing), Codecov reports full coverage of the changed lines, and no breaking schema changes were detected.

Two non-blocking nits from deeper investigation, left as inline comments:

  • The new test only exercises the swagger-level symptom for scalar/array properties, not the full pipeline through generateSchema/PulumiSchema (the actual panic site) nor nullable object properties — all of which I verified work correctly, so this is a coverage nit, not a bug.
  • A CRD field that is both nullable: true and required now keeps its type and stays in the generated Required list (this combination previously always panicked, so it's newly-reachable, not a regression) — worth a follow-up decision on whether such fields should be optional in the generated Pulumi schema.

Nothing here blocks merge.

return names
}

func TestCRDToOpenAPIPreservesNullableFieldTypes(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit — tests

The new regression test only covers nullable scalar and array properties by asserting on the intermediate spec.Swagger structure; it doesn't exercise nullable object-type properties, nested nullable fields under a non-nullable parent, nullable elements inside arrays-of-objects, or the actual downstream panic site in gen.makeSchemaTypeSpec/generateSchema that issue #4588 originally reported.

Consider adding a test that runs the merged spec through generateSchema/PulumiSchema (the actual call path from the bug report), plus a case for a nullable object-type property, as a follow-up hardening -- not required to land this fix.

Why this matters

I manually verified all of these additional scenarios work correctly with the fix as committed, so there is no live bug here -- but a test suite that only pins the swagger-level symptom (rather than the full pipeline through PulumiSchema) would not catch a future regression if a different code path reintroduced the original panic.

crd,
v.Name,
builder.Options{V2: true, StripValueValidation: false, StripNullable: false, AllowNonStructural: true},
builder.Options{V2: true, StripValueValidation: false, StripNullable: true, AllowNonStructural: true},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit — logic

Setting StripNullable:true clears the Nullable flag before the vendored openapiv2.ToStructuralOpenAPIV2 conversion runs, so its logic that removes nullable properties from the parent's Required list (k8s.io/apiextensions-apiserver's conversion.go) never fires anymore. I confirmed empirically that a CRD field which is both nullable:true and required now keeps its type and stays in the swagger Required list, so it will generate as a mandatory (non-optional) Pulumi property even though Kubernetes may legitimately return/accept null for it.

Not blocking for this fix. Consider filing a follow-up to decide whether nullable+required CRD properties should be treated as optional in the generated Pulumi schema.

Why this matters

This combination was previously unreachable (any nullable field crashed generation unconditionally), so it is not a regression introduced by this PR, but it is a newly-reachable edge case that isn't discussed or tested and could produce a Pulumi schema that doesn't fully reflect the CRD's nullability contract for required fields.

@guineveresaenger
guineveresaenger merged commit a385981 into master Sep 8, 2026
20 checks passed
@guineveresaenger
guineveresaenger deleted the worktree-fix-nullable-crd-panic branch September 8, 2026 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extension-parameterized SDK generation fails for Istio CRDs

2 participants