Jsonnet requires validation functions to be written - with CUE it's built it and the result is much less verbose.
Jsonnet validation example (can be inlined with the schema, but gets verbose. Best split into a different file).
local std = std;
{| # Organization structure for Backstage catalog | |
| # | |
| # Defines teams and users that own OpenChoreo catalog entities. | |
| # Projects and components are assigned owners via the backstage.io/owner | |
| # annotation on their Kubernetes CRs. | |
| # --------------------------------------------------------------------------- | |
| # Department | |
| # --------------------------------------------------------------------------- |
| apiVersion: openchoreo.dev/v1alpha1 | |
| kind: ComponentType | |
| metadata: | |
| name: simple-http-service | |
| namespace: default | |
| spec: | |
| workloadType: deployment | |
| schema: | |
| types: |
| #@ load("@ytt:data", "data") | |
| #@ load("@ytt:struct", "struct") | |
| #@ load("@ytt:assert", "assert") | |
| #@ app = data.values.app | |
| ## Note how all the logic is written in yaml comments - hence why it's been excluded from the shortlist. | |
| --- | |
| apiVersion: apps/v1 |
| #@data/values-schema | |
| app: | |
| name: "" | |
| image: "nginx:1.27" | |
| replicas: 1 | |
| ingressClass: "nginx" | |
| serviceType: "ClusterIP" | |
| gatewayName: "default-gateway" | |
| endpoints: | |
| - name: "" |
| apiVersion: platform.example.org/v1alpha1 | |
| kind: WebApp | |
| metadata: | |
| name: react-app | |
| spec: | |
| image: ghcr.io/acme/react-app:main | |
| replicas: 2 | |
| endpoints: | |
| - name: react-ui | |
| host: app.foo.com |
| apiVersion: apiextensions.crossplane.io/v1 | |
| kind: Composition | |
| metadata: | |
| name: webapp | |
| spec: | |
| compositeTypeRef: | |
| apiVersion: platform.example.org/v1alpha1 | |
| kind: WebApp | |
| resources: | |
| - name: deployment |
| apiVersion: apiextensions.crossplane.io/v1 | |
| kind: CompositeResourceDefinition | |
| metadata: | |
| name: webapps.platform.example.org | |
| spec: | |
| group: platform.example.org | |
| names: | |
| kind: WebApp | |
| plural: webapps | |
| claimNames: |
| apiVersion: kro.run/v1alpha1 | |
| kind: ResourceGraphDefinition | |
| metadata: | |
| name: webapps.kro.run | |
| spec: | |
| schema: | |
| apiVersion: v1alpha1 | |
| kind: WebApp | |
| spec: | |
| name: string |
| local web = import 'webApp.libsonnet'; | |
| web.webApp({ | |
| name: 'react', | |
| image: 'ghcr.io/acme/react-app:main', | |
| replicas: 2, | |
| gatewayName: 'default-gateway', | |
| ingressClass: 'nginx', | |
| serviceType: 'ClusterIP', | |
| endpoints: [ |