chore: refactor read scheme to openapi from kubernetes api definition

Previously, only a single embedded Kubernetes API version could be specified, resulting in a lack of support for certain GVKs.
To address this, the goal is to create and utilize a unified scheme that consolidates Kubernetes API definitions.
As a preliminary step, the current method of loading API definitions will be improved.
This commit is contained in:
koba1t
2026-07-17 17:16:44 +09:00
committed by Yugo Kobayashi
parent f7d33c2610
commit 9216c6f573
29 changed files with 1791 additions and 45006 deletions

View File

@@ -4,35 +4,32 @@
package openapi
import (
"path/filepath"
"strings"
"testing"
openapi_v2 "github.com/google/gnostic-models/openapiv2"
"google.golang.org/protobuf/proto"
"sigs.k8s.io/kustomize/kyaml/openapi/kubernetesapi"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
func BenchmarkProtoUnmarshal(t *testing.B) {
version := kubernetesOpenAPIDefaultVersion
// parse the swagger, this should never fail
assetName := filepath.Join(
"kubernetesapi",
strings.ReplaceAll(version, ".", "_"),
"swagger.pb")
b := kubernetesapi.OpenAPIMustAsset[version](assetName)
for i := 0; i < t.N; i++ {
// We parse protobuf and get an openapiv2.Document here.
if err := proto.Unmarshal(b, &openapi_v2.Document{}); err != nil {
t.Fatalf("proto.Unmarshal failed: %v", err)
func BenchmarkBuiltinBundleDecode(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
if _, err := decodeBuiltinBundle(builtinKubernetesOpenAPIBundle); err != nil {
b.Fatalf("decodeBuiltinBundle failed: %v", err)
}
}
}
func BenchmarkFirstSchemaLookup(b *testing.B) {
b.ReportAllocs()
typeMeta := yaml.TypeMeta{APIVersion: "apps/v1", Kind: "Deployment"}
for i := 0; i < b.N; i++ {
ResetOpenAPI()
if schema := SchemaForResourceType(typeMeta); schema == nil {
b.Fatal("Deployment schema was not found")
}
}
ResetOpenAPI()
}
func BenchmarkPrecomputedIsNamespaceScoped(b *testing.B) {
testcases := map[string]yaml.TypeMeta{
"namespace scoped": {APIVersion: "apps/v1", Kind: "ControllerRevision"},