本文整理汇总了Golang中k8s/io/kubernetes/pkg/conversion.IsNotRegisteredError函数的典型用法代码示例。如果您正苦于以下问题:Golang IsNotRegisteredError函数的具体用法?Golang IsNotRegisteredError怎么用?Golang IsNotRegisteredError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IsNotRegisteredError函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: convert_runtime_Object_To_runtime_RawExtension
// Convert_runtime_Object_To_runtime_RawExtension is conversion function that assumes that the runtime.Object you've embedded is in
// the same GroupVersion that your containing type is in. This is signficantly better than simply breaking.
// Given an ordered list of preferred external versions for a given encode or conversion call, the behavior of this function could be
// made generic, predictable, and controllable.
func convert_runtime_Object_To_runtime_RawExtension(in runtime.Object, out *runtime.RawExtension, s conversion.Scope) error {
if in == nil {
return nil
}
externalObject, err := internal.Scheme.ConvertToVersion(in, s.Meta().DestVersion)
if conversion.IsNotRegisteredError(err) {
switch cast := in.(type) {
case *runtime.Unknown:
out.RawJSON = cast.RawJSON
return nil
case *runtime.Unstructured:
bytes, err := runtime.Encode(runtime.UnstructuredJSONScheme, externalObject)
if err != nil {
return err
}
out.RawJSON = bytes
return nil
}
}
if err != nil {
return err
}
bytes, err := runtime.Encode(codec, externalObject)
if err != nil {
return err
}
out.RawJSON = bytes
out.Object = externalObject
return nil
}
示例2: roundTrip
func roundTrip(t *testing.T, codec runtime.Codec, originalItem runtime.Object) {
// Make a copy of the originalItem to give to conversion functions
// This lets us know if conversion messed with the input object
deepCopy, err := api.Scheme.DeepCopy(originalItem)
if err != nil {
t.Errorf("Could not copy object: %v", err)
return
}
item := deepCopy.(runtime.Object)
name := reflect.TypeOf(item).Elem().Name()
data, err := codec.Encode(item)
if err != nil {
if conversion.IsNotRegisteredError(err) {
t.Logf("%v is not registered", name)
return
}
t.Errorf("%v: %v (%#v)", name, err, item)
return
}
obj2, err := codec.Decode(data)
if err != nil {
t.Errorf("0: %v: %v\nCodec: %v\nData: %s\nSource: %#v", name, err, codec, string(data), originalItem)
return
}
if reflect.TypeOf(item) != reflect.TypeOf(obj2) {
obj2conv := reflect.New(reflect.TypeOf(item).Elem()).Interface().(runtime.Object)
if err := api.Scheme.Convert(obj2, obj2conv); err != nil {
t.Errorf("0X: no conversion from %v to %v: %v", reflect.TypeOf(item), reflect.TypeOf(obj2), err)
return
}
obj2 = obj2conv
}
if !api.Semantic.DeepEqual(originalItem, obj2) {
t.Errorf("1: %v: diff: %v\nCodec: %v\nData: %s\nSource: %s", name, util.ObjectDiff(originalItem, obj2), codec, string(data), util.ObjectGoPrintSideBySide(originalItem, obj2))
return
}
obj3 := reflect.New(reflect.TypeOf(item).Elem()).Interface().(runtime.Object)
err = codec.DecodeInto(data, obj3)
if err != nil {
t.Errorf("2: %v: %v", name, err)
return
}
if !api.Semantic.DeepEqual(originalItem, obj3) {
t.Errorf("3: %v: diff: %v\nCodec: %v", name, util.ObjectDiff(originalItem, obj3), codec)
return
}
}
示例3: PrintObj
// PrintObj implements ResourcePrinter
func (p *VersionedPrinter) PrintObj(obj runtime.Object, w io.Writer) error {
if len(p.version) == 0 {
return fmt.Errorf("no version specified, object cannot be converted")
}
for _, version := range p.version {
if len(version) == 0 {
continue
}
converted, err := p.convertor.ConvertToVersion(obj, version)
if conversion.IsNotRegisteredError(err) {
continue
}
if err != nil {
return err
}
return p.printer.PrintObj(converted, w)
}
return fmt.Errorf("the object cannot be converted to any of the versions: %v", p.version)
}
示例4: IsNotRegisteredError
// IsNotRegisteredError returns true if the error indicates the provided
// object or input data is not registered.
func IsNotRegisteredError(err error) bool {
return conversion.IsNotRegisteredError(err)
}