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

Add schema validation example #228

Merged
merged 3 commits into from
Dec 4, 2023
Merged

Conversation

jacobtomlinson
Copy link
Member

@jacobtomlinson jacobtomlinson commented Dec 4, 2023

As discussed in #225 (comment) kr8s will probably never add automatic client-side schema validation for objects.

However, given that kubernetes-validate exists and is easy to use this PR adds an example to the documentation showing how to use it with kr8s.

import kubernetes_validate
from kr8s.objects import Pod

pod = Pod({
        "apiVersion": "v1",
        "kind": "Pod",
        "metadata": {
            "name": "my-pod",
        },
        "spec": {
            "containers": [{"name": "pause", "image": "gcr.io/google_containers/pause",}]
        },
    })

kubernetes_validate.validate(pod.raw, "1.28")
pod.create()

Note

I've also opened willthames/kubernetes-validate#23 which would enable passing objects directly to kubernetes_validate.validate() and means we could drop the .raw from the example (not just kr8s objects but kubernetes, kubernetes_asyncio and lightkube work with that change too).

@github-actions github-actions bot added documentation Improvements or additions to documentation kr8s tests labels Dec 4, 2023
@jacobtomlinson jacobtomlinson changed the title Add optional validate() method to API objects Add schema validation example Dec 4, 2023
Copy link

codecov bot commented Dec 4, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (416860a) 94.78% compared to head (110b37c) 94.80%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #228      +/-   ##
==========================================
+ Coverage   94.78%   94.80%   +0.01%     
==========================================
  Files          27       27              
  Lines        2645     2654       +9     
==========================================
+ Hits         2507     2516       +9     
  Misses        138      138              

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

@jacobtomlinson jacobtomlinson merged commit d2d52c4 into kr8s-org:main Dec 4, 2023
9 checks passed
@jacobtomlinson jacobtomlinson deleted the validate branch December 4, 2023 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation kr8s tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant