/
resource.go
50 lines (41 loc) · 1.02 KB
/
resource.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package commander
import (
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime/schema"
)
type ResourceMap map[schema.GroupKind]*Resource
type ResourceProvider interface {
Resources() (ResourceMap, error)
}
type Resource struct {
Namespaced bool
Resource string
Gk schema.GroupKind
Gvk schema.GroupVersionKind
Verbs []string
}
func (r Resource) GroupVersion() schema.GroupVersion {
return r.Gvk.GroupVersion()
}
func (r Resource) GroupVersionKind() schema.GroupVersionKind {
return r.Gvk
}
func (r Resource) GroupVersionResource() schema.GroupVersionResource {
return r.GroupVersion().WithResource(r.Resource)
}
func (r Resource) Scope() meta.RESTScope {
if r.Namespaced {
return meta.RESTScopeNamespace
} else {
return meta.RESTScopeRoot
}
}
type ResourceContainer interface {
NamespaceAccessor
Status() StatusReporter
Client() Client
ResourceProvider() ResourceProvider
CommandBuilder() CommandBuilder
CommandExecutor() CommandExecutor
ScreenHandler() ScreenHandler
}