forked from openshift/library-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.go
62 lines (50 loc) · 1.4 KB
/
interface.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
51
52
53
54
55
56
57
58
59
60
61
62
package resourcegraph
import (
"fmt"
"github.com/gonum/graph"
)
func NewResources() Resources {
return &resourcesImpl{}
}
func NewResource(coordinates ResourceCoordinates) Resource {
return &simpleSource{coordinates: coordinates}
}
func NewConfigMap(namespace, name string) Resource {
return NewResource(NewCoordinates("", "configmaps", namespace, name))
}
func NewSecret(namespace, name string) Resource {
return NewResource(NewCoordinates("", "secrets", namespace, name))
}
func NewOperator(name string) Resource {
return NewResource(NewCoordinates("config.openshift.io", "clusteroperators", "", name))
}
func NewConfig(resource string) Resource {
return NewResource(NewCoordinates("config.openshift.io", resource, "", "cluster"))
}
type Resource interface {
Add(resources Resources) Resource
From(Resource) Resource
Note(note string) Resource
fmt.Stringer
GetNote() string
Coordinates() ResourceCoordinates
Sources() []Resource
Dump(indentDepth int) []string
DumpSources(indentDepth int) []string
}
type Resources interface {
Add(resource Resource)
Dump() []string
AllResources() []Resource
Resource(coordinates ResourceCoordinates) Resource
Roots() []Resource
NewGraph() graph.Directed
}
func NewCoordinates(group, resource, namespace, name string) ResourceCoordinates {
return ResourceCoordinates{
Group: group,
Resource: resource,
Namespace: namespace,
Name: name,
}
}