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
This commit is contained in:
gzb1128
2026-03-24 16:09:26 +08:00
committed by Kubernetes Publisher
parent 224d0b9220
commit 6fd7c180ef
3 changed files with 30 additions and 3 deletions

View File

@@ -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:

View File

@@ -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:

View File

@@ -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: