mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
20 lines
467 B
Go
20 lines
467 B
Go
package gvk
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
)
|
|
|
|
func Detect(obj []byte) (schema.GroupVersionKind, bool, error) {
|
|
partial := v1.PartialObjectMetadata{}
|
|
if err := json.Unmarshal(obj, &partial); err != nil {
|
|
return schema.GroupVersionKind{}, false, err
|
|
}
|
|
|
|
result := partial.GetObjectKind().GroupVersionKind()
|
|
ok := result.Kind != "" && result.Version != ""
|
|
return result, ok, nil
|
|
}
|