本文整理汇总了Golang中k8s/io/kubernetes/pkg/watch/versioned.Convert_versioned_InternalEvent_to_versioned_Event函数的典型用法代码示例。如果您正苦于以下问题:Golang Convert_versioned_InternalEvent_to_versioned_Event函数的具体用法?Golang Convert_versioned_InternalEvent_to_versioned_Event怎么用?Golang Convert_versioned_InternalEvent_to_versioned_Event使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Convert_versioned_InternalEvent_to_versioned_Event函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Encode
func (t *thirdPartyResourceDataEncoder) Encode(obj runtime.Object, stream io.Writer) (err error) {
switch obj := obj.(type) {
case *extensions.ThirdPartyResourceData:
return encodeToJSON(obj, stream)
case *extensions.ThirdPartyResourceDataList:
// TODO: There are likely still better ways to do this...
listItems := make([]json.RawMessage, len(obj.Items))
for ix := range obj.Items {
buff := &bytes.Buffer{}
err := encodeToJSON(&obj.Items[ix], buff)
if err != nil {
return err
}
listItems[ix] = json.RawMessage(buff.Bytes())
}
if t.gvk.Empty() {
return fmt.Errorf("thirdPartyResourceDataEncoder was not given a target version")
}
encMap := struct {
Kind string `json:"kind,omitempty"`
Items []json.RawMessage `json:"items"`
Metadata unversioned.ListMeta `json:"metadata,omitempty"`
APIVersion string `json:"apiVersion,omitempty"`
}{
Kind: t.gvk.Kind + "List",
Items: listItems,
Metadata: obj.ListMeta,
APIVersion: t.gvk.GroupVersion().String(),
}
encBytes, err := json.Marshal(encMap)
if err != nil {
return err
}
_, err = stream.Write(encBytes)
return err
case *versioned.InternalEvent:
event := &versioned.Event{}
err := versioned.Convert_versioned_InternalEvent_to_versioned_Event(obj, event, nil)
if err != nil {
return err
}
enc := json.NewEncoder(stream)
err = enc.Encode(event)
if err != nil {
return err
}
return nil
case *unversioned.Status, *unversioned.APIResourceList:
return t.delegate.Encode(obj, stream)
default:
return fmt.Errorf("unexpected object to encode: %#v", obj)
}
}
示例2: Encode
func (t *thirdPartyResourceDataEncoder) Encode(obj runtime.Object, stream io.Writer) (err error) {
switch obj := obj.(type) {
case *extensions.ThirdPartyResourceData:
return encodeToJSON(obj, stream)
case *extensions.ThirdPartyResourceDataList:
// TODO: There must be a better way to do this...
dataStrings := make([]string, len(obj.Items))
for ix := range obj.Items {
buff := &bytes.Buffer{}
err := encodeToJSON(&obj.Items[ix], buff)
if err != nil {
return err
}
dataStrings[ix] = buff.String()
}
if t.gvk.IsEmpty() {
return fmt.Errorf("thirdPartyResourceDataEncoder was not given a target version")
}
gv := t.gvk.GroupVersion()
_, err = fmt.Fprintf(stream, template, t.gvk.Kind+"List", gv.String(), strings.Join(dataStrings, ","))
return err
case *versioned.InternalEvent:
event := &versioned.Event{}
err := versioned.Convert_versioned_InternalEvent_to_versioned_Event(obj, event, nil)
if err != nil {
return err
}
enc := json.NewEncoder(stream)
err = enc.Encode(event)
if err != nil {
return err
}
return nil
case *unversioned.Status, *unversioned.APIResourceList:
return t.delegate.Encode(obj, stream)
default:
return fmt.Errorf("unexpected object to encode: %#v", obj)
}
}
示例3: addFastPathConversionFuncs
// This is a "fast-path" that avoids reflection for common types. It focuses on the objects that are
// converted the most in the cluster.
// TODO: generate one of these for every external API group - this is to prove the impact
func addFastPathConversionFuncs(scheme *runtime.Scheme) error {
scheme.AddGenericConversionFunc(func(objA, objB interface{}, s conversion.Scope) (bool, error) {
switch a := objA.(type) {
case *Pod:
switch b := objB.(type) {
case *api.Pod:
return true, Convert_v1_Pod_To_api_Pod(a, b, s)
}
case *api.Pod:
switch b := objB.(type) {
case *Pod:
return true, Convert_api_Pod_To_v1_Pod(a, b, s)
}
case *Event:
switch b := objB.(type) {
case *api.Event:
return true, Convert_v1_Event_To_api_Event(a, b, s)
}
case *api.Event:
switch b := objB.(type) {
case *Event:
return true, Convert_api_Event_To_v1_Event(a, b, s)
}
case *ReplicationController:
switch b := objB.(type) {
case *api.ReplicationController:
return true, Convert_v1_ReplicationController_To_api_ReplicationController(a, b, s)
}
case *api.ReplicationController:
switch b := objB.(type) {
case *ReplicationController:
return true, Convert_api_ReplicationController_To_v1_ReplicationController(a, b, s)
}
case *Node:
switch b := objB.(type) {
case *api.Node:
return true, Convert_v1_Node_To_api_Node(a, b, s)
}
case *api.Node:
switch b := objB.(type) {
case *Node:
return true, Convert_api_Node_To_v1_Node(a, b, s)
}
case *Namespace:
switch b := objB.(type) {
case *api.Namespace:
return true, Convert_v1_Namespace_To_api_Namespace(a, b, s)
}
case *api.Namespace:
switch b := objB.(type) {
case *Namespace:
return true, Convert_api_Namespace_To_v1_Namespace(a, b, s)
}
case *Service:
switch b := objB.(type) {
case *api.Service:
return true, Convert_v1_Service_To_api_Service(a, b, s)
}
case *api.Service:
switch b := objB.(type) {
case *Service:
return true, Convert_api_Service_To_v1_Service(a, b, s)
}
case *Endpoints:
switch b := objB.(type) {
case *api.Endpoints:
return true, Convert_v1_Endpoints_To_api_Endpoints(a, b, s)
}
case *api.Endpoints:
switch b := objB.(type) {
case *Endpoints:
return true, Convert_api_Endpoints_To_v1_Endpoints(a, b, s)
}
case *versioned.Event:
switch b := objB.(type) {
case *versioned.InternalEvent:
return true, versioned.Convert_versioned_Event_to_versioned_InternalEvent(a, b, s)
}
case *versioned.InternalEvent:
switch b := objB.(type) {
case *versioned.Event:
return true, versioned.Convert_versioned_InternalEvent_to_versioned_Event(a, b, s)
}
}
return false, nil
})
return nil
}
示例4: init
func init() {
// This is a "fast-path" that avoids reflection for common types. It focuses on the objects that are
// converted the most in the cluster.
// TODO: generate one of these for every external API group - this is to prove the impact
kapi.Scheme.AddGenericConversionFunc(func(objA, objB interface{}, s conversion.Scope) (bool, error) {
switch a := objA.(type) {
case *watchv1.Event:
switch b := objB.(type) {
case *watchv1.InternalEvent:
return true, watchv1.Convert_versioned_Event_to_versioned_InternalEvent(a, b, s)
case *watchapi.Event:
return true, watchv1.Convert_versioned_Event_to_watch_Event(a, b, s)
}
case *watchv1.InternalEvent:
switch b := objB.(type) {
case *watchv1.Event:
return true, watchv1.Convert_versioned_InternalEvent_to_versioned_Event(a, b, s)
}
case *watchapi.Event:
switch b := objB.(type) {
case *watchv1.Event:
return true, watchv1.Convert_watch_Event_to_versioned_Event(a, b, s)
}
case *kapi.ListOptions:
switch b := objB.(type) {
case *kv1.ListOptions:
return true, kv1.Convert_api_ListOptions_To_v1_ListOptions(a, b, s)
}
case *kv1.ListOptions:
switch b := objB.(type) {
case *kapi.ListOptions:
return true, kv1.Convert_v1_ListOptions_To_api_ListOptions(a, b, s)
}
case *kv1.ServiceAccount:
switch b := objB.(type) {
case *kapi.ServiceAccount:
return true, kv1.Convert_v1_ServiceAccount_To_api_ServiceAccount(a, b, s)
}
case *kapi.ServiceAccount:
switch b := objB.(type) {
case *kv1.ServiceAccount:
return true, kv1.Convert_api_ServiceAccount_To_v1_ServiceAccount(a, b, s)
}
case *kv1.SecretList:
switch b := objB.(type) {
case *kapi.SecretList:
return true, kv1.Convert_v1_SecretList_To_api_SecretList(a, b, s)
}
case *kapi.SecretList:
switch b := objB.(type) {
case *kv1.SecretList:
return true, kv1.Convert_api_SecretList_To_v1_SecretList(a, b, s)
}
case *kv1.Secret:
switch b := objB.(type) {
case *kapi.Secret:
return true, kv1.Convert_v1_Secret_To_api_Secret(a, b, s)
}
case *kapi.Secret:
switch b := objB.(type) {
case *kv1.Secret:
return true, kv1.Convert_api_Secret_To_v1_Secret(a, b, s)
}
case *routev1.RouteList:
switch b := objB.(type) {
case *routeapi.RouteList:
return true, routev1.Convert_v1_RouteList_To_api_RouteList(a, b, s)
}
case *routeapi.RouteList:
switch b := objB.(type) {
case *routev1.RouteList:
return true, routev1.Convert_api_RouteList_To_v1_RouteList(a, b, s)
}
case *routev1.Route:
switch b := objB.(type) {
case *routeapi.Route:
return true, routev1.Convert_v1_Route_To_api_Route(a, b, s)
}
case *routeapi.Route:
switch b := objB.(type) {
case *routev1.Route:
return true, routev1.Convert_api_Route_To_v1_Route(a, b, s)
}
case *buildv1.BuildList:
switch b := objB.(type) {
case *buildapi.BuildList:
return true, buildv1.Convert_v1_BuildList_To_api_BuildList(a, b, s)
}
case *buildapi.BuildList:
switch b := objB.(type) {
case *buildv1.BuildList:
return true, buildv1.Convert_api_BuildList_To_v1_BuildList(a, b, s)
//.........这里部分代码省略.........
示例5: addVersionsToScheme
//.........这里部分代码省略.........
v1.AddToScheme(api.Scheme)
}
}
// This is a "fast-path" that avoids reflection for common types. It focuses on the objects that are
// converted the most in the cluster.
// TODO: generate one of these for every external API group - this is to prove the impact
api.Scheme.AddGenericConversionFunc(func(objA, objB interface{}, s conversion.Scope) (bool, error) {
switch a := objA.(type) {
case *v1.Pod:
switch b := objB.(type) {
case *api.Pod:
return true, v1.Convert_v1_Pod_To_api_Pod(a, b, s)
}
case *api.Pod:
switch b := objB.(type) {
case *v1.Pod:
return true, v1.Convert_api_Pod_To_v1_Pod(a, b, s)
}
case *v1.Event:
switch b := objB.(type) {
case *api.Event:
return true, v1.Convert_v1_Event_To_api_Event(a, b, s)
}
case *api.Event:
switch b := objB.(type) {
case *v1.Event:
return true, v1.Convert_api_Event_To_v1_Event(a, b, s)
}
case *v1.ReplicationController:
switch b := objB.(type) {
case *api.ReplicationController:
return true, v1.Convert_v1_ReplicationController_To_api_ReplicationController(a, b, s)
}
case *api.ReplicationController:
switch b := objB.(type) {
case *v1.ReplicationController:
return true, v1.Convert_api_ReplicationController_To_v1_ReplicationController(a, b, s)
}
case *v1.Node:
switch b := objB.(type) {
case *api.Node:
return true, v1.Convert_v1_Node_To_api_Node(a, b, s)
}
case *api.Node:
switch b := objB.(type) {
case *v1.Node:
return true, v1.Convert_api_Node_To_v1_Node(a, b, s)
}
case *v1.Namespace:
switch b := objB.(type) {
case *api.Namespace:
return true, v1.Convert_v1_Namespace_To_api_Namespace(a, b, s)
}
case *api.Namespace:
switch b := objB.(type) {
case *v1.Namespace:
return true, v1.Convert_api_Namespace_To_v1_Namespace(a, b, s)
}
case *v1.Service:
switch b := objB.(type) {
case *api.Service:
return true, v1.Convert_v1_Service_To_api_Service(a, b, s)
}
case *api.Service:
switch b := objB.(type) {
case *v1.Service:
return true, v1.Convert_api_Service_To_v1_Service(a, b, s)
}
case *v1.Endpoints:
switch b := objB.(type) {
case *api.Endpoints:
return true, v1.Convert_v1_Endpoints_To_api_Endpoints(a, b, s)
}
case *api.Endpoints:
switch b := objB.(type) {
case *v1.Endpoints:
return true, v1.Convert_api_Endpoints_To_v1_Endpoints(a, b, s)
}
case *versioned.Event:
switch b := objB.(type) {
case *versioned.InternalEvent:
return true, versioned.Convert_versioned_Event_to_versioned_InternalEvent(a, b, s)
}
case *versioned.InternalEvent:
switch b := objB.(type) {
case *versioned.Event:
return true, versioned.Convert_versioned_InternalEvent_to_versioned_Event(a, b, s)
}
}
return false, nil
})
}