Skip to content

Conversation

@Danil-Grigorev
Copy link
Member

@Danil-Grigorev Danil-Grigorev commented Nov 25, 2025

Motivation

Schemars bump to 1.0 with kube 2.0 broke optional enum CRD generation. Verified it with schemars 1.1.0 - problem still exists.

Solution

Introduce an OptionalEnum transform to allow usage of Option<Enum> as in kube 1.0.0 with schemars < 1.0.0.

Removes incompatible output of schema generator with:

{
  "anyOf": [
    { "enum": ["Debug", "Info", "Error"], "type": "string" },
    { "enum": [null], "nullable": true }
  ]
}

replacing it with expected:

{ "enum": ["Debug", "Info", "Error"], "type": "string", "nullable": true }

Fixes: #1821

@codecov
Copy link

codecov bot commented Nov 25, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.8%. Comparing base (a12559d) to head (e4e239b).

Additional details and impacted files
@@           Coverage Diff           @@
##            main   #1853     +/-   ##
=======================================
+ Coverage   74.7%   74.8%   +0.1%     
=======================================
  Files         84      84             
  Lines       7938    7951     +13     
=======================================
+ Hits        5927    5941     +14     
+ Misses      2011    2010      -1     
Files with missing lines Coverage Δ
kube-core/src/schema.rs 95.8% <100.0%> (+0.7%) ⬆️
kube-derive/src/custom_resource.rs 84.3% <ø> (ø)
kube-derive/tests/crd_schema_test.rs 100.0% <ø> (ø)

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@clux clux left a comment

Choose a reason for hiding this comment

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

this looks sensible to me. minor nits only.
need to look at the bigger PR though.

@clux clux added the changelog-fix changelog fix category for prs label Nov 26, 2025
@clux clux added this to the 3.0.0 milestone Nov 26, 2025
@Danil-Grigorev Danil-Grigorev force-pushed the transform-optional-enums branch from f93db71 to e4e239b Compare November 26, 2025 20:33
clux
clux previously approved these changes Nov 27, 2025
Copy link
Member

@clux clux left a comment

Choose a reason for hiding this comment

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

Thanks a lot. Easy to review. Maybe let's wait for a response on #1839 first. They have tests for this exact transform, and it'd be good to preserve those / get some tests for this.

@clux clux dismissed their stale review November 28, 2025 08:05

let's wait with this. the #1893 pr is more holistic approach, so lets see if we can get that merged first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-fix changelog fix category for prs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CRD generation for optional enums broke with kube 2.0.0

2 participants