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 infra
import (
"maps"
"reflect"
"slices"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
exposurev1alpha1 "github.com/johnandersen777/socialweb-computer-kcp/api/exposure/v1alpha1"
"github.com/johnandersen777/socialweb-computer-kcp/api/v1alpha1"
)
func metaChanged(old, new metav1.Object) bool {
return old.GetGeneration() != new.GetGeneration() || !maps.Equal(old.GetLabels(), new.GetLabels()) ||
old.GetDeletionTimestamp().IsZero() != new.GetDeletionTimestamp().IsZero() ||
!reflect.DeepEqual(old.GetOwnerReferences(), new.GetOwnerReferences())
}
type contractView struct {
phase v1alpha1.ComputeContractPhase
message string
receipt string
winner string
}
func viewOfContract(cc *v1alpha1.ComputeContract) contractView {
out := contractView{phase: cc.Status.Phase, message: cc.Status.Message}
if state := cc.Status.Contract; state != nil {
out.receipt = state.ReceiptURI
if state.Winner != nil {
out.winner = state.Winner.DID
}
}
return out
}
func contractChanged(old, new *v1alpha1.ComputeContract) bool {
return metaChanged(old, new) || viewOfContract(old) != viewOfContract(new)
}
type recordAt struct {
uri string
cid string
}
func watchedRecords(w *v1alpha1.AtprotoRecordWatch) []recordAt {
out := make([]recordAt, 0, len(w.Status.Records))
for _, rec := range w.Status.Records {
out = append(out, recordAt{uri: rec.URI, cid: rec.Cid})
}
return out
}
func recordWatchChanged(old, new *v1alpha1.AtprotoRecordWatch) bool {
return metaChanged(old, new) || !slices.Equal(watchedRecords(old), watchedRecords(new)) || !slices.Equal(old.Status.Deleted, new.Status.Deleted)
}
func linkAccepted(link *exposurev1alpha1.ComponentLink) bool {
if link.Status.ObservedGeneration < link.Generation {
return false
}
return meta.IsStatusConditionTrue(link.Status.Conditions, exposurev1alpha1.ComponentLinkConditionAccepted)
}
func linkChanged(old, new *exposurev1alpha1.ComponentLink) bool {
return metaChanged(old, new) || old.Status.ObservedGeneration != new.Status.ObservedGeneration || linkAccepted(old) != linkAccepted(new)
}