Skip to content

Commit

Permalink
parse custom schema only once when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
natasha41575 committed Mar 10, 2021
1 parent ed3ab9f commit a513c56
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions kyaml/openapi/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 globalSchema.currentOpenAPIVersion != currentVersion {
parseBuiltinSchema(currentVersion)
if kubernetesOpenAPIVersion == "" {
parseBuiltinSchema(kubernetesOpenAPIDefaultVersion)
} else {
parseBuiltinSchema(kubernetesOpenAPIVersion)
}
globalSchema.currentOpenAPIVersion = currentVersion
}

// parseBuiltinSchema calls parse to parse the json schemas
Expand Down

0 comments on commit a513c56

Please sign in to comment.