示例#1
0
func init() {
	conversionScheme = conversion.NewScheme()
	conversionScheme.InternalVersion = ""
	conversionScheme.ExternalVersion = "v1beta1"
	conversionScheme.MetaInsertionFactory = metaInsertion{}
	AddKnownTypes("",
		PodList{},
		Pod{},
		ReplicationControllerList{},
		ReplicationController{},
		ServiceList{},
		Service{},
		MinionList{},
		Minion{},
		Status{},
		ServerOpList{},
		ServerOp{},
		ContainerManifestList{},
		Endpoints{},
	)
	AddKnownTypes("v1beta1",
		v1beta1.PodList{},
		v1beta1.Pod{},
		v1beta1.ReplicationControllerList{},
		v1beta1.ReplicationController{},
		v1beta1.ServiceList{},
		v1beta1.Service{},
		v1beta1.MinionList{},
		v1beta1.Minion{},
		v1beta1.Status{},
		v1beta1.ServerOpList{},
		v1beta1.ServerOp{},
		v1beta1.ContainerManifestList{},
		v1beta1.Endpoints{},
	)

	// TODO: when we get more of this stuff, move to its own file. This is not a
	// good home for lots of conversion functions.
	// TODO: Consider inverting dependency chain-- imagine v1beta1 package
	// registering all of these functions. Then, if you want to be able to understand
	// v1beta1 objects, you just import that package for its side effects.
	AddConversionFuncs(
		// EnvVar's Name is depricated in favor of Key.
		func(in *EnvVar, out *v1beta1.EnvVar) error {
			out.Value = in.Value
			out.Key = in.Name
			out.Name = in.Name
			return nil
		},
		func(in *v1beta1.EnvVar, out *EnvVar) error {
			out.Value = in.Value
			if in.Name != "" {
				out.Name = in.Name
			} else {
				out.Name = in.Key
			}
			return nil
		},
	)
}
示例#2
0
文件: helper.go 项目: asim/kubernetes
// NewScheme creates a new Scheme. A default scheme is provided and accessible
// as the "DefaultScheme" variable.
func NewScheme(internalVersion, externalVersion string) *Scheme {
	s := &Scheme{conversion.NewScheme()}
	s.raw.InternalVersion = internalVersion
	s.raw.ExternalVersion = externalVersion
	s.raw.MetaInsertionFactory = metaInsertion{}
	return s
}
示例#3
0
// NewScheme creates a new Scheme. This scheme is pluggable by default.
func NewScheme() *Scheme {
	s := &Scheme{conversion.NewScheme()}
	s.raw.InternalVersion = ""
	s.raw.MetaFactory = conversion.SimpleMetaFactory{BaseFields: []string{"TypeMeta"}, VersionField: "APIVersion", KindField: "Kind"}
	s.raw.AddConversionFuncs(
		s.embeddedObjectToRawExtension,
		s.rawExtensionToEmbeddedObject,
	)
	return s
}
示例#4
0
// NewScheme creates a new Scheme. This scheme is pluggable by default.
func NewScheme() *Scheme {
	s := &Scheme{conversion.NewScheme()}
	s.raw.InternalVersion = ""
	s.raw.MetaInsertionFactory = metaInsertion{}
	s.raw.AddConversionFuncs(
		s.embeddedObjectToRawExtension,
		s.rawExtensionToEmbeddedObject,
	)
	return s
}
示例#5
0
// NewScheme creates a new Scheme. This scheme is pluggable by default.
func NewScheme() *Scheme {
	s := &Scheme{conversion.NewScheme(), map[string]map[string]FieldLabelConversionFunc{}}
	s.raw.InternalVersion = ""
	s.raw.MetaFactory = conversion.SimpleMetaFactory{BaseFields: []string{"TypeMeta"}, VersionField: "APIVersion", KindField: "Kind"}
	if err := s.raw.AddConversionFuncs(
		s.embeddedObjectToRawExtension,
		s.rawExtensionToEmbeddedObject,
		s.runtimeObjectToRawExtensionArray,
		s.rawExtensionToRuntimeObjectArray,
	); err != nil {
		panic(err)
	}
	return s
}
示例#6
0
文件: scheme.go 项目: cjnygard/origin
// NewScheme creates a new Scheme. This scheme is pluggable by default.
func NewScheme() *Scheme {
	s := &Scheme{conversion.NewScheme(), map[string]map[string]FieldLabelConversionFunc{}}
	s.raw.InternalVersion = ""
	s.raw.MetaFactory = conversion.SimpleMetaFactory{BaseFields: []string{"TypeMeta"}, VersionField: "APIVersion", KindField: "Kind"}
	if err := s.raw.AddConversionFuncs(
		s.embeddedObjectToRawExtension,
		s.rawExtensionToEmbeddedObject,
		s.runtimeObjectToRawExtensionArray,
		s.rawExtensionToRuntimeObjectArray,
	); err != nil {
		panic(err)
	}
	// Enable map[string][]string conversions by default
	if err := s.raw.AddConversionFuncs(DefaultStringConversions...); err != nil {
		panic(err)
	}
	if err := s.raw.RegisterInputDefaults(&map[string][]string{}, JSONKeyMapper, conversion.AllowDifferentFieldTypeNames|conversion.IgnoreMissingFields); err != nil {
		panic(err)
	}
	if err := s.raw.RegisterInputDefaults(&url.Values{}, JSONKeyMapper, conversion.AllowDifferentFieldTypeNames|conversion.IgnoreMissingFields); err != nil {
		panic(err)
	}
	return s
}
示例#7
0
func init() {
	scheme = conversion.NewScheme()
	scheme.ExternalVersion = "v1beta1"
	scheme.AddKnownTypes("", TestResource{})
	scheme.AddKnownTypes("v1beta1", TestResource{})
}
示例#8
0
文件: helper.go 项目: lmiccini/origin
// objects.
type codec interface {
	Encode(obj interface{}) (data []byte, err error)
	Decode(data []byte) (interface{}, error)
	DecodeInto(data []byte, obj interface{}) error
}

// resourceVersioner provides methods for setting and retrieving
// the resource version from an API object.
type resourceVersioner interface {
	SetResourceVersion(obj interface{}, version uint64) error
	ResourceVersion(obj interface{}) (uint64, error)
}

var ResourceVersioner resourceVersioner = NewJSONBaseResourceVersioner()
var conversionScheme = conversion.NewScheme()
var Codec codec = conversionScheme

func init() {
	conversionScheme.InternalVersion = ""
	conversionScheme.ExternalVersion = "v1beta1"
	conversionScheme.MetaInsertionFactory = metaInsertion{}
}

// AddKnownTypes registers the types of the arguments to the marshaller of the package api.
// Encode() refuses the object unless its type is registered with AddKnownTypes.
func AddKnownTypes(version string, types ...interface{}) {
	conversionScheme.AddKnownTypes(version, types...)
}

// New returns a new API object of the given version ("" for internal