1
0
mirror of https://github.com/rancher/steve.git synced 2025-05-08 16:07:21 +00:00
steve/pkg/resources/schema/converter/k8stonorman.go

38 lines
879 B
Go
Raw Normal View History

2019-08-13 23:36:03 +00:00
package converter
import (
"fmt"
"github.com/rancher/norman/pkg/types"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/discovery"
)
func gvkToSchemaID(gvk schema.GroupVersionKind) string {
if gvk.Group == "" {
2019-08-14 02:00:29 +00:00
return fmt.Sprintf("core.%s.%s", gvk.Version, gvk.Kind)
2019-08-13 23:36:03 +00:00
}
2019-08-14 02:00:29 +00:00
return fmt.Sprintf("%s.%s.%s", gvk.Group, gvk.Version, gvk.Kind)
2019-08-13 23:36:03 +00:00
}
func GVRToSchemaID(gvk schema.GroupVersionResource) string {
if gvk.Group == "" {
2019-08-14 02:00:29 +00:00
return fmt.Sprintf("core.%s.%s", gvk.Version, gvk.Resource)
2019-08-13 23:36:03 +00:00
}
2019-08-14 02:00:29 +00:00
return fmt.Sprintf("%s.%s.%s", gvk.Group, gvk.Version, gvk.Resource)
2019-08-13 23:36:03 +00:00
}
func ToSchemas(client discovery.DiscoveryInterface) (map[string]*types.Schema, error) {
result := map[string]*types.Schema{}
if err := AddOpenAPI(client, result); err != nil {
return nil, err
}
if err := AddDiscovery(client, result); err != nil {
return nil, err
}
return result, nil
}