本文整理汇总了Golang中k8s/io/kubernetes/pkg/conversion.NewConverter函数的典型用法代码示例。如果您正苦于以下问题:Golang NewConverter函数的具体用法?Golang NewConverter怎么用?Golang NewConverter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewConverter函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestV1Beta3toAPIVolumeSourceConversion
func TestV1Beta3toAPIVolumeSourceConversion(t *testing.T) {
c := conversion.NewConverter(conversion.DefaultNameFunc)
c.Debug = t
if err := c.RegisterConversionFunc(convert_v1beta3_VolumeSource_To_api_VolumeSource); err != nil {
t.Fatalf("unexpected error %v", err)
}
in := VolumeSource{
Metadata: &MetadataVolumeSource{
Items: []MetadataFile{
{
Name: "./test/v1beta3-to-api/conversion",
},
},
},
}
out := api.VolumeSource{}
if err := c.Convert(&in, &out, 0, nil); err != nil {
t.Fatalf("unexpected error %v", err)
}
if e, a := in.Metadata.Items[0].Name, out.DownwardAPI.Items[0].Path; e != a {
t.Errorf("expected %v, got %v", e, a)
}
}
示例2: NewScheme
// NewScheme creates a new Scheme. This scheme is pluggable by default.
func NewScheme() *Scheme {
s := &Scheme{
gvkToType: map[unversioned.GroupVersionKind]reflect.Type{},
typeToGVK: map[reflect.Type][]unversioned.GroupVersionKind{},
unversionedTypes: map[reflect.Type]unversioned.GroupVersionKind{},
unversionedKinds: map[string]reflect.Type{},
cloner: conversion.NewCloner(),
fieldLabelConversionFuncs: map[string]map[string]FieldLabelConversionFunc{},
}
s.converter = conversion.NewConverter(s.nameFunc)
s.AddConversionFuncs(DefaultEmbeddedConversions()...)
// Enable map[string][]string conversions by default
if err := s.AddConversionFuncs(DefaultStringConversions...); err != nil {
panic(err)
}
if err := s.RegisterInputDefaults(&map[string][]string{}, JSONKeyMapper, conversion.AllowDifferentFieldTypeNames|conversion.IgnoreMissingFields); err != nil {
panic(err)
}
if err := s.RegisterInputDefaults(&url.Values{}, JSONKeyMapper, conversion.AllowDifferentFieldTypeNames|conversion.IgnoreMissingFields); err != nil {
panic(err)
}
return s
}
示例3: TestAPItoV1Beta3VolumeSourceConversion
func TestAPItoV1Beta3VolumeSourceConversion(t *testing.T) {
c := conversion.NewConverter(conversion.DefaultNameFunc)
c.Debug = t
if err := c.RegisterConversionFunc(convert_api_VolumeSource_To_v1beta3_VolumeSource); err != nil {
t.Fatalf("unexpected error %v", err)
}
in := api.VolumeSource{
DownwardAPI: &api.DownwardAPIVolumeSource{
Items: []api.DownwardAPIVolumeFile{
{
Path: "./test/api-to-v1beta3/conversion",
},
},
},
}
out := VolumeSource{}
if err := c.Convert(&in, &out, 0, nil); err != nil {
t.Fatalf("unexpected error %v", err)
}
if e, a := in.DownwardAPI.Items[0].Path, out.Metadata.Items[0].Name; e != a {
t.Errorf("expected %v, got %v", e, a)
}
}