This repository has been archived by the owner on May 30, 2020. It is now read-only.
/
util.go
57 lines (51 loc) · 1.52 KB
/
util.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
package appstate
import (
"sort"
"github.com/replicatedhq/kotsadm/operator/pkg/appstate/types"
)
func normalizeStatusInformers(informers []types.StatusInformer, targetNamespace string) (next []types.StatusInformer) {
for _, informer := range informers {
informer.Kind = getResourceKindCommonName(informer.Kind)
if informer.Namespace == "" {
informer.Namespace = targetNamespace
}
next = append(next, informer)
}
return
}
func filterStatusInformersByResourceKind(informers []types.StatusInformer, kind string) (next []types.StatusInformer) {
for _, informer := range informers {
if informer.Kind == kind {
next = append(next, informer)
}
}
return
}
func buildResourceStatesFromStatusInformers(informers []types.StatusInformer) types.ResourceStates {
next := types.ResourceStates{}
for _, informer := range informers {
next = append(next, types.ResourceState{
Kind: informer.Kind,
Name: informer.Name,
Namespace: informer.Namespace,
State: types.StateMissing,
})
}
sort.Sort(next)
return next
}
func resourceStatesApplyNew(resourceStates types.ResourceStates, informers []types.StatusInformer, resourceState types.ResourceState) (next types.ResourceStates, didChange bool) {
for _, r := range resourceStates {
if resourceState.Kind == r.Kind &&
resourceState.Namespace == r.Namespace &&
resourceState.Name == r.Name &&
resourceState.State != r.State {
didChange = true
next = append(next, resourceState)
} else {
next = append(next, r)
}
}
sort.Sort(next)
return
}