本文整理汇总了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
}
示例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")
}
示例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))
}
示例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
}