@@ -25,7 +25,6 @@ import (
25
25
"github.com/google/cel-go/common/types/ref"
26
26
"github.com/google/cel-go/common/types/traits"
27
27
"math"
28
- "strings"
29
28
30
29
"k8s.io/apiserver/pkg/cel"
31
30
)
@@ -201,7 +200,7 @@ func (l *CostEstimator) CallCost(function, overloadId string, args []ref.Val, re
201
200
}
202
201
case "validate" :
203
202
if len (args ) >= 2 {
204
- format , isFormat := args [0 ].Value ().(* cel.Format )
203
+ format , isFormat := args [0 ].Value ().(cel.Format )
205
204
if isFormat {
206
205
strSize := actualSize (args [1 ])
207
206
@@ -243,13 +242,14 @@ func (l *CostEstimator) CallCost(function, overloadId string, args []ref.Val, re
243
242
case * cel.Quantity , cel.Quantity ,
244
243
* cel.IP , cel.IP ,
245
244
* cel.CIDR , cel.CIDR ,
246
- * cel.Format , // Formats have a small max size. Format takes pointer receiver.
245
+ * cel.Format , cel. Format , // Formats have a small max size. Format takes pointer receiver.
247
246
* cel.URL , cel.URL , // TODO: Computing the actual cost is expensive, and changing this would be a breaking change
247
+ * cel.Semver , cel.Semver ,
248
248
* authorizerVal , authorizerVal , * pathCheckVal , pathCheckVal , * groupCheckVal , groupCheckVal ,
249
249
* resourceCheckVal , resourceCheckVal , * decisionVal , decisionVal :
250
250
return & unitCost
251
251
default :
252
- if panicOnUnknown && isKubernetesType ( lhs .Type ()) {
252
+ if panicOnUnknown && lhs . Type () != nil && isRegisteredType ( lhs .Type (). TypeName ()) {
253
253
panic (fmt .Errorf ("CallCost: unhandled equality for Kubernetes type %T" , lhs ))
254
254
}
255
255
}
@@ -509,7 +509,7 @@ func (l *CostEstimator) EstimateCallCost(function, overloadId string, target *ch
509
509
if t .Kind () == types .StructKind {
510
510
switch t {
511
511
case cel .QuantityType , AuthorizerType , PathCheckType , // O(1) cost equality checks
512
- GroupCheckType , ResourceCheckType , DecisionType :
512
+ GroupCheckType , ResourceCheckType , DecisionType , cel . SemverType :
513
513
return & checker.CallEstimate {CostEstimate : checker.CostEstimate {Min : 1 , Max : 1 }}
514
514
case cel .FormatType :
515
515
return & checker.CallEstimate {CostEstimate : checker.CostEstimate {Min : 1 , Max : cel .MaxFormatSize }.MultiplyByCostFactor (common .StringTraversalCostFactor )}
@@ -523,7 +523,7 @@ func (l *CostEstimator) EstimateCallCost(function, overloadId string, target *ch
523
523
return & checker.CallEstimate {CostEstimate : checker.CostEstimate {Min : 1 , Max : size .Max }.MultiplyByCostFactor (common .StringTraversalCostFactor )}
524
524
}
525
525
}
526
- if panicOnUnknown && isKubernetesType ( t ) {
526
+ if panicOnUnknown && isRegisteredType ( t . TypeName () ) {
527
527
panic (fmt .Errorf ("EstimateCallCost: unhandled equality for Kubernetes type %v" , t ))
528
528
}
529
529
}
@@ -632,17 +632,3 @@ func traversalCost(v ref.Val) uint64 {
632
632
return 1
633
633
}
634
634
}
635
-
636
- // isKubernetesType returns ture if a type is type defined by Kubernetes,
637
- // as identified by opaque or struct types with a "kubernetes." prefix.
638
- func isKubernetesType (t ref.Type ) bool {
639
- if tt , ok := t .(* types.Type ); ok {
640
- switch tt .Kind () {
641
- case types .OpaqueKind , types .StructKind :
642
- return strings .HasPrefix (tt .TypeName (), "kubernetes." )
643
- default :
644
- return false
645
- }
646
- }
647
- return false
648
- }
0 commit comments