本文整理匯總了Golang中k8s/io/kubernetes/pkg/api/unversioned.GroupVersionKind.Version方法的典型用法代碼示例。如果您正苦於以下問題:Golang GroupVersionKind.Version方法的具體用法?Golang GroupVersionKind.Version怎麽用?Golang GroupVersionKind.Version使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類k8s/io/kubernetes/pkg/api/unversioned.GroupVersionKind
的用法示例。
在下文中一共展示了GroupVersionKind.Version方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Kind
func (o objects) Kind(kind unversioned.GroupVersionKind, name string) (runtime.Object, error) {
// TODO our test clients deal in internal versions. We need to plumb that knowledge down here
// we might do this via an extra function to the scheme to allow getting internal group versions
// I'm punting for now
kind.Version = ""
empty, _ := o.scheme.New(kind)
nilValue := reflect.Zero(reflect.TypeOf(empty)).Interface().(runtime.Object)
arr, ok := o.types[kind.Kind]
if !ok {
if strings.HasSuffix(kind.Kind, "List") {
itemKind := kind.Kind[:len(kind.Kind)-4]
arr, ok := o.types[itemKind]
if !ok {
return empty, nil
}
out, err := o.scheme.New(kind)
if err != nil {
return nilValue, err
}
if err := meta.SetList(out, arr); err != nil {
return nilValue, err
}
if out, err = o.scheme.Copy(out); err != nil {
return nilValue, err
}
return out, nil
}
return nilValue, errors.NewNotFound(unversioned.GroupResource{Group: kind.Group, Resource: kind.Kind}, name)
}
index := o.last[kind.Kind]
if index >= len(arr) {
index = len(arr) - 1
}
if index < 0 {
return nilValue, errors.NewNotFound(unversioned.GroupResource{Group: kind.Group, Resource: kind.Kind}, name)
}
out, err := o.scheme.Copy(arr[index])
if err != nil {
return nilValue, err
}
o.last[kind.Kind] = index + 1
if status, ok := out.(*unversioned.Status); ok {
if status.Details != nil {
status.Details.Kind = kind.Kind
}
if status.Status != unversioned.StatusSuccess {
return nilValue, &errors.StatusError{ErrStatus: *status}
}
}
return out, nil
}
示例2: Kind
func (o objects) Kind(kind unversioned.GroupVersionKind, name string) (runtime.Object, error) {
if len(kind.Version) == 0 {
kind.Version = runtime.APIVersionInternal
}
empty, err := o.scheme.New(kind)
nilValue := reflect.Zero(reflect.TypeOf(empty)).Interface().(runtime.Object)
arr, ok := o.types[kind.Kind]
if !ok {
if strings.HasSuffix(kind.Kind, "List") {
itemKind := kind.Kind[:len(kind.Kind)-4]
arr, ok := o.types[itemKind]
if !ok {
return empty, nil
}
out, err := o.scheme.New(kind)
if err != nil {
return nilValue, err
}
if err := meta.SetList(out, arr); err != nil {
return nilValue, err
}
if out, err = o.scheme.Copy(out); err != nil {
return nilValue, err
}
return out, nil
}
return nilValue, errors.NewNotFound(unversioned.GroupResource{Group: kind.Group, Resource: kind.Kind}, name)
}
index := o.last[kind.Kind]
if index >= len(arr) {
index = len(arr) - 1
}
if index < 0 {
return nilValue, errors.NewNotFound(unversioned.GroupResource{Group: kind.Group, Resource: kind.Kind}, name)
}
out, err := o.scheme.Copy(arr[index])
if err != nil {
return nilValue, err
}
o.last[kind.Kind] = index + 1
if status, ok := out.(*unversioned.Status); ok {
if status.Details != nil {
status.Details.Kind = kind.Kind
}
if status.Status != unversioned.StatusSuccess {
return nilValue, &errors.StatusError{ErrStatus: *status}
}
}
return out, nil
}
示例3: copyKindDefaults
// copyKindDefaults defaults dst to the value in src if dst does not have a value set.
func copyKindDefaults(dst, src *unversioned.GroupVersionKind) {
if src == nil {
return
}
// apply kind and version defaulting from provided default
if len(dst.Kind) == 0 {
dst.Kind = src.Kind
}
if len(dst.Version) == 0 && len(src.Version) > 0 {
dst.Group = src.Group
dst.Version = src.Version
}
}
示例4: registerResourceHandlers
func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storage, ws *restful.WebService, proxyHandler http.Handler) (*unversioned.APIResource, error) {
admit := a.group.Admit
context := a.group.Context
optionsExternalVersion := a.group.GroupVersion
if a.group.OptionsExternalVersion != nil {
optionsExternalVersion = *a.group.OptionsExternalVersion
}
var resource, subresource string
switch parts := strings.Split(path, "/"); len(parts) {
case 2:
resource, subresource = parts[0], parts[1]
case 1:
resource = parts[0]
default:
// TODO: support deeper paths
return nil, fmt.Errorf("api_installer allows only one or two segment paths (resource or resource/subresource)")
}
hasSubresource := len(subresource) > 0
object := storage.New()
fqKinds, err := a.group.Typer.ObjectKinds(object)
if err != nil {
return nil, err
}
// a given go type can have multiple potential fully qualified kinds. Find the one that corresponds with the group
// we're trying to register here
fqKindToRegister := unversioned.GroupVersionKind{}
for _, fqKind := range fqKinds {
if fqKind.Group == a.group.GroupVersion.Group {
fqKindToRegister = fqKind
break
}
// TODO This keeps it doing what it was doing before, but it doesn't feel right.
if fqKind.Group == extensions.GroupName && fqKind.Kind == "ThirdPartyResourceData" {
fqKindToRegister = fqKind
fqKindToRegister.Group = a.group.GroupVersion.Group
fqKindToRegister.Version = a.group.GroupVersion.Version
}
}
if fqKindToRegister.IsEmpty() {
return nil, fmt.Errorf("unable to locate fully qualified kind for %v: found %v when registering for %v", reflect.TypeOf(object), fqKinds, a.group.GroupVersion)
}
kind := fqKindToRegister.Kind
versionedPtr, err := a.group.Creater.New(a.group.GroupVersion.WithKind(kind))
if err != nil {
return nil, err
}
versionedObject := indirectArbitraryPointer(versionedPtr)
mapping, err := a.group.Mapper.RESTMapping(fqKindToRegister.GroupKind(), a.group.GroupVersion.Version)
if err != nil {
return nil, err
}
// subresources must have parent resources, and follow the namespacing rules of their parent
if hasSubresource {
parentStorage, ok := a.group.Storage[resource]
if !ok {
return nil, fmt.Errorf("subresources can only be declared when the parent is also registered: %s needs %s", path, resource)
}
parentObject := parentStorage.New()
parentFQKinds, err := a.group.Typer.ObjectKinds(parentObject)
if err != nil {
return nil, err
}
// a given go type can have multiple potential fully qualified kinds. Find the one that corresponds with the group
// we're trying to register here
parentFQKindToRegister := unversioned.GroupVersionKind{}
for _, fqKind := range parentFQKinds {
if fqKind.Group == a.group.GroupVersion.Group {
parentFQKindToRegister = fqKind
break
}
}
if parentFQKindToRegister.IsEmpty() {
return nil, fmt.Errorf("unable to locate fully qualified kind for %v: found %v when registering for %v", reflect.TypeOf(object), fqKinds, a.group.GroupVersion)
}
parentMapping, err := a.group.Mapper.RESTMapping(parentFQKindToRegister.GroupKind(), a.group.GroupVersion.Version)
if err != nil {
return nil, err
}
mapping.Scope = parentMapping.Scope
}
// what verbs are supported by the storage, used to know what verbs we support per path
creater, isCreater := storage.(rest.Creater)
namedCreater, isNamedCreater := storage.(rest.NamedCreater)
lister, isLister := storage.(rest.Lister)
getter, isGetter := storage.(rest.Getter)
getterWithOptions, isGetterWithOptions := storage.(rest.GetterWithOptions)
deleter, isDeleter := storage.(rest.Deleter)
gracefulDeleter, isGracefulDeleter := storage.(rest.GracefulDeleter)
collectionDeleter, isCollectionDeleter := storage.(rest.CollectionDeleter)
//.........這裏部分代碼省略.........