-
Notifications
You must be signed in to change notification settings - Fork 302
/
delta.go
48 lines (42 loc) · 1.12 KB
/
delta.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
package apicmp
import (
"fmt"
"reflect"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/conversion"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
"github.com/tilt-dev/tilt/internal/timecmp"
)
func Comparators() []interface{} {
return []interface{}{
func(a, b resource.Quantity) bool {
return a.Cmp(b) == 0
},
func(a, b metav1.MicroTime) bool {
return timecmp.Equal(a, b)
},
func(a, b metav1.Time) bool {
return timecmp.Equal(a, b)
},
func(a, b labels.Selector) bool {
return a.String() == b.String()
},
func(a, b fields.Selector) bool {
return a.String() == b.String()
},
}
}
// A deep equality check to see if a client object and
// a server object are different, such that the server object
// needs to be updated.
var delta = conversion.EqualitiesOrDie(Comparators()...)
func DeepEqual(a, b interface{}) bool {
typeA := reflect.TypeOf(a)
typeB := reflect.TypeOf(b)
if typeA != typeB {
panic(fmt.Sprintf("internal error: comparing incommensurable objects: %T, %T", a, b))
}
return delta.DeepEqual(a, b)
}