Skip to content

Commit

Permalink
rename proto swagger files and remove old json files
Browse files Browse the repository at this point in the history
  • Loading branch information
natasha41575 committed Apr 4, 2022
1 parent bf635a8 commit 7b37903
Show file tree
Hide file tree
Showing 10 changed files with 276 additions and 101,580 deletions.
8 changes: 4 additions & 4 deletions kyaml/openapi/kubernetesapi/openapiinfo.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

249 changes: 0 additions & 249 deletions kyaml/openapi/kubernetesapi/v1212/swagger.go

This file was deleted.

101,036 changes: 0 additions & 101,036 deletions kyaml/openapi/kubernetesapi/v1212/swagger.json

This file was deleted.

@@ -1,6 +1,6 @@
// Copyright 2022 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0

package v1218pb
package v1218

const OpenAPIProtobuf = "v1218pb"
249 changes: 249 additions & 0 deletions kyaml/openapi/kubernetesapi/v1218/swagger.go

Large diffs are not rendered by default.

278 changes: 0 additions & 278 deletions kyaml/openapi/kubernetesapi/v1218pb/swagger.go

This file was deleted.

15 changes: 12 additions & 3 deletions kyaml/openapi/openapi.go
Expand Up @@ -16,7 +16,6 @@ import (
"k8s.io/kube-openapi/pkg/validation/spec"
"sigs.k8s.io/kustomize/kyaml/errors"
"sigs.k8s.io/kustomize/kyaml/openapi/kubernetesapi"
"sigs.k8s.io/kustomize/kyaml/openapi/kubernetesapi/v1218pb"
"sigs.k8s.io/kustomize/kyaml/openapi/kustomizationapi"
"sigs.k8s.io/kustomize/kyaml/yaml"
k8syaml "sigs.k8s.io/yaml"
Expand Down Expand Up @@ -89,12 +88,14 @@ var precomputedIsNamespaceScoped = map[yaml.TypeMeta]bool{
{APIVersion: "extensions/v1beta1", Kind: "Ingress"}: true,
{APIVersion: "flowcontrol.apiserver.k8s.io/v1beta1", Kind: "FlowSchema"}: false,
{APIVersion: "flowcontrol.apiserver.k8s.io/v1beta1", Kind: "PriorityLevelConfiguration"}: false,
{APIVersion: "internal.apiserver.k8s.io/v1alpha1", Kind: "StorageVersion"}: false,
{APIVersion: "networking.k8s.io/v1", Kind: "Ingress"}: true,
{APIVersion: "networking.k8s.io/v1", Kind: "IngressClass"}: false,
{APIVersion: "networking.k8s.io/v1", Kind: "NetworkPolicy"}: true,
{APIVersion: "networking.k8s.io/v1beta1", Kind: "Ingress"}: true,
{APIVersion: "networking.k8s.io/v1beta1", Kind: "IngressClass"}: false,
{APIVersion: "node.k8s.io/v1", Kind: "RuntimeClass"}: false,
{APIVersion: "node.k8s.io/v1alpha1", Kind: "RuntimeClass"}: false,
{APIVersion: "node.k8s.io/v1beta1", Kind: "RuntimeClass"}: false,
{APIVersion: "policy/v1", Kind: "PodDisruptionBudget"}: true,
{APIVersion: "policy/v1beta1", Kind: "PodDisruptionBudget"}: true,
Expand All @@ -103,16 +104,23 @@ var precomputedIsNamespaceScoped = map[yaml.TypeMeta]bool{
{APIVersion: "rbac.authorization.k8s.io/v1", Kind: "ClusterRoleBinding"}: false,
{APIVersion: "rbac.authorization.k8s.io/v1", Kind: "Role"}: true,
{APIVersion: "rbac.authorization.k8s.io/v1", Kind: "RoleBinding"}: true,
{APIVersion: "rbac.authorization.k8s.io/v1alpha1", Kind: "ClusterRole"}: false,
{APIVersion: "rbac.authorization.k8s.io/v1alpha1", Kind: "ClusterRoleBinding"}: false,
{APIVersion: "rbac.authorization.k8s.io/v1alpha1", Kind: "Role"}: true,
{APIVersion: "rbac.authorization.k8s.io/v1alpha1", Kind: "RoleBinding"}: true,
{APIVersion: "rbac.authorization.k8s.io/v1beta1", Kind: "ClusterRole"}: false,
{APIVersion: "rbac.authorization.k8s.io/v1beta1", Kind: "ClusterRoleBinding"}: false,
{APIVersion: "rbac.authorization.k8s.io/v1beta1", Kind: "Role"}: true,
{APIVersion: "rbac.authorization.k8s.io/v1beta1", Kind: "RoleBinding"}: true,
{APIVersion: "scheduling.k8s.io/v1", Kind: "PriorityClass"}: false,
{APIVersion: "scheduling.k8s.io/v1alpha1", Kind: "PriorityClass"}: false,
{APIVersion: "scheduling.k8s.io/v1beta1", Kind: "PriorityClass"}: false,
{APIVersion: "storage.k8s.io/v1", Kind: "CSIDriver"}: false,
{APIVersion: "storage.k8s.io/v1", Kind: "CSINode"}: false,
{APIVersion: "storage.k8s.io/v1", Kind: "StorageClass"}: false,
{APIVersion: "storage.k8s.io/v1", Kind: "VolumeAttachment"}: false,
{APIVersion: "storage.k8s.io/v1alpha1", Kind: "CSIStorageCapacity"}: true,
{APIVersion: "storage.k8s.io/v1alpha1", Kind: "VolumeAttachment"}: false,
{APIVersion: "storage.k8s.io/v1beta1", Kind: "CSIDriver"}: false,
{APIVersion: "storage.k8s.io/v1beta1", Kind: "CSINode"}: false,
{APIVersion: "storage.k8s.io/v1beta1", Kind: "CSIStorageCapacity"}: true,
Expand All @@ -121,6 +129,7 @@ var precomputedIsNamespaceScoped = map[yaml.TypeMeta]bool{
{APIVersion: "v1", Kind: "ComponentStatus"}: false,
{APIVersion: "v1", Kind: "ConfigMap"}: true,
{APIVersion: "v1", Kind: "Endpoints"}: true,
{APIVersion: "v1", Kind: "EphemeralContainers"}: true,
{APIVersion: "v1", Kind: "Event"}: true,
{APIVersion: "v1", Kind: "LimitRange"}: true,
{APIVersion: "v1", Kind: "Namespace"}: false,
Expand Down Expand Up @@ -625,10 +634,10 @@ func parseBuiltinSchema(version string) {
// parse the swagger, this should never fail
assetName := filepath.Join(
"kubernetesapi",
"v1218pb",
version,
"swagger.pb")

if err := parse(v1218pb.MustAsset(assetName), "proto"); err != nil {
if err := parse(kubernetesapi.OpenAPIMustAsset[version](assetName), "proto"); err != nil {
// this should never happen
panic(err)
}
Expand Down
6 changes: 3 additions & 3 deletions kyaml/openapi/openapi_benchmark_test.go
Expand Up @@ -11,7 +11,7 @@ import (
"google.golang.org/protobuf/proto"
"k8s.io/kube-openapi/pkg/validation/spec"
"sigs.k8s.io/kustomize/kyaml/openapi/kubernetesapi"
"sigs.k8s.io/kustomize/kyaml/openapi/kubernetesapi/v1218pb"
"sigs.k8s.io/kustomize/kyaml/openapi/kubernetesapi/v1218"
)

// Benchmark for swagger parsing (UnmarshalJSON)
Expand Down Expand Up @@ -55,10 +55,10 @@ func BenchmarkOpenAPIV2ParseDocument(t *testing.B) {
func BenchmarkProtoUnmarshal(t *testing.B) {
assetName := filepath.Join(
"kubernetesapi",
"v1218pb",
"v1218",
"swagger.pb")

b := v1218pb.MustAsset(assetName)
b := v1218.MustAsset(assetName)

for i := 0; i < t.N; i++ {
// We parse protobuf and get an openapiv2.Document here.
Expand Down
13 changes: 7 additions & 6 deletions kyaml/openapi/openapi_test.go
Expand Up @@ -8,6 +8,7 @@ import (
"io/ioutil"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
Expand Down Expand Up @@ -272,12 +273,12 @@ func TestIsNamespaceScoped_builtin(t *testing.T) {
}

// TestIsNamespaceScopedPrecompute checks that the precomputed result meets the actual result
// func TestIsNamespaceScopedPrecompute(t *testing.T) {
// initSchema()
// if diff := cmp.Diff(globalSchema.namespaceabilityByResourceType, precomputedIsNamespaceScoped); diff != "" {
// t.Fatalf(diff)
// }
// }
func TestIsNamespaceScopedPrecompute(t *testing.T) {
initSchema()
if diff := cmp.Diff(globalSchema.namespaceabilityByResourceType, precomputedIsNamespaceScoped); diff != "" {
t.Fatalf(diff)
}
}

func TestIsNamespaceScoped_custom(t *testing.T) {
SuppressBuiltInSchemaUse()
Expand Down

0 comments on commit 7b37903

Please sign in to comment.