github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/internal/controllers/apicmp/delta.go (about) 1 package apicmp 2 3 import ( 4 "fmt" 5 "reflect" 6 7 "k8s.io/apimachinery/pkg/api/resource" 8 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 9 "k8s.io/apimachinery/pkg/conversion" 10 "k8s.io/apimachinery/pkg/fields" 11 "k8s.io/apimachinery/pkg/labels" 12 13 "github.com/tilt-dev/tilt/internal/timecmp" 14 ) 15 16 func Comparators() []interface{} { 17 return []interface{}{ 18 func(a, b resource.Quantity) bool { 19 return a.Cmp(b) == 0 20 }, 21 func(a, b metav1.MicroTime) bool { 22 return timecmp.Equal(a, b) 23 }, 24 func(a, b metav1.Time) bool { 25 return timecmp.Equal(a, b) 26 }, 27 func(a, b labels.Selector) bool { 28 return a.String() == b.String() 29 }, 30 func(a, b fields.Selector) bool { 31 return a.String() == b.String() 32 }, 33 } 34 } 35 36 // A deep equality check to see if a client object and 37 // a server object are different, such that the server object 38 // needs to be updated. 39 var delta = conversion.EqualitiesOrDie(Comparators()...) 40 41 func DeepEqual(a, b interface{}) bool { 42 typeA := reflect.TypeOf(a) 43 typeB := reflect.TypeOf(b) 44 if typeA != typeB { 45 panic(fmt.Sprintf("internal error: comparing incommensurable objects: %T, %T", a, b)) 46 } 47 return delta.DeepEqual(a, b) 48 }