当前位置: 首页>>代码示例>>Golang>>正文


Golang ObjectTyper.ObjectVersionAndKind方法代码示例

本文整理汇总了Golang中github.com/GoogleCloudPlatform/kubernetes/pkg/runtime.ObjectTyper.ObjectVersionAndKind方法的典型用法代码示例。如果您正苦于以下问题:Golang ObjectTyper.ObjectVersionAndKind方法的具体用法?Golang ObjectTyper.ObjectVersionAndKind怎么用?Golang ObjectTyper.ObjectVersionAndKind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/GoogleCloudPlatform/kubernetes/pkg/runtime.ObjectTyper的用法示例。


在下文中一共展示了ObjectTyper.ObjectVersionAndKind方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: CreateObjects

// CreateObjects creates bulk of resources provided by items list. Each item must
// be valid API type. It requires ObjectTyper to parse the Version and Kind and
// RESTMapper to get the resource URI and REST client that knows how to create
// given type
func CreateObjects(typer runtime.ObjectTyper, mapper meta.RESTMapper, clientFor ClientFunc, objects []runtime.Object) util.ErrorList {
	allErrors := util.ErrorList{}
	for i, obj := range objects {
		version, kind, err := typer.ObjectVersionAndKind(obj)
		if err != nil {
			allErrors = append(allErrors, fmt.Errorf("Config.item[%d] kind: %v", i, err))
			continue
		}

		mapping, err := mapper.RESTMapping(version, kind)
		if err != nil {
			allErrors = append(allErrors, fmt.Errorf("Config.item[%d] mapping: %v", i, err))
			continue
		}

		client, err := clientFor(mapping)
		if err != nil {
			allErrors = append(allErrors, fmt.Errorf("Config.item[%d] client: %v", i, err))
			continue
		}

		if err := CreateObject(client, mapping, obj); err != nil {
			allErrors = append(allErrors, fmt.Errorf("Config.item[%d]: %v", i, err))
		}
	}

	return allErrors
}
开发者ID:TencentSA,项目名称:kubernetes-0.5,代码行数:32,代码来源:config.go

示例2: CreateObjects

// CreateObjects creates bulk of resources provided by items list. Each item must
// be valid API type. It requires ObjectTyper to parse the Version and Kind and
// RESTMapper to get the resource URI and REST client that knows how to create
// given type
func CreateObjects(typer runtime.ObjectTyper, mapper meta.RESTMapper, clientFor ClientFunc, objects []runtime.Object) errs.ValidationErrorList {
	allErrors := errs.ValidationErrorList{}
	for i, obj := range objects {
		version, kind, err := typer.ObjectVersionAndKind(obj)
		if err != nil {
			reportError(&allErrors, i, errs.NewFieldInvalid("kind", obj))
			continue
		}

		mapping, err := mapper.RESTMapping(version, kind)
		if err != nil {
			reportError(&allErrors, i, errs.NewFieldNotSupported("mapping", err))
			continue
		}

		client, err := clientFor(mapping)
		if err != nil {
			reportError(&allErrors, i, errs.NewFieldNotSupported("client", obj))
			continue
		}

		if err := CreateObject(client, mapping, obj); err != nil {
			reportError(&allErrors, i, *err)
		}
	}

	return allErrors.Prefix("Config")
}
开发者ID:ericcapricorn,项目名称:kubernetes,代码行数:32,代码来源:config.go

示例3: transformDecodeError

// transformDecodeError adds additional information when a decode fails.
func transformDecodeError(typer runtime.ObjectTyper, baseErr error, into runtime.Object, body []byte) error {
	_, kind, err := typer.ObjectVersionAndKind(into)
	if err != nil {
		return err
	}
	if version, dataKind, err := typer.DataVersionAndKind(body); err == nil && len(dataKind) > 0 {
		return errors.NewBadRequest(fmt.Sprintf("%s in version %s cannot be handled as a %s: %v", dataKind, version, kind, baseErr))
	}
	return errors.NewBadRequest(fmt.Sprintf("the object provided is unrecognized (must be of type %s): %v", kind, baseErr))
}
开发者ID:cjnygard,项目名称:origin,代码行数:11,代码来源:resthandler.go

示例4: objectMetaAndKind

// objectMetaAndKind retrieves kind and ObjectMeta from a runtime object, or returns an error.
func objectMetaAndKind(typer runtime.ObjectTyper, obj runtime.Object) (*api.ObjectMeta, string, error) {
	objectMeta, err := api.ObjectMetaFor(obj)
	if err != nil {
		return nil, "", errors.NewInternalError(err)
	}
	_, kind, err := typer.ObjectVersionAndKind(obj)
	if err != nil {
		return nil, "", errors.NewInternalError(err)
	}
	return objectMeta, kind, nil
}
开发者ID:brorhie,项目名称:panamax-kubernetes-adapter-go,代码行数:12,代码来源:create.go


注:本文中的github.com/GoogleCloudPlatform/kubernetes/pkg/runtime.ObjectTyper.ObjectVersionAndKind方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。