Skip to content

Commit

Permalink
feat: add list of known resource types and factory from runtime.Object
Browse files Browse the repository at this point in the history
  • Loading branch information
metacosm committed Oct 21, 2019
1 parent 8ae5f60 commit c4d5ff4
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pkg/cmdutil/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c4d5ff4

Please sign in to comment.