github.com/gocrane/crane@v0.11.0/pkg/utils/schema.go (about)

     1  package utils
     2  
     3  import (
     4  	"k8s.io/apimachinery/pkg/api/meta"
     5  	"k8s.io/apimachinery/pkg/runtime/schema"
     6  )
     7  
     8  func KindForResource(resource string, restMapper meta.RESTMapper) (string, error) {
     9  	singular, err := restMapper.ResourceSingularizer(resource)
    10  	if err != nil {
    11  		return "", err
    12  	}
    13  	fullySpecifiedGVR, groupResource := schema.ParseResourceArg(singular)
    14  	gvk := schema.GroupVersionKind{}
    15  	if fullySpecifiedGVR != nil {
    16  		gvk, err = restMapper.KindFor(*fullySpecifiedGVR)
    17  	}
    18  	if gvk.Empty() {
    19  		gvk, err = restMapper.KindFor(groupResource.WithVersion(""))
    20  	}
    21  
    22  	return gvk.Kind, err
    23  }