當前位置: 首頁>>代碼示例>>Golang>>正文


Golang versioned.Convert_versioned_InternalEvent_to_versioned_Event函數代碼示例

本文整理匯總了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)
	}
}
開發者ID:vikaschoudhary16,項目名稱:kubernetes,代碼行數:60,代碼來源:codec.go

示例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)
	}
}
開發者ID:Xmagicer,項目名稱:origin,代碼行數:41,代碼來源:codec.go

示例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
}
開發者ID:Q-Lee,項目名稱:kubernetes,代碼行數:98,代碼來源:conversion.go

示例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)
//.........這裏部分代碼省略.........
開發者ID:ZenoRewn,項目名稱:origin,代碼行數:101,代碼來源:install.go

示例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
	})
}
開發者ID:Xmagicer,項目名稱:origin,代碼行數:101,代碼來源:install.go


注:本文中的k8s/io/kubernetes/pkg/watch/versioned.Convert_versioned_InternalEvent_to_versioned_Event函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。