diff --git a/staging/src/k8s.io/apiserver/pkg/cel/cidr.go b/staging/src/k8s.io/apiserver/pkg/cel/cidr.go index b785f460def..8e97f63cd74 100644 --- a/staging/src/k8s.io/apiserver/pkg/cel/cidr.go +++ b/staging/src/k8s.io/apiserver/pkg/cel/cidr.go @@ -33,7 +33,7 @@ type CIDR struct { } var ( - CIDRType = cel.ObjectType("net.CIDR") + CIDRType = cel.OpaqueType("net.CIDR") ) // ConvertToNative implements ref.Val.ConvertToNative. diff --git a/staging/src/k8s.io/apiserver/pkg/cel/ip.go b/staging/src/k8s.io/apiserver/pkg/cel/ip.go index 5e9bddce82f..f91c6cb7a86 100644 --- a/staging/src/k8s.io/apiserver/pkg/cel/ip.go +++ b/staging/src/k8s.io/apiserver/pkg/cel/ip.go @@ -33,7 +33,7 @@ type IP struct { } var ( - IPType = cel.ObjectType("net.IP") + IPType = cel.OpaqueType("net.IP") ) // ConvertToNative implements ref.Val.ConvertToNative. diff --git a/staging/src/k8s.io/apiserver/pkg/cel/library/cost.go b/staging/src/k8s.io/apiserver/pkg/cel/library/cost.go index a12a6d6da59..3a30422965c 100644 --- a/staging/src/k8s.io/apiserver/pkg/cel/library/cost.go +++ b/staging/src/k8s.io/apiserver/pkg/cel/library/cost.go @@ -498,19 +498,27 @@ func (l *CostEstimator) EstimateCallCost(function, overloadId string, target *ch rhs := args[1] if lhs.Type().Equal(rhs.Type()) == types.True { t := lhs.Type() - switch t { - case cel.IPType, cel.CIDRType, cel.QuantityType: // O(1) cost equality checks - return &checker.CallEstimate{CostEstimate: checker.CostEstimate{Min: 1, Max: 1}} - case cel.FormatType: - return &checker.CallEstimate{CostEstimate: checker.CostEstimate{Min: 1, Max: cel.MaxFormatSize}.MultiplyByCostFactor(common.StringTraversalCostFactor)} - case cel.URLType: - size := checker.SizeEstimate{Min: 1, Max: 1} - rhSize := rhs.ComputedSize() - lhSize := rhs.ComputedSize() - if rhSize != nil && lhSize != nil { - size = rhSize.Union(*lhSize) + if t.Kind() == types.OpaqueKind { + switch t.TypeName() { + case cel.IPType.TypeName(), cel.CIDRType.TypeName(): + return &checker.CallEstimate{CostEstimate: checker.CostEstimate{Min: 1, Max: 1}} + } + } + if t.Kind() == types.StructKind { + switch t { + case cel.QuantityType: // O(1) cost equality checks + return &checker.CallEstimate{CostEstimate: checker.CostEstimate{Min: 1, Max: 1}} + case cel.FormatType: + return &checker.CallEstimate{CostEstimate: checker.CostEstimate{Min: 1, Max: cel.MaxFormatSize}.MultiplyByCostFactor(common.StringTraversalCostFactor)} + case cel.URLType: + size := checker.SizeEstimate{Min: 1, Max: 1} + rhSize := rhs.ComputedSize() + lhSize := rhs.ComputedSize() + if rhSize != nil && lhSize != nil { + size = rhSize.Union(*lhSize) + } + return &checker.CallEstimate{CostEstimate: checker.CostEstimate{Min: 1, Max: size.Max}.MultiplyByCostFactor(common.StringTraversalCostFactor)} } - return &checker.CallEstimate{CostEstimate: checker.CostEstimate{Min: 1, Max: size.Max}.MultiplyByCostFactor(common.StringTraversalCostFactor)} } } }