diff --git a/staging/src/k8s.io/apiserver/pkg/cel/mutation/common/val.go b/staging/src/k8s.io/apiserver/pkg/cel/mutation/common/val.go index 0055623dda8..16cca9dd261 100644 --- a/staging/src/k8s.io/apiserver/pkg/cel/mutation/common/val.go +++ b/staging/src/k8s.io/apiserver/pkg/cel/mutation/common/val.go @@ -77,7 +77,10 @@ func (v *ObjectVal) ConvertToType(typeValue ref.Type) ref.Val { // Equal returns true if the `other` value has the same type and content as the implementing struct. func (v *ObjectVal) Equal(other ref.Val) ref.Val { - return types.Bool(v == other) + if rhs, ok := other.(*ObjectVal); ok { + return types.Bool(reflect.DeepEqual(v.fields, rhs.fields)) + } + return types.Bool(false) } // Type returns the TypeValue of the value. diff --git a/staging/src/k8s.io/apiserver/pkg/cel/mutation/unstructured/typeresolver_test.go b/staging/src/k8s.io/apiserver/pkg/cel/mutation/unstructured/typeresolver_test.go index d249d53d3f2..b46fc273eaf 100644 --- a/staging/src/k8s.io/apiserver/pkg/cel/mutation/unstructured/typeresolver_test.go +++ b/staging/src/k8s.io/apiserver/pkg/cel/mutation/unstructured/typeresolver_test.go @@ -101,6 +101,11 @@ func TestTypeProvider(t *testing.T) { }.intList.sum()`, expectedValue: int64(6), }, + { + name: "equality check", + expression: "Object{spec: Object.spec{replicas: 3}} == Object{spec: Object.spec{replicas: 1 + 2}}", + expectedValue: true, + }, } { t.Run(tc.name, func(t *testing.T) { _, option := mutation.NewTypeProviderAndEnvOption(&TypeResolver{})