forked from carvel-dev/kapp
/
matchers.go
73 lines (54 loc) · 1.47 KB
/
matchers.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
63
64
65
66
67
68
69
70
71
72
73
package resources
type ResourceMatcher interface {
Matches(Resource) bool
}
type AnyMatcher struct {
Matchers []ResourceMatcher
}
var _ ResourceMatcher = AnyMatcher{}
func (m AnyMatcher) Matches(res Resource) bool {
for _, matcher := range m.Matchers {
if matcher.Matches(res) {
return true
}
}
return false
}
type APIGroupKindMatcher struct {
APIGroup string
Kind string
}
var _ ResourceMatcher = APIGroupKindMatcher{}
func (m APIGroupKindMatcher) Matches(res Resource) bool {
return res.APIGroup() == m.APIGroup && res.Kind() == m.Kind
}
type APIVersionKindMatcher struct {
APIVersion string
Kind string
}
var _ ResourceMatcher = APIVersionKindMatcher{}
func (m APIVersionKindMatcher) Matches(res Resource) bool {
return res.APIVersion() == m.APIVersion && res.Kind() == m.Kind
}
type KindNamespaceNameMatcher struct {
Kind, Namespace, Name string
}
var _ ResourceMatcher = KindNamespaceNameMatcher{}
func (m KindNamespaceNameMatcher) Matches(res Resource) bool {
return res.Kind() == m.Kind && res.Namespace() == m.Namespace && res.Name() == m.Name
}
type AllResourceMatcher struct{}
var _ ResourceMatcher = AllResourceMatcher{}
func (AllResourceMatcher) Matches(Resource) bool { return true }
type AnyResourceMatcher struct {
Matchers []ResourceMatcher
}
var _ ResourceMatcher = AnyResourceMatcher{}
func (m AnyResourceMatcher) Matches(res Resource) bool {
for _, m := range m.Matchers {
if m.Matches(res) {
return true
}
}
return false
}