@@ -23,34 +23,31 @@ import (
2323 "sigs.k8s.io/kustomize/kyaml/openapi/kustomizationapi"
2424)
2525
26+ const (
27+ SchemaSourceBuiltin = "builtin"
28+ SchemaSourceFile = "file"
29+ SchemaSourceCluster = "cluster"
30+ )
31+
2632// ConfigureOpenAPI sets the openAPI schema in kyaml. It can either
2733// fetch the schema from a cluster, read it from file, or just the
2834// schema built into kyaml.
2935func ConfigureOpenAPI (factory util.Factory , k8sSchemaSource , k8sSchemaPath string ) error {
3036 switch k8sSchemaSource {
31- case "" :
32- openAPISchema , err := FetchOpenAPISchemaFromCluster (factory )
33- if err != nil {
34- // The default behavior is to try to fetch the schema from the
35- // cluster, but fall back on using the builtin one if that doesn't
36- // work
37- return nil
38- }
39- return ConfigureOpenAPISchema (openAPISchema )
40- case "cluster" :
37+ case SchemaSourceCluster :
4138 openAPISchema , err := FetchOpenAPISchemaFromCluster (factory )
4239 if err != nil {
4340 return fmt .Errorf ("error fetching schema from cluster: %v" , err )
4441 }
4542 return ConfigureOpenAPISchema (openAPISchema )
46- case "file" :
43+ case SchemaSourceFile :
4744 openAPISchema , err := ReadOpenAPISchemaFromDisk (k8sSchemaPath )
4845 if err != nil {
4946 return fmt .Errorf ("error reading file at path %s: %v" ,
5047 k8sSchemaPath , err )
5148 }
5249 return ConfigureOpenAPISchema (openAPISchema )
53- case "builtin" :
50+ case SchemaSourceBuiltin :
5451 return nil
5552 default :
5653 return fmt .Errorf ("unknown schema source %s. Must be one of file, cluster, builtin" ,
0 commit comments