本文整理匯總了Golang中k8s/io/apimachinery/pkg/runtime/schema.GroupVersionKind.GroupKind方法的典型用法代碼示例。如果您正苦於以下問題:Golang GroupVersionKind.GroupKind方法的具體用法?Golang GroupVersionKind.GroupKind怎麽用?Golang GroupVersionKind.GroupKind使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類k8s/io/apimachinery/pkg/runtime/schema.GroupVersionKind
的用法示例。
在下文中一共展示了GroupVersionKind.GroupKind方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: checkNamespace
// checkNamespace makes sure that the scope of gvk matches ns. It
// returns an error if namespace is empty but gvk is a namespaced
// kind, or if ns is non-empty and gvk is a namespaced kind.
func checkNamespace(gvk schema.GroupVersionKind, ns string) error {
group, err := api.Registry.Group(gvk.Group)
if err != nil {
return err
}
mapping, err := group.RESTMapper.RESTMapping(gvk.GroupKind(), gvk.Version)
if err != nil {
return err
}
switch mapping.Scope.Name() {
case meta.RESTScopeNameRoot:
if ns != "" {
return fmt.Errorf("namespace specified for a non-namespaced kind %s", gvk)
}
case meta.RESTScopeNameNamespace:
if ns == "" {
// Skipping this check for Events, since
// controllers emit events that have no namespace,
// even though Event is a namespaced resource.
if gvk.Kind != "Event" {
return fmt.Errorf("no namespace specified for a namespaced kind %s", gvk)
}
}
}
return nil
}
示例2: mappingFor
// mappingFor returns the RESTMapping for the Kind referenced by the resource.
// prefers a fully specified GroupVersionResource match. If we don't have one match on GroupResource
func (b *Builder) mappingFor(resourceArg string) (*meta.RESTMapping, error) {
fullySpecifiedGVR, groupResource := schema.ParseResourceArg(resourceArg)
gvk := schema.GroupVersionKind{}
if fullySpecifiedGVR != nil {
gvk, _ = b.mapper.KindFor(*fullySpecifiedGVR)
}
if gvk.Empty() {
var err error
gvk, err = b.mapper.KindFor(groupResource.WithVersion(""))
if err != nil {
return nil, err
}
}
return b.mapper.RESTMapping(gvk.GroupKind(), gvk.Version)
}