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 support for validating objects with a to_dict method #23

Merged

Conversation

jacobtomlinson
Copy link
Contributor

Thanks for the useful library!

Some other libraries such as kubernetes, kubernetes-asyncio, kr8s and lightkube all have objects that can represent Kubernetes resources, and all of those objects have a to_dict() method. This PR adds support for those objects to be passed directly into kubernetes_validate.validate().

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, "1.28", strict=True)

@willthames
Copy link
Owner

Hi @jacobtomlinson - I'm definitely happy with the idea of this PR, and once the test suite passes I'll merge it.

I don't know enough mypy to be able to offer suggestions for fixes, unfortunately!

@jacobtomlinson
Copy link
Contributor Author

Thanks @willthames. I think I've made mypy happy now.

@jacobtomlinson
Copy link
Contributor Author

Using Any felt like cheating here so on second thoughts I made a protocol instead, I've not done that before so that was a fun learning experience. mypy is happy for me locally so hopefully CI will be happy now.

@willthames
Copy link
Owner

ok, now the updates are failing flake8 tests, but that should be very simple to fix up.

@jacobtomlinson
Copy link
Contributor Author

Gah so sorry. Pushed another commit.

@willthames willthames merged commit 526bb8c into willthames:main Dec 9, 2023
6 checks passed
@willthames
Copy link
Owner

Thanks @jacobtomlinson , I'll sort a new 1.28 release shortly

@willthames
Copy link
Owner

1.28.1 is now released

@jacobtomlinson jacobtomlinson deleted the support_objects_with_to_dict branch December 11, 2023 14:45
@jacobtomlinson
Copy link
Contributor Author

Awesome thanks @willthames!

@jacobtomlinson
Copy link
Contributor Author

I added an example of using kubernetes-validate to the kr8s documentation too.

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.

2 participants