From c4d5ff4da3d1f89d7f5f8467776b0900bdc5771c Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Mon, 21 Oct 2019 22:13:17 +0200 Subject: [PATCH] feat: add list of known resource types and factory from runtime.Object --- pkg/cmdutil/entity.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pkg/cmdutil/entity.go b/pkg/cmdutil/entity.go index ba67c20..61332fe 100644 --- a/pkg/cmdutil/entity.go +++ b/pkg/cmdutil/entity.go @@ -21,6 +21,23 @@ func (r ResourceType) String() string { return string(r) } +func KnownResourceTypes() []ResourceType { + return []ResourceType{Capability, Component, Link} +} + +func ResourceTypeFor(object runtime.Object) (ResourceType, error) { + if object == nil { + return "", fmt.Errorf("must provide a non-nil runtime.Object") + } + kind := strings.ToLower(object.GetObjectKind().GroupVersionKind().Kind) + for _, t := range KnownResourceTypes() { + if kind == t.String() { + return t, nil + } + } + return "", fmt.Errorf("unknown resource type: %s", kind) +} + type GenericOperationOptions struct { ResourceType ResourceType Name string