mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
parse custom schema only once when necessary
This commit is contained in:
@@ -44,10 +44,9 @@ type openapiData struct {
|
|||||||
// Kubernetes schema as part of the global schema
|
// Kubernetes schema as part of the global schema
|
||||||
noUseBuiltInSchema bool
|
noUseBuiltInSchema bool
|
||||||
|
|
||||||
// currentOpenAPIVersion stores the version if the kubernetes openapi data
|
// schemaInit stores whether or not we've parsed the schema already,
|
||||||
// that is currently stored as the schema, so that we only reparse the
|
// so that we only reparse the when necessary (to speed up performance)
|
||||||
// schema when necessary (to speed up performance)
|
schemaInit bool
|
||||||
currentOpenAPIVersion string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResourceSchema wraps the OpenAPI Schema.
|
// ResourceSchema wraps the OpenAPI Schema.
|
||||||
@@ -477,27 +476,28 @@ func GetSchemaVersion() string {
|
|||||||
|
|
||||||
// initSchema parses the json schema
|
// initSchema parses the json schema
|
||||||
func initSchema() {
|
func initSchema() {
|
||||||
|
if globalSchema.schemaInit {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
globalSchema.schemaInit = true
|
||||||
|
|
||||||
if customSchema != nil {
|
if customSchema != nil {
|
||||||
ResetOpenAPI()
|
|
||||||
err := parse(customSchema)
|
err := parse(customSchema)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("invalid schema file")
|
panic("invalid schema file")
|
||||||
}
|
}
|
||||||
if err := parse(kustomizationapi.MustAsset(kustomizationAPIAssetName)); err != nil {
|
if err = parse(kustomizationapi.MustAsset(kustomizationAPIAssetName)); err != nil {
|
||||||
// this should never happen
|
// this should never happen
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
currentVersion := kubernetesOpenAPIVersion
|
if kubernetesOpenAPIVersion == "" {
|
||||||
if currentVersion == "" {
|
parseBuiltinSchema(kubernetesOpenAPIDefaultVersion)
|
||||||
currentVersion = kubernetesOpenAPIDefaultVersion
|
} else {
|
||||||
|
parseBuiltinSchema(kubernetesOpenAPIVersion)
|
||||||
}
|
}
|
||||||
if globalSchema.currentOpenAPIVersion != currentVersion {
|
|
||||||
parseBuiltinSchema(currentVersion)
|
|
||||||
}
|
|
||||||
globalSchema.currentOpenAPIVersion = currentVersion
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseBuiltinSchema calls parse to parse the json schemas
|
// parseBuiltinSchema calls parse to parse the json schemas
|
||||||
|
|||||||
Reference in New Issue
Block a user