Skip to content

Generate core types oapi schemas - #26

Merged
jbw976 merged 2 commits into
crossplane-contrib:mainfrom
jonasz-lasut:9-core-types
Apr 13, 2026
Merged

Generate core types oapi schemas#26
jbw976 merged 2 commits into
crossplane-contrib:mainfrom
jonasz-lasut:9-core-types

Conversation

@jonasz-lasut

@jonasz-lasut jonasz-lasut commented Mar 20, 2026

Copy link
Copy Markdown

Description of your changes

Adds support for kubernetes core resources for Crossplane <2.2.0 that does not support required_schemas capability.
Generates openapi schemas with go generate ./... and later merges them with k8s.io/apiextensions-apiserver/pkg/generated/openapi schemas in the resolver.

Fixes #9

Tested using the following steps:

kind create cluster

helm install crossplane --version=2.1.3 --namespace crossplane-system --create-namespace crossplane-stable/crossplane --set args='{"--debug","--circuit-breaker-burst=500.0", "--circuit-breaker-refill-rate=5.0", "--circuit-breaker-cooldown=1m"}'

kubectl apply -f example/drc.yaml -f example/extensions.yaml -f example/core/xrd.yaml -f example/core/composition.yaml

kubectl apply -f example/core/xr.yaml

docker build . --platform=linux/amd64 --tag runtime-amd64

crossplane xpkg build --package-root=package --embed-runtime-image=runtime-amd64 --package-file=function-amd64.xpkg

crossplane xpkg push --package-files=function-amd64.xpkg ttl.sh/function-kro:0.0.0

kubectl patch function function-kro --type='json' -p='[{"op": "replace", "path": "/spec/package", "value":"ttl.sh/function-kro:0.0.0"}]'

Result:

judasz@fedora:~/code/function-kro$ k get -f example/core/xr.yaml -oyaml
apiVersion: core.example.crossplane.io/v1
kind: CoolSecret
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"core.example.crossplane.io/v1","kind":"CoolSecret","metadata":{"annotations":{},"name":"cool-secret","namespace":"default"},"spec":{"secretField":"cool-value"}}
  creationTimestamp: "2026-03-20T13:39:19Z"
  finalizers:
  - composite.apiextensions.crossplane.io
  generation: 4
  labels:
    crossplane.io/composite: cool-secret
  name: cool-secret
  namespace: default
  resourceVersion: "8738"
  uid: 265a095f-fc25-4101-8401-5cb7f5dfd0de
spec:
  crossplane:
    compositionRef:
      name: coolsecret-core
    compositionRevisionRef:
      name: coolsecret-core-7bed349
    compositionUpdatePolicy: Automatic
    resourceRefs:
    - apiVersion: v1
      kind: Secret
      name: cool-secret-8b3c0d296275
  secretField: cool-value
status:
  conditions:
  - lastTransitionTime: "2026-03-20T13:39:19Z"
    observedGeneration: 4
    reason: ReconcileSuccess
    status: "True"
    type: Synced
  - lastTransitionTime: "2026-03-20T13:39:19Z"
    observedGeneration: 4
    reason: Available
    status: "True"
    type: Ready
  - lastTransitionTime: "2026-03-20T13:39:19Z"
    observedGeneration: 4
    reason: WatchCircuitClosed
    status: "True"
    type: Responsive

Tool versions:

judasz@fedora:~/code/function-kro/example$ crossplane version
Client Version: v2.1.3
Server Version: v2.1.3
judasz@fedora:~/code/function-kro/example$ kubectl version
Client Version: v1.35.0
Kustomize Version: v5.7.1
Server Version: v1.35.0

I have:

  • Read and followed Crossplane's contribution process.
    - [ ] Added or updated unit tests for my change. - did not add tests as the PR adds a go:generate script but I've added an example and tested the feature

@jonasz-lasut
jonasz-lasut marked this pull request as ready for review March 30, 2026 07:40
@avarei

avarei commented Apr 6, 2026

Copy link
Copy Markdown

at the moment assuming that a missing CRD is probably a k8s core resource is causing a strange behaviour when using crossplane render without extra-resources. (for a composition with non k8s core resources)

https://github.com/jonasz-lasut/function-kro/blob/0aa0fb2927f791f55492c1b398ea50f1b12e8e3f/fn.go#L423-L428

maybe this PR would also be an opportunity to throw an error if a crd was requested and not found instead of assuming it to be a k8s core resource?

@jonasz-lasut

jonasz-lasut commented Apr 6, 2026

Copy link
Copy Markdown
Author

Hi @avarei , the issue with throwing error in that place instead of passing through to the next iteration is that we'd effectively halt the execution if we threw the error. We'd have to distinguish three cases -> crd found (add to crds, core resource found (just continue, handled by default resolved) and some resource not found (can be both core and crd, depends on if we have generated the core type).

I'll be happy to think about how we can solve that issue in a clean way but I'd rather do that in a separate PR to not block Crossplane <2.2 users to use function-kro with core resources.

If you open an issue please just mention me there and I'll be happy to take care of it :)

@jbw976 jbw976 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is amazing @jonasz-lasut, thank you for trying out this functionality! it will fill an important functionality gap when running on Crossplane pre-v2.2 🙇

when i did the v0.2.0 release, i made some changes to the resolver code to refactor it, which affects this PR. would you be able to rebase and reapply these changes to the latest in main? sorry for the hassle! 🙏

After that's done, please let me know so I can take this for a local test spin too! really excited for this!

Comment thread schemas/zz_generated.openapi.go
Comment thread generate/generate.go Outdated
Comment thread generate/generate.go Outdated
Comment thread example/core/extra.yaml Outdated
Signed-off-by: Jonasz Łasut-Balcerzak <jonasz.lasut@gmail.com>
@jonasz-lasut
jonasz-lasut force-pushed the 9-core-types branch 3 times, most recently from f59a9d8 to 4eb5d10 Compare April 9, 2026 16:25
@jonasz-lasut
jonasz-lasut requested a review from jbw976 April 9, 2026 16:39

@jbw976 jbw976 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for integrating the feedback @jonasz-lasut! I was able to take this for a test spin on a v2.1 and v2.2 control plane - both worked perfectly! 💪

I only have a few small suggestions now, and then I think we can merge this and have awesome support for core types pre v2.2! 🙇

Comment thread example/README.md
Comment thread kro/graph/schema/resolver/resolver.go Outdated
Comment thread example/README.md Outdated
Signed-off-by: Jonasz Łasut-Balcerzak <jonasz.lasut@gmail.com>

@jbw976 jbw976 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yessss, nice work @jonasz-lasut! let's ship this!!! 🚀

@jbw976
jbw976 merged commit 539c7ce into crossplane-contrib:main Apr 13, 2026
6 checks passed
@github-actions

Copy link
Copy Markdown

Successfully created backport PR for release-0.2:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kuberentes core type schemas not found for Crossplane versions pre v2.2

3 participants