Fix CEL equality bug for structs will nil field not marked as omitempty
Kubernetes-commit: 66b8a8427cf0be6f6a87ea3384e7213696bdfd4c
This commit is contained in:
parent
eeced267ad
commit
c199f9d392
|
@ -318,6 +318,16 @@ func TestToValue(t *testing.T) {
|
||||||
"s2": struct2,
|
"s2": struct2,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "compare: identical complex structs",
|
||||||
|
expression: "c1 == c2",
|
||||||
|
activation: map[string]typedValue{"c1": complex1, "c2": complex1Again},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "compare: different complex structs",
|
||||||
|
expression: "c1 != c2",
|
||||||
|
activation: map[string]typedValue{"c1": complex1, "c2": complex2},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "compare: struct and pointer to identical struct",
|
name: "compare: struct and pointer to identical struct",
|
||||||
expression: "s1 == s1_ptr",
|
expression: "s1 == s1_ptr",
|
||||||
|
|
|
@ -598,13 +598,17 @@ func (t *unstructuredMap) Equal(other ref.Val) ref.Val {
|
||||||
if t.Size() != oMap.Size() {
|
if t.Size() != oMap.Size() {
|
||||||
return types.False
|
return types.False
|
||||||
}
|
}
|
||||||
|
|
||||||
for key, value := range t.value {
|
for key, value := range t.value {
|
||||||
if propSchema, ok := t.propSchema(key); ok {
|
if _, ok := t.propSchema(key); ok {
|
||||||
ov, found := oMap.Find(types.String(key))
|
v, found := t.Find(types.String(key))
|
||||||
if !found {
|
ov, oFound := oMap.Find(types.String(key))
|
||||||
|
if found != oFound {
|
||||||
return types.False
|
return types.False
|
||||||
}
|
}
|
||||||
v := UnstructuredToVal(value, propSchema)
|
if !found {
|
||||||
|
continue
|
||||||
|
}
|
||||||
vEq := v.Equal(ov)
|
vEq := v.Equal(ov)
|
||||||
if vEq != types.True {
|
if vEq != types.True {
|
||||||
return vEq // either false or error
|
return vEq // either false or error
|
||||||
|
|
Loading…
Reference in New Issue