-
Notifications
You must be signed in to change notification settings - Fork 5.1k
/
filtered_resource.go
40 lines (34 loc) · 1011 Bytes
/
filtered_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
package settings
import "github.com/argoproj/argo-cd/v2/util/glob"
type FilteredResource struct {
APIGroups []string `json:"apiGroups,omitempty"`
Kinds []string `json:"kinds,omitempty"`
Clusters []string `json:"clusters,omitempty"`
}
func (r FilteredResource) matchGroup(apiGroup string) bool {
for _, excludedApiGroup := range r.APIGroups {
if glob.Match(excludedApiGroup, apiGroup) {
return true
}
}
return len(r.APIGroups) == 0
}
func (r FilteredResource) matchKind(kind string) bool {
for _, excludedKind := range r.Kinds {
if excludedKind == "*" || excludedKind == kind {
return true
}
}
return len(r.Kinds) == 0
}
func (r FilteredResource) MatchCluster(cluster string) bool {
for _, excludedCluster := range r.Clusters {
if glob.Match(excludedCluster, cluster) {
return true
}
}
return len(r.Clusters) == 0
}
func (r FilteredResource) Match(apiGroup, kind, cluster string) bool {
return r.matchGroup(apiGroup) && r.matchKind(kind) && r.MatchCluster(cluster)
}