TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: Update your CRDs with confidence ( schema validation with cty)

2 pointsby skarlso9 months ago
Hello everyone!<p>Previously I wrote about cty[^1] that can be used to generate valid YAML samples from a CRD ( now, including things like, valid Pattern generated random string, enums, default values, minimum int, minimum number of items.. etc ).<p>It also has a website that can be used to achieve the same thing here: <a href="https:&#x2F;&#x2F;crdtoyaml.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;crdtoyaml.com&#x2F;</a><p>This update <a href="https:&#x2F;&#x2F;github.com&#x2F;Skarlso&#x2F;crd-to-sample-yaml&#x2F;releases&#x2F;tag&#x2F;v0.8.0">https:&#x2F;&#x2F;github.com&#x2F;Skarlso&#x2F;crd-to-sample-yaml&#x2F;releases&#x2F;tag&#x2F;v...</a> brings a feature with it, which I think is super cool. If not, well, then no. :)<p>Basically, inspired by `helm unittest` the user can define a test like this:<p><pre><code> suite: test aws clusters infrastructure crds template: sample-tests&#x2F;crds&#x2F;infrastructure.cluster.x-k8s.io_awsclusters.yaml tests: - it: matches AWSCluster crds correctly asserts: - matchSnapshot: # this will generate one snapshot &#x2F; CRD version and match all of them to the right version of the CRD path: sample-tests&#x2F;__snapshots__ - matchSnapshot: path: sample-tests&#x2F;__snapshots__ # generates a yaml file minimal: true - matchString: apiVersion: infrastructure.cluster.x-k8s.io&#x2F;v1beta2 kind: AWSCluster spec: controlPlaneEndpoint: host: string port: 1 - matchString: apiVersion: infrastructure.cluster.x-k8s.io&#x2F;v1beta2 kind: AWSCluster spec: controlPlaneEndpoint: # this is failing the test because the type is number and not string host: 12345 port: 1 </code></pre> This will take a CRD and test the CRD validates a given sample. In this case, it&#x27;s a string and two snapshot values. The snapshots can be generated using `cty test sample-tests --update`.<p>The snapshots will contain valid values, such as minimum integer, minimum number of items, defaults, enums, Patterns ( yes it generates random value that will satisfy a given pattern regex ) and more.<p>It will only ever match the right version with the right version. Meaning it won&#x27;t try `v1beta2` to match to `v1alpha1`. Since CRD files can have multiple versions in them.<p>It can be added as a simple make target like helm unittest.<p>This is very much an alpha feature, so please, if you do use it, report any problems. :)<p>Thank you! Enjoy.<p>[^1]: <a href="https:&#x2F;&#x2F;github.com&#x2F;Skarlso&#x2F;crd-to-sample-yaml">https:&#x2F;&#x2F;github.com&#x2F;Skarlso&#x2F;crd-to-sample-yaml</a>

no comments

no comments