-
Notifications
You must be signed in to change notification settings - Fork 0
/
executor_algs.go
70 lines (54 loc) · 1.27 KB
/
executor_algs.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
package executor
import (
"strings"
"github.com/dlclark/regexp2"
core "k8s.io/api/core/v1"
"github.com/dodopizza/stand-schedule-policy-controller/internal/azure"
apis "github.com/dodopizza/stand-schedule-policy-controller/pkg/apis/standschedules/v1"
"github.com/dodopizza/stand-schedule-policy-controller/pkg/util"
)
func FilterAndSortNamespaces(
objects []*core.Namespace,
filter string,
reverse bool,
) []string {
var (
namespaces []string
filters = strings.Split(filter, "|")
)
if reverse {
filters = util.Reverse(filters)
}
for _, f := range filters {
if f == "" {
continue
}
reg, err := regexp2.Compile(f, regexp2.None)
if err != nil {
continue
}
for _, namespace := range objects {
matched, _ := reg.MatchString(namespace.Name)
if matched {
namespaces = append(namespaces, namespace.Name)
}
}
}
return namespaces
}
func FilterAndMergeAzureResources(
result map[int64][]*azure.Resource,
list []*azure.Resource,
filter apis.AzureResource,
) {
reg, err := regexp2.Compile(filter.ResourceNameFilter, regexp2.None)
if err != nil {
return
}
for _, resource := range list {
match, _ := reg.MatchString(resource.GetName())
if match {
result[filter.Priority] = append(result[filter.Priority], resource)
}
}
}