From bcececadfb5b7deb3f6ecb253a73ea98a2fdd80c Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Wed, 17 Jul 2024 19:36:36 +0200 Subject: [PATCH] CEL: add QuantityDeclType Most functions in k8s.io/apiserver/pkg/cel work with DeclType for type definitions, which made the existing QuantityType unusable with them. The new QuantityDeclType fills that gap. --- staging/src/k8s.io/apiserver/pkg/cel/types.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/staging/src/k8s.io/apiserver/pkg/cel/types.go b/staging/src/k8s.io/apiserver/pkg/cel/types.go index bd14e169744..53832d7843a 100644 --- a/staging/src/k8s.io/apiserver/pkg/cel/types.go +++ b/staging/src/k8s.io/apiserver/pkg/cel/types.go @@ -28,6 +28,7 @@ import ( exprpb "google.golang.org/genproto/googleapis/api/expr/v1alpha1" "google.golang.org/protobuf/proto" + "k8s.io/apimachinery/pkg/api/resource" ) const ( @@ -576,6 +577,10 @@ var ( // labeled as Timestamp will necessarily have the same MinSerializedSize. TimestampType = NewSimpleTypeWithMinSize("timestamp", cel.TimestampType, types.Timestamp{Time: time.Time{}}, JSONDateSize) + // QuantityDeclType wraps a [QuantityType] and makes it usable with functions that expect + // a [DeclType]. + QuantityDeclType = NewSimpleTypeWithMinSize("quantity", QuantityType, Quantity{Quantity: resource.NewQuantity(0, resource.DecimalSI)}, 8) + // UintType is equivalent to the CEL 'uint' type. UintType = NewSimpleTypeWithMinSize("uint", cel.UintType, types.Uint(0), 1)