コード例 #1
0
ファイル: resthandler.go プロジェクト: alexhersh/kubernetes
// transformDecodeError adds additional information when a decode fails.
func transformDecodeError(typer runtime.ObjectTyper, baseErr error, into runtime.Object, body []byte) error {
	objectGroupVersionKind, err := typer.ObjectKind(into)
	if err != nil {
		return err
	}
	if dataGroupVersionKind, err := typer.DataKind(body); err == nil && len(dataGroupVersionKind.Kind) > 0 {
		return errors.NewBadRequest(fmt.Sprintf("%s in version %v cannot be handled as a %s: %v", dataGroupVersionKind.Kind, dataGroupVersionKind.GroupVersion(), objectGroupVersionKind.Kind, baseErr))
	}
	return errors.NewBadRequest(fmt.Sprintf("the object provided is unrecognized (must be of type %s): %v", objectGroupVersionKind.Kind, baseErr))
}
コード例 #2
0
ファイル: resthandler.go プロジェクト: mataihang/kubernetes
// transformDecodeError adds additional information when a decode fails.
func transformDecodeError(typer runtime.ObjectTyper, baseErr error, into runtime.Object, gvk *unversioned.GroupVersionKind) error {
	objGVK, err := typer.ObjectKind(into)
	if err != nil {
		return err
	}
	if gvk != nil && len(gvk.Kind) > 0 {
		return errors.NewBadRequest(fmt.Sprintf("%s in version %q cannot be handled as a %s: %v", gvk.Kind, gvk.Version, objGVK.Kind, baseErr))
	}
	return errors.NewBadRequest(fmt.Sprintf("the object provided is unrecognized (must be of type %s): %v", objGVK.Kind, baseErr))
}
コード例 #3
0
ファイル: create.go プロジェクト: CNDonny/scope
// objectMetaAndKind retrieves kind and ObjectMeta from a runtime object, or returns an error.
func objectMetaAndKind(typer runtime.ObjectTyper, obj runtime.Object) (*api.ObjectMeta, unversioned.GroupVersionKind, error) {
	objectMeta, err := api.ObjectMetaFor(obj)
	if err != nil {
		return nil, unversioned.GroupVersionKind{}, errors.NewInternalError(err)
	}
	kind, err := typer.ObjectKind(obj)
	if err != nil {
		return nil, unversioned.GroupVersionKind{}, errors.NewInternalError(err)
	}
	return objectMeta, kind, nil
}
コード例 #4
0
ファイル: create.go プロジェクト: erinboyd/origin
// 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)
	}
	gvk, err := typer.ObjectKind(obj)
	if err != nil {
		return nil, "", errors.NewInternalError(err)
	}
	return objectMeta, gvk.Kind, nil
}