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 OpenAPI v3 schema support to the Virtual Workspace framework #3246

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

xmudrii
Copy link
Contributor

@xmudrii xmudrii commented Jan 13, 2025

Summary

This PR continues work done in #3059. Huge thanks to @palnabarun for all the work on this feature so far!

This PR adds OpenAPI v3 schema support to the Virtual Workspace dynamic framework.

A new openAPIHandler has been implemented that utilizes the kube-openapi library to generate and serve the OpenAPI v3 specs. The specs are generated for the following routes:

  • /api and /apis - information about API groups
  • /apis/<group> - information about API versions
  • /api/v1 and /apis/<group>/<version> - specs for the concrete GroupVersion

Example calls:

# The root spec containing all other OpenAPI v3 URLs
k get --raw '/services/apiexport/<Cluster ID>/<APIExport Name>/clusters/<Cluster ID>/openapi/v3

# Information about API groups
k get --raw '/services/apiexport/<Cluster ID>/<APIExport Name>/clusters/<Cluster ID>/openapi/v3/apis

# Specs for APIs in stable.example.com/v1
k get --raw '/services/apiexport/<Cluster ID>/<APIExport Name>/clusters/<Cluster ID>/openapi/v3/stable.example.com/v1

Specs are generated for all APIDefintions available in that virtual workspace. In other words, everything that's served by GetAPIDefinitionSet function is available in the OpenAPI v3 spec in that virtual workspace.

The implementation is a bit different to what the regular API servers are doing due to the way how are virtual workspaces implemented. The regular API servers are building the OpenAPI v3 specs from web services registered in that API server. However, this is not an option for the virtual workspaces API server because it only has three web services registered: /api, /apis, and /version. None of these three web services have any subroute registered, so there's no information about e.g. /apis/<group> or /apis/<group>/<version>. That makes generating the OpenAPI v3 specs using the "usual approach" impossible.

I mitigated that by:

  • Generating specs for /api, /apis/, and /version from the respective web services
  • Utilizing API discovery to generate web services for each available /apis/<group>, and then generate the OpenAPI v3 specs for these web services
  • Converting the available APIDefinitions to CustomResourceDefintions, and then using the appropriate function from the kube-openapi library to generate the specs

At the end, all these specs are merged into one and served. This is heavily inspired by #3246

This is also a bit different than idea in #3059, as #3059 tried to manually implement each OpenAPI v3 route, while this heavily relies on the kube-openapi library.

To make this more performant, a simple caching solution has been implemented. I'm generating a hash out of the APIDefinition's spec, and then use it to generate a key. That key is used for the LRU cache where I store the OpenAPI v3 service. This is almost copy-paste of implementation from #3246.

As requested by the community, I implemented a simple way to disable the OpenAPI v3 generation by setting the SkipOpenAPIInstallation extra configuration option to true.

Finally, unlike the original implementation in #3059, this implementation doesn't tap into the CreateServingInfoFor function. Thinking about that, I think it would have been possible and it could have enabled more effective caching, but because of the complexity, I decided to go with a "simpler" initial implementation, and we can consider doing this in the future.

The only missing part are E2E tests. This is something that I plan on adding later, potentially as a follow up PR if that's okay.

Related issue(s)

Fixes #3242

Release Notes

Add OpenAPI v3 schema support to the Virtual Workspace framework

@kcp-ci-bot kcp-ci-bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. dco-signoff: yes Indicates the PR's author has signed the DCO. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jan 13, 2025
@kcp-ci-bot
Copy link
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@kcp-ci-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign clubanderson for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kcp-ci-bot kcp-ci-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jan 13, 2025
@xmudrii xmudrii force-pushed the vws-openapi-v3 branch 3 times, most recently from 4003968 to 4d4d225 Compare February 5, 2025 19:14
Signed-off-by: Marko Mudrinić <[email protected]>
On-behalf-of: @SAP [email protected]
@kcp-ci-bot kcp-ci-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Feb 6, 2025
@xmudrii xmudrii marked this pull request as ready for review February 6, 2025 14:24
@kcp-ci-bot kcp-ci-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 6, 2025
@xmudrii xmudrii changed the title ✨ [WIP] Add OpenAPI v3 schema support to the Virtual Workspace framework ✨ Add OpenAPI v3 schema support to the Virtual Workspace framework Feb 6, 2025
@sttts
Copy link
Member

sttts commented Feb 6, 2025

/retest

e2e-sharded flake real?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dco-signoff: yes Indicates the PR's author has signed the DCO. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature: OpenAPIv3 support in virtual workspace framework
4 participants