From 6fd7c180efb341b8ba3aab4ab7e3cb0b03986ede Mon Sep 17 00:00:00 2001 From: gzb1128 <591605936@qq.com> Date: Tue, 24 Mar 2026 16:09:26 +0800 Subject: [PATCH] DRA: add hint for CEL "no such key" errors When CEL expressions access non-existent map keys, add a helpful hint suggesting optional chaining (.? followed by orValue()) or has() macro. Kubernetes-commit: 5e2d5b9a621109bd89f2dbc4092e0123ab500c85 --- applyconfigurations/resource/v1/celdeviceselector.go | 11 ++++++++++- .../resource/v1beta1/celdeviceselector.go | 11 ++++++++++- .../resource/v1beta2/celdeviceselector.go | 11 ++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/applyconfigurations/resource/v1/celdeviceselector.go b/applyconfigurations/resource/v1/celdeviceselector.go index 15ec20da4..d5ca19905 100644 --- a/applyconfigurations/resource/v1/celdeviceselector.go +++ b/applyconfigurations/resource/v1/celdeviceselector.go @@ -33,7 +33,7 @@ type CELDeviceSelectorApplyConfiguration struct { // - driver (string): the name of the driver which defines this device. // - attributes (map[string]object): the device's attributes, grouped by prefix // (e.g. device.attributes["dra.example.com"] evaluates to an object with all - // of the attributes which were prefixed by "dra.example.com". + // of the attributes which were prefixed by "dra.example.com"). // - capacity (map[string]object): the device's capacities, grouped by prefix. // - allowMultipleAllocations (bool): the allowMultipleAllocations property of the device // (v1.34+ with the DRAConsumableCapacity feature enabled). @@ -66,6 +66,15 @@ type CELDeviceSelectorApplyConfiguration struct { // A robust expression should check for the existence of attributes // before referencing them. // + // Common errors: + // - "no such key": Use optional chaining (.? followed by orValue()) + // or guarding the check with has() for optional fields. + // See CEL Optional Types for details: + // https://pkg.go.dev/github.com/google/cel-go@v0.17.4/cel#OptionalTypes + // + // For more CEL expression syntax and examples, see: + // https://kubernetes.io/docs/reference/using-api/cel/ + // // For ease of use, the cel.bind() function is enabled, and can be used // to simplify expressions that access multiple attributes with the // same domain. For example: diff --git a/applyconfigurations/resource/v1beta1/celdeviceselector.go b/applyconfigurations/resource/v1beta1/celdeviceselector.go index ba65467ae..40663836d 100644 --- a/applyconfigurations/resource/v1beta1/celdeviceselector.go +++ b/applyconfigurations/resource/v1beta1/celdeviceselector.go @@ -33,7 +33,7 @@ type CELDeviceSelectorApplyConfiguration struct { // - driver (string): the name of the driver which defines this device. // - attributes (map[string]object): the device's attributes, grouped by prefix // (e.g. device.attributes["dra.example.com"] evaluates to an object with all - // of the attributes which were prefixed by "dra.example.com". + // of the attributes which were prefixed by "dra.example.com"). // - capacity (map[string]object): the device's capacities, grouped by prefix. // - allowMultipleAllocations (bool): the allowMultipleAllocations property of the device // (v1.34+ with the DRAConsumableCapacity feature enabled). @@ -66,6 +66,15 @@ type CELDeviceSelectorApplyConfiguration struct { // A robust expression should check for the existence of attributes // before referencing them. // + // Common errors: + // - "no such key": Use optional chaining (.? followed by orValue()) + // or guarding the check with has() for optional fields. + // See CEL Optional Types for details: + // https://pkg.go.dev/github.com/google/cel-go@v0.17.4/cel#OptionalTypes + // + // For more CEL expression syntax and examples, see: + // https://kubernetes.io/docs/reference/using-api/cel/ + // // For ease of use, the cel.bind() function is enabled, and can be used // to simplify expressions that access multiple attributes with the // same domain. For example: diff --git a/applyconfigurations/resource/v1beta2/celdeviceselector.go b/applyconfigurations/resource/v1beta2/celdeviceselector.go index a184590eb..73485f502 100644 --- a/applyconfigurations/resource/v1beta2/celdeviceselector.go +++ b/applyconfigurations/resource/v1beta2/celdeviceselector.go @@ -33,7 +33,7 @@ type CELDeviceSelectorApplyConfiguration struct { // - driver (string): the name of the driver which defines this device. // - attributes (map[string]object): the device's attributes, grouped by prefix // (e.g. device.attributes["dra.example.com"] evaluates to an object with all - // of the attributes which were prefixed by "dra.example.com". + // of the attributes which were prefixed by "dra.example.com"). // - capacity (map[string]object): the device's capacities, grouped by prefix. // - allowMultipleAllocations (bool): the allowMultipleAllocations property of the device // (v1.34+ with the DRAConsumableCapacity feature enabled). @@ -66,6 +66,15 @@ type CELDeviceSelectorApplyConfiguration struct { // A robust expression should check for the existence of attributes // before referencing them. // + // Common errors: + // - "no such key": Use optional chaining (.? followed by orValue()) + // or guarding the check with has() for optional fields. + // See CEL Optional Types for details: + // https://pkg.go.dev/github.com/google/cel-go@v0.17.4/cel#OptionalTypes + // + // For more CEL expression syntax and examples, see: + // https://kubernetes.io/docs/reference/using-api/cel/ + // // For ease of use, the cel.bind() function is enabled, and can be used // to simplify expressions that access multiple attributes with the // same domain. For example: