Skip to content
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

Allow duration format used in Kubernetes API machinery #309

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MattiasAng
Copy link

Fixes #300 to allow duration format commonly used across Kubernetes operators.

While this could potentially be fixed in upstream github.com/santhosh-tekuri/jsonschema I think this validation is very much up to the interpretation of the RFC and it would probably require an upgrade to v6 which has changed APIs in the package and would require a lot of refactoring.

@MattiasAng MattiasAng force-pushed the fix-duration-validation branch from 3a09ed4 to cf07921 Compare February 11, 2025 09:03
@yannh
Copy link
Owner

yannh commented Feb 12, 2025

Hi @MattiasAng , are you saying that upgrading to v6 of the schema validation library would fix this? Eventually we probably would need to do that work anyway... Thanks!

EDIT: I see :( still I'd rather update the library rather than add workarounds to be honest :/

@MattiasAng
Copy link
Author

MattiasAng commented Feb 13, 2025

@yannh No, it wouldn't solve the issue as they both interpret the RFC differently. So rephrasing a bit;

If we try and get this added to the jsonschema package and it gets merged it would probably be on the v6 version which would require a bigger refactoring of kubeconform validation steps. Considering the jsonschema package is not specific to Kubernetes I've got a feeling that it wouldn't be merged, but even if it was it would require considerably more work than just updating the version of the current module used.

If you think this workaround is not acceptable I'm currently swamped with other things that I wouldn't have time to take on trying to get this in to the jsonschema package, so I'll let someone else pick that up in that case and we'll use my fork for now.

@yannh
Copy link
Owner

yannh commented Feb 13, 2025

@MattiasAng can you help me understand, essentially Kubernetes accepts some duration formats that are not part of the spec / or not part of the implementation of the spec in gojsonschemas? Could you expand a bit on those differences? 🙏

@yannh
Copy link
Owner

yannh commented Feb 16, 2025

@MattiasAng I started a v6 branch, but am hoping for a cosmetic improvement first santhosh-tekuri/jsonschema#211 before I merge. I am also not completely sure I got it right just yet 😅 https://github.com/yannh/kubeconform/compare/jsonschemav6?expand=1

If this is a case of Kubernetes not implementing the spec correctly, and accepting input that is not, fundamentally, valid json schema, I think your patch would make sense, also it seems well-tested and simple enough...

@MattiasAng
Copy link
Author

MattiasAng commented Feb 17, 2025

@yannh Sorry, I gave a bit more context in the issue and code comment so I can understand that the pull request itself is a bit confusing.

Yes, essentially Kubernetes API machinery package is not implementing duration according to ISO8601 where JSON schema uses RFC3339 Appendix A which is based on ISO8601. JSON Schema expects all time durations to start with P while API Machinery for Kubernetes (which most custom operators use) expects a format such as 5m or 5 min which is either parsed by time.ParseDuration (which I used) or Scala duration format which doesn't match against RFC3339.

A bit annoying considering they use the formatting for datetime and date from RFC3339.

So in short, unless the maintainers of JSONschema package want to be non-compliant with RFC3339 I don't see how this could be upstreamed. 😄

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.

'30s' is not valid 'duration'
2 participants