1 /* 2 Copyright 2018 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package managedfields 18 19 import ( 20 "k8s.io/apimachinery/pkg/util/managedfields/internal" 21 "k8s.io/kube-openapi/pkg/validation/spec" 22 ) 23 24 // TypeConverter allows you to convert from runtime.Object to 25 // typed.TypedValue and the other way around. 26 type TypeConverter = internal.TypeConverter 27 28 // NewDeducedTypeConverter creates a TypeConverter for CRDs that don't 29 // have a schema. It does implement the same interface though (and 30 // create the same types of objects), so that everything can still work 31 // the same. CRDs are merged with all their fields being "atomic" (lists 32 // included). 33 func NewDeducedTypeConverter() TypeConverter { 34 return internal.NewDeducedTypeConverter() 35 } 36 37 // NewTypeConverter builds a TypeConverter from a map of OpenAPIV3 schemas. 38 // This will automatically find the proper version of the object, and the 39 // corresponding schema information. 40 // The keys to the map must be consistent with the names 41 // used by Refs within the schemas. 42 // The schemas should conform to the Kubernetes Structural Schema OpenAPI 43 // restrictions found in docs: 44 // https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#specifying-a-structural-schema 45 func NewTypeConverter(openapiSpec map[string]*spec.Schema, preserveUnknownFields bool) (TypeConverter, error) { 46 return internal.NewTypeConverter(openapiSpec, preserveUnknownFields) 47 } 48