From a513c56d88406d5bc9e6ab5b80ab5b0716ac8503 Mon Sep 17 00:00:00 2001 From: Natasha Sarkar Date: Wed, 10 Mar 2021 13:45:53 -0800 Subject: [PATCH] parse custom schema only once when necessary --- kyaml/openapi/openapi.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/kyaml/openapi/openapi.go b/kyaml/openapi/openapi.go index cfe18e469..5b7857606 100644 --- a/kyaml/openapi/openapi.go +++ b/kyaml/openapi/openapi.go @@ -44,10 +44,9 @@ type openapiData struct { // Kubernetes schema as part of the global schema noUseBuiltInSchema bool - // currentOpenAPIVersion stores the version if the kubernetes openapi data - // that is currently stored as the schema, so that we only reparse the - // schema when necessary (to speed up performance) - currentOpenAPIVersion string + // schemaInit stores whether or not we've parsed the schema already, + // so that we only reparse the when necessary (to speed up performance) + schemaInit bool } // ResourceSchema wraps the OpenAPI Schema. @@ -477,27 +476,28 @@ func GetSchemaVersion() string { // initSchema parses the json schema func initSchema() { + if globalSchema.schemaInit { + return + } + globalSchema.schemaInit = true + if customSchema != nil { - ResetOpenAPI() err := parse(customSchema) if err != nil { panic("invalid schema file") } - if err := parse(kustomizationapi.MustAsset(kustomizationAPIAssetName)); err != nil { + if err = parse(kustomizationapi.MustAsset(kustomizationAPIAssetName)); err != nil { // this should never happen panic(err) } return } - currentVersion := kubernetesOpenAPIVersion - if currentVersion == "" { - currentVersion = kubernetesOpenAPIDefaultVersion + if kubernetesOpenAPIVersion == "" { + parseBuiltinSchema(kubernetesOpenAPIDefaultVersion) + } else { + parseBuiltinSchema(kubernetesOpenAPIVersion) } - if globalSchema.currentOpenAPIVersion != currentVersion { - parseBuiltinSchema(currentVersion) - } - globalSchema.currentOpenAPIVersion = currentVersion } // parseBuiltinSchema calls parse to parse the json schemas