diff --git a/internal/schemas/generator/go.go b/internal/schemas/generator/go.go index 95b99e01..c57784e8 100644 --- a/internal/schemas/generator/go.go +++ b/internal/schemas/generator/go.go @@ -290,6 +290,7 @@ func (g goGenerator) GenerateFromCRD(_ context.Context, fromFS afero.Fs, _ runne // Generate models for the non-k8s schemas. for _, oapi := range openAPIs { code, err := generateGo(oapi.spec, oapi.version, + goRemoveValidationOnlyCombinators, goRenameTypes, goRenameEnums, goReplaceNumberWithInt, @@ -369,6 +370,7 @@ func (g goGenerator) generateSharedK8sPackage(schemaFS afero.Fs, pkg string, sch } code, err := generateGo(pkgSpec, goPkg.version, + goRemoveValidationOnlyCombinators, goRenameTypes, goRenameEnums, goReplaceNumberWithInt, @@ -739,6 +741,16 @@ func goSchemaPath(group, kind, version string) string { switch group { case "apps", k8sPkgNameAutoscaling, "batch", "policy": return filepath.Join("io", "k8s", group, version, strings.ToLower(kind)+".go") + case "resource.k8s.io": + // The resource.k8s.io group (dynamic resource allocation) would + // collide with the shared apimachinery Quantity package at + // io/k8s/resource/v1, so it lives under io/k8s/api/resource instead, + // mirroring the upstream k8s.io/api/resource layout. + return filepath.Join("io", "k8s", "api", "resource", version, strings.ToLower(kind)+".go") + case "resource.apimachinery.k8s.io": + // Pseudo-group for the shared apimachinery Quantity package; it keeps + // its historical path at io/k8s/resource/v1. + return filepath.Join("io", "k8s", "resource", version, strings.ToLower(kind)+".go") } path := strings.Split(group, ".") @@ -868,6 +880,85 @@ func goRetypeSchema(schema *spec.Schema, oldType, newType string) { } } +// goRemoveValidationOnlyCombinators removes anyOf/oneOf combinators that carry +// no structural type information. Kubernetes structural schemas allow these +// junctors only for validation (e.g. "exactly one of endpointSelector and +// nodeSelector must be set"), where each variant contains only `required` +// constraints and empty property schemas. oapi-codegen generates a union +// member type named for each variant, so a schema with both +// anyOf and oneOf produces colliding type names (two 0). The +// variants don't affect the generated Go structs, so we drop them. +// Combinators with typed variants (e.g. x-kubernetes-int-or-string's +// anyOf: [{type: integer}, {type: string}]) are kept. +func goRemoveValidationOnlyCombinators(s *spec3.OpenAPI) { + for _, schema := range s.Components.Schemas { + goRemoveSchemaValidationOnlyCombinators(schema) + } +} + +func goRemoveSchemaValidationOnlyCombinators(schema *spec.Schema) { + if schema == nil { + return + } + + if goCombinatorIsValidationOnly(schema.AnyOf) { + schema.AnyOf = nil + } + if goCombinatorIsValidationOnly(schema.OneOf) { + schema.OneOf = nil + } + + for i := range schema.AllOf { + goRemoveSchemaValidationOnlyCombinators(&schema.AllOf[i]) + } + for i := range schema.AnyOf { + goRemoveSchemaValidationOnlyCombinators(&schema.AnyOf[i]) + } + for i := range schema.OneOf { + goRemoveSchemaValidationOnlyCombinators(&schema.OneOf[i]) + } + for name, prop := range schema.Properties { + goRemoveSchemaValidationOnlyCombinators(&prop) + schema.Properties[name] = prop + } + if schema.Items != nil && schema.Items.Schema != nil { + goRemoveSchemaValidationOnlyCombinators(schema.Items.Schema) + } + if schema.AdditionalProperties != nil && schema.AdditionalProperties.Schema != nil { + goRemoveSchemaValidationOnlyCombinators(schema.AdditionalProperties.Schema) + } +} + +// goCombinatorIsValidationOnly returns true if all the given anyOf/oneOf +// variants constrain validation without describing any structure. +func goCombinatorIsValidationOnly(variants []spec.Schema) bool { + if len(variants) == 0 { + return false + } + for i := range variants { + if !goSchemaIsValidationOnly(&variants[i]) { + return false + } + } + return true +} + +func goSchemaIsValidationOnly(s *spec.Schema) bool { + if len(s.Type) > 0 || s.Ref.String() != "" || s.Format != "" || + s.Items != nil || s.AdditionalProperties != nil || + len(s.Enum) > 0 || s.Default != nil || + len(s.AllOf) > 0 || len(s.AnyOf) > 0 || len(s.OneOf) > 0 || s.Not != nil { + return false + } + for name := range s.Properties { + prop := s.Properties[name] + if !goSchemaIsValidationOnly(&prop) { + return false + } + } + return true +} + // goRemoveRequired removes the required fields from schemas. We want all fields // in our generated models to be optional (so functions can set only the fields // they wish to own). @@ -1052,17 +1143,23 @@ func tryReplaceK8sTypeWithMetaPath(schema *spec.Schema, ref string, useCorePath } } +// isSharedK8sSchema returns true if the named schema belongs to one of the +// k8s packages we generate as shared models for all other models to reference. +func isSharedK8sSchema(name string) bool { + return strings.HasPrefix(name, k8sPkgMetaV1) || + strings.HasPrefix(name, k8sPkgRuntime) || + strings.HasPrefix(name, k8sPkgCoreV1) || + strings.HasPrefix(name, k8sPkgIntStr) || + strings.HasPrefix(name, k8sPkgResource) || + strings.HasPrefix(name, k8sPkgAutoscalingV1) +} + // goRemoveK8s removes all k8s schemas from the given OpenAPI spec, so // that we can generate models for them separately and share them across all our // other generated models. func goRemoveK8s(s *spec3.OpenAPI) { for name := range s.Components.Schemas { - if strings.HasPrefix(name, k8sPkgMetaV1) || - strings.HasPrefix(name, k8sPkgRuntime) || - strings.HasPrefix(name, k8sPkgCoreV1) || - strings.HasPrefix(name, k8sPkgIntStr) || - strings.HasPrefix(name, k8sPkgResource) || - strings.HasPrefix(name, k8sPkgAutoscalingV1) { + if isSharedK8sSchema(name) { delete(s.Components.Schemas, name) } } @@ -1451,6 +1548,7 @@ func generateK8sPackageCode(pkg string, schemas map[string]*spec.Schema, schemaF goPkg := getK8sPackageInfo(pkg) code, err := generateGo(pkgSpec, goPkg.version, + goRemoveValidationOnlyCombinators, goRenameTypes, goRenameEnums, goReplaceNumberWithInt, @@ -1506,7 +1604,10 @@ func getK8sPackageInfo(pkg string) goPackage { case k8sPkgIntStr: return goPackage{group: "util.k8s.io", kind: "intstr", version: "v1"} case k8sPkgResource: - return goPackage{group: "resource.k8s.io", kind: "resource", version: "v1"} + // Pseudo-group to distinguish the shared apimachinery Quantity + // package from the real resource.k8s.io API group (dynamic resource + // allocation); see goSchemaPath. + return goPackage{group: "resource.apimachinery.k8s.io", kind: "resource", version: "v1"} case k8sPkgAutoscalingV1: return goPackage{ group: k8sPkgNameAutoscaling, @@ -1525,6 +1626,21 @@ func generateModelsWithGVK(openAPISpecs []*spec3.OpenAPI, schemaFS afero.Fs, g g gvkGroups := groupSchemasByGVK(openAPISpec) for gvkKey, schemas := range gvkGroups { + // Skip groups whose schemas are all shared k8s package schemas + // (e.g. autoscaling/v1's Scale). They're generated by + // generateK8sSharedSchemas, and goRemoveK8s would leave this group + // empty, overwriting the shared package file with an empty one. + shared := true + for name := range schemas { + if !isSharedK8sSchema(name) { + shared = false + break + } + } + if shared { + continue + } + if err := generateGVKGroupCode(gvkKey, schemas, openAPISpec, schemaFS, g); err != nil { return err } @@ -1616,6 +1732,7 @@ func generateGVKGroupCode(gvkKey string, schemas map[string]*spec.Schema, openAP maps.Copy(groupSpec.Components.Schemas, openAPISpec.Components.Schemas) code, err := generateGo(groupSpec, version, + goRemoveValidationOnlyCombinators, goRenameTypes, goRenameEnums, goReplaceNumberWithInt, diff --git a/internal/schemas/generator/go_test.go b/internal/schemas/generator/go_test.go index 65200566..358f84a1 100644 --- a/internal/schemas/generator/go_test.go +++ b/internal/schemas/generator/go_test.go @@ -18,9 +18,11 @@ package generator import ( "embed" + "go/ast" "go/parser" "go/token" "path/filepath" + "strings" "testing" "github.com/google/go-cmp/cmp" @@ -31,6 +33,35 @@ import ( //go:embed testdata/*.yaml var testdataFS embed.FS +// assertValidTypeDecls fails the test if the given parsed Go file declares the +// same type twice or declares a self-referential alias (`type X = X`), both of +// which don't compile but slip through syntax-only parsing. +func assertValidTypeDecls(t *testing.T, f *ast.File, path string) { + t.Helper() + + seen := make(map[string]bool) + for _, decl := range f.Decls { + gd, ok := decl.(*ast.GenDecl) + if !ok || gd.Tok != token.TYPE { + continue + } + for _, s := range gd.Specs { + ts, ok := s.(*ast.TypeSpec) + if !ok { + continue + } + if seen[ts.Name.Name] { + t.Errorf("duplicate type %s declared in %s", ts.Name.Name, path) + } + seen[ts.Name.Name] = true + + if ident, ok := ts.Type.(*ast.Ident); ok && ident.Name == ts.Name.Name { + t.Errorf("self-referential type %s in %s", ts.Name.Name, path) + } + } + } +} + func TestGenerateFromCRDGo(t *testing.T) { inputFS := afero.NewBasePathFs(afero.FromIOFS{FS: testdataFS}, "testdata") schemaFS, err := goGenerator{}.GenerateFromCRD(t.Context(), inputFS, nil) @@ -44,6 +75,8 @@ func TestGenerateFromCRDGo(t *testing.T) { "models/co/acme/platform/v1alpha1/accountscaffold.go", "models/co/acme/platform/v1alpha1/xaccountscaffold.go", "models/io/upbound/azure/web/v1beta1/linuxfunctionapp.go", + "models/io/cilium/v2/ciliumclusterwidenetworkpolicy.go", + "models/com/example/v1/widget.go", } files := token.NewFileSet() @@ -71,6 +104,7 @@ func TestGenerateFromCRDGo(t *testing.T) { if diff := cmp.Diff(expectedPackage, f.Name.Name); diff != "" { t.Errorf("package name (-want +got):\n%s", diff) } + assertValidTypeDecls(t, f, path) case ".mod": mod, err := modfile.Parse(path, contents, nil) @@ -84,6 +118,138 @@ func TestGenerateFromCRDGo(t *testing.T) { } } +// TestGenerateFromCRDGoScaleSubresource ensures CRDs with a scale subresource +// generate a model for the resource itself and don't pull the autoscaling/v1 +// Scale schemas into the generated models. crd.ToOpenAPI drops the scale +// subresource before building the OpenAPI spec, so no shared autoscaling +// package must appear in the CRD flow. +func TestGenerateFromCRDGoScaleSubresource(t *testing.T) { + inputFS := afero.NewBasePathFs(afero.FromIOFS{FS: testdataFS}, "testdata") + schemaFS, err := goGenerator{}.GenerateFromCRD(t.Context(), inputFS, nil) + if err != nil { + t.Fatal(err) + } + + contents, err := afero.ReadFile(schemaFS, "models/com/example/v1/widget.go") + if err != nil { + t.Fatal(err) + } + if !strings.Contains(string(contents), "type Widget struct") { + t.Error("generated code doesn't define Widget") + } + + exists, err := afero.Exists(schemaFS, "models/io/k8s/autoscaling/v1/autoscaling.go") + if err != nil { + t.Fatal(err) + } + if exists { + t.Error("scale subresource leaked the autoscaling/v1 Scale schemas into the generated models") + } +} + +// TestGenerateFromCRDGoValidationOnlyCombinators ensures we can generate +// models for CRDs that use anyOf/oneOf purely for validation (e.g. Cilium's +// "exactly one of endpointSelector and nodeSelector must be set"). Kubernetes +// structural schemas allow only `required` constraints and empty property +// schemas inside these junctors, but oapi-codegen would generate a union +// member type per variant, and a schema with both anyOf and oneOf produces +// colliding type names (two 0). We strip such combinators; typed +// ones like x-kubernetes-int-or-string's anyOf must be kept. +func TestGenerateFromCRDGoValidationOnlyCombinators(t *testing.T) { + inputFS := afero.NewBasePathFs(afero.FromIOFS{FS: testdataFS}, "testdata") + schemaFS, err := goGenerator{}.GenerateFromCRD(t.Context(), inputFS, nil) + if err != nil { + t.Fatal(err) + } + + contents, err := afero.ReadFile(schemaFS, "models/io/cilium/v2/ciliumclusterwidenetworkpolicy.go") + if err != nil { + t.Fatal(err) + } + code := string(contents) + + // The fields referenced by the validation-only combinators must still be + // generated from the schema's regular properties. + for _, field := range []string{"EndpointSelector", "NodeSelector", "Ingress", "Egress"} { + if !strings.Contains(code, field) { + t.Errorf("generated code missing field %s", field) + } + } + + // No union types must be generated for the validation-only combinators on + // the spec schema. + if strings.Contains(code, "type IoCiliumV2CiliumClusterwideNetworkPolicySpec0") { + t.Error("generated code contains a union type for a validation-only combinator") + } + + // Typed anyOf variants (x-kubernetes-int-or-string) must still generate + // union member types. + if !strings.Contains(code, "IoCiliumV2CiliumClusterwideNetworkPolicySpecEgressIcmpsFieldsType0") { + t.Error("generated code is missing the int-or-string union member type") + } +} + +// TestGenerateFromOpenAPIGoSharedK8sPackages ensures models generated for +// real k8s API groups don't overwrite the shared k8s packages: +// +// - The resource.k8s.io group (dynamic resource allocation, GA in k8s 1.34) +// reverses to the same io/k8s/resource/v1 path as the shared apimachinery +// Quantity package. It used to clobber it, leaving a package that imported +// itself and creating a core/v1 -> resource/v1 -> core/v1 import cycle. +// It now lives at io/k8s/api/resource instead. +// - GVK groups whose schemas are all shared k8s package schemas (e.g. +// autoscaling/v1's Scale) used to generate an empty file over the shared +// package. They're skipped now. +func TestGenerateFromOpenAPIGoSharedK8sPackages(t *testing.T) { + inputFS := afero.NewBasePathFs(afero.FromIOFS{FS: testdataJSONFS}, "testdata") + schemaFS, err := goGenerator{}.GenerateFromOpenAPI(t.Context(), inputFS, nil) + if err != nil { + t.Fatal(err) + } + + // The shared apimachinery resource package must define Quantity and must + // not import itself. + contents, err := afero.ReadFile(schemaFS, "models/io/k8s/resource/v1/resource.go") + if err != nil { + t.Fatal(err) + } + shared := string(contents) + if !strings.Contains(shared, "type Quantity struct") { + t.Error("shared resource package no longer defines Quantity") + } + if strings.Contains(shared, "type Quantity = Quantity") { + t.Error("shared resource package contains a self-referential Quantity alias") + } + if strings.Contains(shared, `"dev.crossplane.io/models/io/k8s/resource/v1"`) { + t.Error("shared resource package imports itself") + } + + // The resource.k8s.io group models live at io/k8s/api/resource and + // reference Quantity from the shared package instead of importing + // themselves. + contents, err = afero.ReadFile(schemaFS, "models/io/k8s/api/resource/v1/resource.go") + if err != nil { + t.Fatal(err) + } + dra := string(contents) + if !strings.Contains(dra, "DeviceClass") { + t.Error("resource.k8s.io models are missing DRA types") + } + if !strings.Contains(dra, "resourcev1.Quantity") { + t.Error("resource.k8s.io models don't reference the shared Quantity") + } + + // The shared autoscaling package must not be overwritten by the empty + // autoscaling/v1 GVK group. + contents, err = afero.ReadFile(schemaFS, "models/io/k8s/autoscaling/v1/autoscaling.go") + if err != nil { + t.Fatal(err) + } + if !strings.Contains(string(contents), "type Scale") { + t.Error("shared autoscaling package no longer defines Scale") + } +} + func TestGenerateFromOpenAPIGo(t *testing.T) { inputFS := afero.NewBasePathFs(afero.FromIOFS{FS: testdataJSONFS}, "testdata") schemaFS, err := goGenerator{}.GenerateFromOpenAPI(t.Context(), inputFS, nil) @@ -99,6 +265,7 @@ func TestGenerateFromOpenAPIGo(t *testing.T) { "models/io/k8s/policy/v1/policy.go", "models/io/k8s/autoscaling/v1/autoscaling.go", "models/io/k8s/resource/v1/resource.go", + "models/io/k8s/api/resource/v1/resource.go", "models/io/k8s/authentication/v1/authentication.go", } @@ -127,6 +294,7 @@ func TestGenerateFromOpenAPIGo(t *testing.T) { if diff := cmp.Diff(expectedPackage, f.Name.Name); diff != "" { t.Errorf("package name (-want +got):\n%s", diff) } + assertValidTypeDecls(t, f, path) case ".mod": mod, err := modfile.Parse(path, contents, nil) diff --git a/internal/schemas/generator/runtimeobject_compilegate_test.go b/internal/schemas/generator/runtimeobject_compilegate_test.go index 68851be1..954d2ef2 100644 --- a/internal/schemas/generator/runtimeobject_compilegate_test.go +++ b/internal/schemas/generator/runtimeobject_compilegate_test.go @@ -242,7 +242,8 @@ func TestBuiltInGroupVersions(t *testing.T) { }{ "CoreV1": {obj: &corev1.Pod{}, want: schema.GroupVersionKind{Version: "v1", Kind: "Pod"}}, "MetaV1": {obj: &metav1.Status{}, want: schema.GroupVersionKind{Version: "v1", Kind: "Status"}}, - "Autoscaling": {obj: &autoscalingv1.TokenRequest{}, want: schema.GroupVersionKind{Group: "autoscaling", Version: "v1", Kind: "TokenRequest"}}, + "Autoscaling": {obj: &autoscalingv1.Scale{}, want: schema.GroupVersionKind{Group: "autoscaling", Version: "v1", Kind: "Scale"}}, + "Authn": {obj: &authnv1.TokenRequest{}, want: schema.GroupVersionKind{Group: "authentication.k8s.io", Version: "v1", Kind: "TokenRequest"}}, } for name, tc := range cases { t.Run(name, func(t *testing.T) { diff --git a/internal/schemas/generator/testdata/apis__resource.k8s.io__v1_openapi.json b/internal/schemas/generator/testdata/apis__resource.k8s.io__v1_openapi.json new file mode 100644 index 00000000..03eadd66 --- /dev/null +++ b/internal/schemas/generator/testdata/apis__resource.k8s.io__v1_openapi.json @@ -0,0 +1,8887 @@ +{ + "components": { + "schemas": { + "io.k8s.api.core.v1.NodeSelector": { + "description": "A node selector represents the union of the results of one or more label queries over a set of nodes; that is, it represents the OR of the selectors represented by the node selector terms.", + "properties": { + "nodeSelectorTerms": { + "description": "Required. A list of node selector terms. The terms are ORed.", + "items": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.core.v1.NodeSelectorTerm" + } + ], + "default": {} + }, + "type": "array", + "x-kubernetes-list-type": "atomic" + } + }, + "required": [ + "nodeSelectorTerms" + ], + "type": "object", + "x-kubernetes-map-type": "atomic" + }, + "io.k8s.api.core.v1.NodeSelectorRequirement": { + "description": "A node selector requirement is a selector that contains values, a key, and an operator that relates the key and values.", + "properties": { + "key": { + "default": "", + "description": "The label key that the selector applies to.", + "type": "string" + }, + "operator": { + "default": "", + "description": "Represents a key's relationship to a set of values. Valid operators are In, NotIn, Exists, DoesNotExist. Gt, and Lt.", + "type": "string" + }, + "values": { + "description": "An array of string values. If the operator is In or NotIn, the values array must be non-empty. If the operator is Exists or DoesNotExist, the values array must be empty. If the operator is Gt or Lt, the values array must have a single element, which will be interpreted as an integer. This array is replaced during a strategic merge patch.", + "items": { + "default": "", + "type": "string" + }, + "type": "array", + "x-kubernetes-list-type": "atomic" + } + }, + "required": [ + "key", + "operator" + ], + "type": "object" + }, + "io.k8s.api.core.v1.NodeSelectorTerm": { + "description": "A null or empty node selector term matches no objects. The requirements of them are ANDed. The TopologySelectorTerm type implements a subset of the NodeSelectorTerm.", + "properties": { + "matchExpressions": { + "description": "A list of node selector requirements by node's labels.", + "items": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.core.v1.NodeSelectorRequirement" + } + ], + "default": {} + }, + "type": "array", + "x-kubernetes-list-type": "atomic" + }, + "matchFields": { + "description": "A list of node selector requirements by node's fields.", + "items": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.core.v1.NodeSelectorRequirement" + } + ], + "default": {} + }, + "type": "array", + "x-kubernetes-list-type": "atomic" + } + }, + "type": "object", + "x-kubernetes-map-type": "atomic" + }, + "io.k8s.api.resource.v1.AllocatedDeviceStatus": { + "description": "AllocatedDeviceStatus contains the status of an allocated device, if the driver chooses to report it. This may include driver-specific information.\n\nThe combination of Driver, Pool, Device, and ShareID must match the corresponding key in Status.Allocation.Devices.", + "properties": { + "conditions": { + "description": "Conditions contains the latest observation of the device's state. If the device has been configured according to the class and claim config references, the `Ready` condition should be True.\n\nMust not contain more than 8 entries.", + "items": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.Condition" + } + ], + "default": {} + }, + "type": "array", + "x-kubernetes-list-map-keys": [ + "type" + ], + "x-kubernetes-list-type": "map" + }, + "data": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.apimachinery.pkg.runtime.RawExtension" + } + ], + "description": "Data contains arbitrary driver-specific data.\n\nThe length of the raw data must be smaller or equal to 10 Ki." + }, + "device": { + "default": "", + "description": "Device references one device instance via its name in the driver's resource pool. It must be a DNS label.", + "type": "string" + }, + "driver": { + "default": "", + "description": "Driver specifies the name of the DRA driver whose kubelet plugin should be invoked to process the allocation once the claim is needed on a node.\n\nMust be a DNS subdomain and should end with a DNS domain owned by the vendor of the driver. It should use only lower case characters.", + "type": "string" + }, + "networkData": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.resource.v1.NetworkDeviceData" + } + ], + "description": "NetworkData contains network-related information specific to the device." + }, + "pool": { + "default": "", + "description": "This name together with the driver name and the device name field identify which device was allocated (`//`).\n\nMust not be longer than 253 characters and may contain one or more DNS sub-domains separated by slashes.", + "type": "string" + }, + "shareID": { + "description": "ShareID uniquely identifies an individual allocation share of the device.", + "type": "string" + } + }, + "required": [ + "driver", + "pool", + "device" + ], + "type": "object" + }, + "io.k8s.api.resource.v1.AllocationResult": { + "description": "AllocationResult contains attributes of an allocated resource.", + "properties": { + "allocationTimestamp": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.Time" + } + ], + "description": "AllocationTimestamp stores the time when the resources were allocated. This field is not guaranteed to be set, in which case that time is unknown.\n\nThis is an alpha field and requires enabling the DRADeviceBindingConditions and DRAResourceClaimDeviceStatus feature gate." + }, + "devices": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.resource.v1.DeviceAllocationResult" + } + ], + "default": {}, + "description": "Devices is the result of allocating devices." + }, + "nodeSelector": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.core.v1.NodeSelector" + } + ], + "description": "NodeSelector defines where the allocated resources are available. If unset, they are available everywhere." + } + }, + "type": "object" + }, + "io.k8s.api.resource.v1.CELDeviceSelector": { + "description": "CELDeviceSelector contains a CEL expression for selecting a device.", + "properties": { + "expression": { + "default": "", + "description": "Expression is a CEL expression which evaluates a single device. It must evaluate to true when the device under consideration satisfies the desired criteria, and false when it does not. Any other result is an error and causes allocation of devices to abort.\n\nThe expression's input is an object named \"device\", which carries the following properties:\n - driver (string): the name of the driver which defines this device.\n - attributes (map[string]object): the device's attributes, grouped by prefix\n (e.g. device.attributes[\"dra.example.com\"] evaluates to an object with all\n of the attributes which were prefixed by \"dra.example.com\".\n - capacity (map[string]object): the device's capacities, grouped by prefix.\n - allowMultipleAllocations (bool): the allowMultipleAllocations property of the device\n (v1.34+ with the DRAConsumableCapacity feature enabled).\n\nExample: Consider a device with driver=\"dra.example.com\", which exposes two attributes named \"model\" and \"ext.example.com/family\" and which exposes one capacity named \"modules\". This input to this expression would have the following fields:\n\n device.driver\n device.attributes[\"dra.example.com\"].model\n device.attributes[\"ext.example.com\"].family\n device.capacity[\"dra.example.com\"].modules\n\nThe device.driver field can be used to check for a specific driver, either as a high-level precondition (i.e. you only want to consider devices from this driver) or as part of a multi-clause expression that is meant to consider devices from different drivers.\n\nThe value type of each attribute is defined by the device definition, and users who write these expressions must consult the documentation for their specific drivers. The value type of each capacity is Quantity.\n\nIf an unknown prefix is used as a lookup in either device.attributes or device.capacity, an empty map will be returned. Any reference to an unknown field will cause an evaluation error and allocation to abort.\n\nA robust expression should check for the existence of attributes before referencing them.\n\nFor 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:\n\n cel.bind(dra, device.attributes[\"dra.example.com\"], dra.someBool && dra.anotherBool)\n\nThe length of the expression must be smaller or equal to 10 Ki. The cost of evaluating it is also limited based on the estimated number of logical steps.", + "type": "string" + } + }, + "required": [ + "expression" + ], + "type": "object" + }, + "io.k8s.api.resource.v1.CapacityRequestPolicy": { + "description": "CapacityRequestPolicy defines how requests consume device capacity.\n\nMust not set more than one ValidRequestValues.", + "properties": { + "default": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.apimachinery.pkg.api.resource.Quantity" + } + ], + "description": "Default specifies how much of this capacity is consumed by a request that does not contain an entry for it in DeviceRequest's Capacity." + }, + "validRange": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.resource.v1.CapacityRequestPolicyRange" + } + ], + "description": "ValidRange defines an acceptable quantity value range in consuming requests.\n\nIf this field is set, Default must be defined and it must fall within the defined ValidRange.\n\nIf the requested amount does not fall within the defined range, the request violates the policy, and this device cannot be allocated.\n\nIf the request doesn't contain this capacity entry, Default value is used." + }, + "validValues": { + "description": "ValidValues defines a set of acceptable quantity values in consuming requests.\n\nMust not contain more than 10 entries. Must be sorted in ascending order.\n\nIf this field is set, Default must be defined and it must be included in ValidValues list.\n\nIf the requested amount does not match any valid value but smaller than some valid values, the scheduler calculates the smallest valid value that is greater than or equal to the request. That is: min(ceil(requestedValue) ∈ validValues), where requestedValue ≤ max(validValues).\n\nIf the requested amount exceeds all valid values, the request violates the policy, and this device cannot be allocated.", + "items": { + "$ref": "#/components/schemas/io.k8s.apimachinery.pkg.api.resource.Quantity" + }, + "type": "array", + "x-kubernetes-list-type": "atomic" + } + }, + "type": "object" + }, + "io.k8s.api.resource.v1.CapacityRequestPolicyRange": { + "description": "CapacityRequestPolicyRange defines a valid range for consumable capacity values.\n\n - If the requested amount is less than Min, it is rounded up to the Min value.\n - If Step is set and the requested amount is between Min and Max but not aligned with Step,\n it will be rounded up to the next value equal to Min + (n * Step).\n - If Step is not set, the requested amount is used as-is if it falls within the range Min to Max (if set).\n - If the requested or rounded amount exceeds Max (if set), the request does not satisfy the policy,\n and the device cannot be allocated.", + "properties": { + "max": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.apimachinery.pkg.api.resource.Quantity" + } + ], + "description": "Max defines the upper limit for capacity that can be requested.\n\nMax must be less than or equal to the capacity value. Min and requestPolicy.default must be less than or equal to the maximum." + }, + "min": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.apimachinery.pkg.api.resource.Quantity" + } + ], + "description": "Min specifies the minimum capacity allowed for a consumption request.\n\nMin must be greater than or equal to zero, and less than or equal to the capacity value. requestPolicy.default must be more than or equal to the minimum." + }, + "step": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.apimachinery.pkg.api.resource.Quantity" + } + ], + "description": "Step defines the step size between valid capacity amounts within the range.\n\nMax (if set) and requestPolicy.default must be a multiple of Step. Min + Step must be less than or equal to the capacity value." + } + }, + "required": [ + "min" + ], + "type": "object" + }, + "io.k8s.api.resource.v1.CapacityRequirements": { + "description": "CapacityRequirements defines the capacity requirements for a specific device request.", + "properties": { + "requests": { + "additionalProperties": { + "$ref": "#/components/schemas/io.k8s.apimachinery.pkg.api.resource.Quantity" + }, + "description": "Requests represent individual device resource requests for distinct resources, all of which must be provided by the device.\n\nThis value is used as an additional filtering condition against the available capacity on the device. This is semantically equivalent to a CEL selector with `device.capacity[]..compareTo(quantity()) >= 0`. For example, device.capacity['test-driver.cdi.k8s.io'].counters.compareTo(quantity('2')) >= 0.\n\nWhen a requestPolicy is defined, the requested amount is adjusted upward to the nearest valid value based on the policy. If the requested amount cannot be adjusted to a valid value—because it exceeds what the requestPolicy allows— the device is considered ineligible for allocation.\n\nFor any capacity that is not explicitly requested: - If no requestPolicy is set, the default consumed capacity is equal to the full device capacity\n (i.e., the whole device is claimed).\n- If a requestPolicy is set, the default consumed capacity is determined according to that policy.\n\nIf the device allows multiple allocation, the aggregated amount across all requests must not exceed the capacity value. The consumed capacity, which may be adjusted based on the requestPolicy if defined, is recorded in the resource claim’s status.devices[*].consumedCapacity field.", + "type": "object" + } + }, + "type": "object" + }, + "io.k8s.api.resource.v1.Counter": { + "description": "Counter describes a quantity associated with a device.", + "properties": { + "value": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.apimachinery.pkg.api.resource.Quantity" + } + ], + "description": "Value defines how much of a certain device counter is available." + } + }, + "required": [ + "value" + ], + "type": "object" + }, + "io.k8s.api.resource.v1.CounterSet": { + "description": "CounterSet defines a named set of counters that are available to be used by devices defined in the ResourcePool.\n\nThe counters are not allocatable by themselves, but can be referenced by devices. When a device is allocated, the portion of counters it uses will no longer be available for use by other devices.", + "properties": { + "counters": { + "additionalProperties": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.resource.v1.Counter" + } + ], + "default": {} + }, + "description": "Counters defines the set of counters for this CounterSet The name of each counter must be unique in that set and must be a DNS label.\n\nThe maximum number of counters is 32.", + "type": "object" + }, + "name": { + "default": "", + "description": "Name defines the name of the counter set. It must be a DNS label.", + "type": "string" + } + }, + "required": [ + "name", + "counters" + ], + "type": "object" + }, + "io.k8s.api.resource.v1.Device": { + "description": "Device represents one individual hardware instance that can be selected based on its attributes. Besides the name, exactly one field must be set.", + "properties": { + "allNodes": { + "description": "AllNodes indicates that all nodes have access to the device.\n\nMust only be set if Spec.PerDeviceNodeSelection is set to true. At most one of NodeName, NodeSelector and AllNodes can be set.", + "type": "boolean" + }, + "allowMultipleAllocations": { + "description": "AllowMultipleAllocations marks whether the device is allowed to be allocated to multiple DeviceRequests.\n\nIf AllowMultipleAllocations is set to true, the device can be allocated more than once, and all of its capacity is consumable, regardless of whether the requestPolicy is defined or not.", + "type": "boolean" + }, + "attributes": { + "additionalProperties": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.resource.v1.DeviceAttribute" + } + ], + "default": {} + }, + "description": "Attributes defines the set of attributes for this device. The name of each attribute must be unique in that set.\n\nThe maximum number of attributes and capacities combined is 32.", + "type": "object" + }, + "bindingConditions": { + "description": "BindingConditions defines the conditions for proceeding with binding. All of these conditions must be set in the per-device status conditions with a value of True to proceed with binding the pod to the node while scheduling the pod.\n\nThe maximum number of binding conditions is 4.\n\nThe conditions must be a valid condition type string.\n\nThis is an alpha field and requires enabling the DRADeviceBindingConditions and DRAResourceClaimDeviceStatus feature gates.", + "items": { + "default": "", + "type": "string" + }, + "type": "array", + "x-kubernetes-list-type": "atomic" + }, + "bindingFailureConditions": { + "description": "BindingFailureConditions defines the conditions for binding failure. They may be set in the per-device status conditions. If any is set to \"True\", a binding failure occurred.\n\nThe maximum number of binding failure conditions is 4.\n\nThe conditions must be a valid condition type string.\n\nThis is an alpha field and requires enabling the DRADeviceBindingConditions and DRAResourceClaimDeviceStatus feature gates.", + "items": { + "default": "", + "type": "string" + }, + "type": "array", + "x-kubernetes-list-type": "atomic" + }, + "bindsToNode": { + "description": "BindsToNode indicates if the usage of an allocation involving this device has to be limited to exactly the node that was chosen when allocating the claim. If set to true, the scheduler will set the ResourceClaim.Status.Allocation.NodeSelector to match the node where the allocation was made.\n\nThis is an alpha field and requires enabling the DRADeviceBindingConditions and DRAResourceClaimDeviceStatus feature gates.", + "type": "boolean" + }, + "capacity": { + "additionalProperties": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.resource.v1.DeviceCapacity" + } + ], + "default": {} + }, + "description": "Capacity defines the set of capacities for this device. The name of each capacity must be unique in that set.\n\nThe maximum number of attributes and capacities combined is 32.", + "type": "object" + }, + "consumesCounters": { + "description": "ConsumesCounters defines a list of references to sharedCounters and the set of counters that the device will consume from those counter sets.\n\nThere can only be a single entry per counterSet.\n\nThe maximum number of device counter consumptions per device is 2.", + "items": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.resource.v1.DeviceCounterConsumption" + } + ], + "default": {} + }, + "type": "array", + "x-kubernetes-list-type": "atomic" + }, + "name": { + "default": "", + "description": "Name is unique identifier among all devices managed by the driver in the pool. It must be a DNS label.", + "type": "string" + }, + "nodeName": { + "description": "NodeName identifies the node where the device is available.\n\nMust only be set if Spec.PerDeviceNodeSelection is set to true. At most one of NodeName, NodeSelector and AllNodes can be set.", + "type": "string" + }, + "nodeSelector": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.core.v1.NodeSelector" + } + ], + "description": "NodeSelector defines the nodes where the device is available.\n\nMust use exactly one term.\n\nMust only be set if Spec.PerDeviceNodeSelection is set to true. At most one of NodeName, NodeSelector and AllNodes can be set." + }, + "taints": { + "description": "If specified, these are the driver-defined taints.\n\nThe maximum number of taints is 16. If taints are set for any device in a ResourceSlice, then the maximum number of allowed devices per ResourceSlice is 64 instead of 128.\n\nThis is an alpha field and requires enabling the DRADeviceTaints feature gate.", + "items": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.resource.v1.DeviceTaint" + } + ], + "default": {} + }, + "type": "array", + "x-kubernetes-list-type": "atomic" + } + }, + "required": [ + "name" + ], + "type": "object" + }, + "io.k8s.api.resource.v1.DeviceAllocationConfiguration": { + "description": "DeviceAllocationConfiguration gets embedded in an AllocationResult.", + "properties": { + "opaque": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.resource.v1.OpaqueDeviceConfiguration" + } + ], + "description": "Opaque provides driver-specific configuration parameters." + }, + "requests": { + "description": "Requests lists the names of requests where the configuration applies. If empty, its applies to all requests.\n\nReferences to subrequests must include the name of the main request and may include the subrequest using the format
[/]. If just the main request is given, the configuration applies to all subrequests.", + "items": { + "default": "", + "type": "string" + }, + "type": "array", + "x-kubernetes-list-type": "atomic" + }, + "source": { + "default": "", + "description": "Source records whether the configuration comes from a class and thus is not something that a normal user would have been able to set or from a claim.", + "type": "string" + } + }, + "required": [ + "source" + ], + "type": "object" + }, + "io.k8s.api.resource.v1.DeviceAllocationResult": { + "description": "DeviceAllocationResult is the result of allocating devices.", + "properties": { + "config": { + "description": "This field is a combination of all the claim and class configuration parameters. Drivers can distinguish between those based on a flag.\n\nThis includes configuration parameters for drivers which have no allocated devices in the result because it is up to the drivers which configuration parameters they support. They can silently ignore unknown configuration parameters.", + "items": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.resource.v1.DeviceAllocationConfiguration" + } + ], + "default": {} + }, + "type": "array", + "x-kubernetes-list-type": "atomic" + }, + "results": { + "description": "Results lists all allocated devices.", + "items": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.resource.v1.DeviceRequestAllocationResult" + } + ], + "default": {} + }, + "type": "array", + "x-kubernetes-list-type": "atomic" + } + }, + "type": "object" + }, + "io.k8s.api.resource.v1.DeviceAttribute": { + "description": "DeviceAttribute must have exactly one field set.", + "properties": { + "bool": { + "description": "BoolValue is a true/false value.", + "type": "boolean" + }, + "int": { + "description": "IntValue is a number.", + "format": "int64", + "type": "integer" + }, + "string": { + "description": "StringValue is a string. Must not be longer than 64 characters.", + "type": "string" + }, + "version": { + "description": "VersionValue is a semantic version according to semver.org spec 2.0.0. Must not be longer than 64 characters.", + "type": "string" + } + }, + "type": "object" + }, + "io.k8s.api.resource.v1.DeviceCapacity": { + "description": "DeviceCapacity describes a quantity associated with a device.", + "properties": { + "requestPolicy": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.resource.v1.CapacityRequestPolicy" + } + ], + "description": "RequestPolicy defines how this DeviceCapacity must be consumed when the device is allowed to be shared by multiple allocations.\n\nThe Device must have allowMultipleAllocations set to true in order to set a requestPolicy.\n\nIf unset, capacity requests are unconstrained: requests can consume any amount of capacity, as long as the total consumed across all allocations does not exceed the device's defined capacity. If request is also unset, default is the full capacity value." + }, + "value": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.apimachinery.pkg.api.resource.Quantity" + } + ], + "description": "Value defines how much of a certain capacity that device has.\n\nThis field reflects the fixed total capacity and does not change. The consumed amount is tracked separately by scheduler and does not affect this value." + } + }, + "required": [ + "value" + ], + "type": "object" + }, + "io.k8s.api.resource.v1.DeviceClaim": { + "description": "DeviceClaim defines how to request devices with a ResourceClaim.", + "properties": { + "config": { + "description": "This field holds configuration for multiple potential drivers which could satisfy requests in this claim. It is ignored while allocating the claim.", + "items": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.resource.v1.DeviceClaimConfiguration" + } + ], + "default": {} + }, + "type": "array", + "x-kubernetes-list-type": "atomic" + }, + "constraints": { + "description": "These constraints must be satisfied by the set of devices that get allocated for the claim.", + "items": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.resource.v1.DeviceConstraint" + } + ], + "default": {} + }, + "type": "array", + "x-kubernetes-list-type": "atomic" + }, + "requests": { + "description": "Requests represent individual requests for distinct devices which must all be satisfied. If empty, nothing needs to be allocated.", + "items": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.resource.v1.DeviceRequest" + } + ], + "default": {} + }, + "type": "array", + "x-kubernetes-list-type": "atomic" + } + }, + "type": "object" + }, + "io.k8s.api.resource.v1.DeviceClaimConfiguration": { + "description": "DeviceClaimConfiguration is used for configuration parameters in DeviceClaim.", + "properties": { + "opaque": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.resource.v1.OpaqueDeviceConfiguration" + } + ], + "description": "Opaque provides driver-specific configuration parameters." + }, + "requests": { + "description": "Requests lists the names of requests where the configuration applies. If empty, it applies to all requests.\n\nReferences to subrequests must include the name of the main request and may include the subrequest using the format
[/]. If just the main request is given, the configuration applies to all subrequests.", + "items": { + "default": "", + "type": "string" + }, + "type": "array", + "x-kubernetes-list-type": "atomic" + } + }, + "type": "object" + }, + "io.k8s.api.resource.v1.DeviceClass": { + "description": "DeviceClass is a vendor- or admin-provided resource that contains device configuration and selectors. It can be referenced in the device requests of a claim to apply these presets. Cluster scoped.\n\nThis is an alpha type and requires enabling the DynamicResourceAllocation feature gate.", + "properties": { + "apiVersion": { + "description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", + "type": "string" + }, + "kind": { + "description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", + "type": "string" + }, + "metadata": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta" + } + ], + "default": {}, + "description": "Standard object metadata" + }, + "spec": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.resource.v1.DeviceClassSpec" + } + ], + "default": {}, + "description": "Spec defines what can be allocated and how to configure it.\n\nThis is mutable. Consumers have to be prepared for classes changing at any time, either because they get updated or replaced. Claim allocations are done once based on whatever was set in classes at the time of allocation.\n\nChanging the spec automatically increments the metadata.generation number." + } + }, + "required": [ + "spec" + ], + "type": "object", + "x-kubernetes-group-version-kind": [ + { + "group": "resource.k8s.io", + "kind": "DeviceClass", + "version": "v1" + } + ] + }, + "io.k8s.api.resource.v1.DeviceClassConfiguration": { + "description": "DeviceClassConfiguration is used in DeviceClass.", + "properties": { + "opaque": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.resource.v1.OpaqueDeviceConfiguration" + } + ], + "description": "Opaque provides driver-specific configuration parameters." + } + }, + "type": "object" + }, + "io.k8s.api.resource.v1.DeviceClassList": { + "description": "DeviceClassList is a collection of classes.", + "properties": { + "apiVersion": { + "description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", + "type": "string" + }, + "items": { + "description": "Items is the list of resource classes.", + "items": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.resource.v1.DeviceClass" + } + ], + "default": {} + }, + "type": "array" + }, + "kind": { + "description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", + "type": "string" + }, + "metadata": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.ListMeta" + } + ], + "default": {}, + "description": "Standard list metadata" + } + }, + "required": [ + "items" + ], + "type": "object", + "x-kubernetes-group-version-kind": [ + { + "group": "resource.k8s.io", + "kind": "DeviceClassList", + "version": "v1" + } + ] + }, + "io.k8s.api.resource.v1.DeviceClassSpec": { + "description": "DeviceClassSpec is used in a [DeviceClass] to define what can be allocated and how to configure it.", + "properties": { + "config": { + "description": "Config defines configuration parameters that apply to each device that is claimed via this class. Some classses may potentially be satisfied by multiple drivers, so each instance of a vendor configuration applies to exactly one driver.\n\nThey are passed to the driver, but are not considered while allocating the claim.", + "items": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.resource.v1.DeviceClassConfiguration" + } + ], + "default": {} + }, + "type": "array", + "x-kubernetes-list-type": "atomic" + }, + "extendedResourceName": { + "description": "ExtendedResourceName is the extended resource name for the devices of this class. The devices of this class can be used to satisfy a pod's extended resource requests. It has the same format as the name of a pod's extended resource. It should be unique among all the device classes in a cluster. If two device classes have the same name, then the class created later is picked to satisfy a pod's extended resource requests. If two classes are created at the same time, then the name of the class lexicographically sorted first is picked.\n\nThis is an alpha field.", + "type": "string" + }, + "selectors": { + "description": "Each selector must be satisfied by a device which is claimed via this class.", + "items": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.resource.v1.DeviceSelector" + } + ], + "default": {} + }, + "type": "array", + "x-kubernetes-list-type": "atomic" + } + }, + "type": "object" + }, + "io.k8s.api.resource.v1.DeviceConstraint": { + "description": "DeviceConstraint must have exactly one field set besides Requests.", + "properties": { + "distinctAttribute": { + "description": "DistinctAttribute requires that all devices in question have this attribute and that its type and value are unique across those devices.\n\nThis acts as the inverse of MatchAttribute.\n\nThis constraint is used to avoid allocating multiple requests to the same device by ensuring attribute-level differentiation.\n\nThis is useful for scenarios where resource requests must be fulfilled by separate physical devices. For example, a container requests two network interfaces that must be allocated from two different physical NICs.", + "type": "string" + }, + "matchAttribute": { + "description": "MatchAttribute requires that all devices in question have this attribute and that its type and value are the same across those devices.\n\nFor example, if you specified \"dra.example.com/numa\" (a hypothetical example!), then only devices in the same NUMA node will be chosen. A device which does not have that attribute will not be chosen. All devices should use a value of the same type for this attribute because that is part of its specification, but if one device doesn't, then it also will not be chosen.\n\nMust include the domain qualifier.", + "type": "string" + }, + "requests": { + "description": "Requests is a list of the one or more requests in this claim which must co-satisfy this constraint. If a request is fulfilled by multiple devices, then all of the devices must satisfy the constraint. If this is not specified, this constraint applies to all requests in this claim.\n\nReferences to subrequests must include the name of the main request and may include the subrequest using the format
[/]. If just the main request is given, the constraint applies to all subrequests.", + "items": { + "default": "", + "type": "string" + }, + "type": "array", + "x-kubernetes-list-type": "atomic" + } + }, + "type": "object" + }, + "io.k8s.api.resource.v1.DeviceCounterConsumption": { + "description": "DeviceCounterConsumption defines a set of counters that a device will consume from a CounterSet.", + "properties": { + "counterSet": { + "default": "", + "description": "CounterSet is the name of the set from which the counters defined will be consumed.", + "type": "string" + }, + "counters": { + "additionalProperties": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.resource.v1.Counter" + } + ], + "default": {} + }, + "description": "Counters defines the counters that will be consumed by the device.\n\nThe maximum number of counters is 32.", + "type": "object" + } + }, + "required": [ + "counterSet", + "counters" + ], + "type": "object" + }, + "io.k8s.api.resource.v1.DeviceRequest": { + "description": "DeviceRequest is a request for devices required for a claim. This is typically a request for a single resource like a device, but can also ask for several identical devices. With FirstAvailable it is also possible to provide a prioritized list of requests.", + "properties": { + "exactly": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.resource.v1.ExactDeviceRequest" + } + ], + "description": "Exactly specifies the details for a single request that must be met exactly for the request to be satisfied.\n\nOne of Exactly or FirstAvailable must be set." + }, + "firstAvailable": { + "description": "FirstAvailable contains subrequests, of which exactly one will be selected by the scheduler. It tries to satisfy them in the order in which they are listed here. So if there are two entries in the list, the scheduler will only check the second one if it determines that the first one can not be used.\n\nDRA does not yet implement scoring, so the scheduler will select the first set of devices that satisfies all the requests in the claim. And if the requirements can be satisfied on more than one node, other scheduling features will determine which node is chosen. This means that the set of devices allocated to a claim might not be the optimal set available to the cluster. Scoring will be implemented later.", + "items": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.resource.v1.DeviceSubRequest" + } + ], + "default": {} + }, + "type": "array", + "x-kubernetes-list-type": "atomic" + }, + "name": { + "default": "", + "description": "Name can be used to reference this request in a pod.spec.containers[].resources.claims entry and in a constraint of the claim.\n\nReferences using the name in the DeviceRequest will uniquely identify a request when the Exactly field is set. When the FirstAvailable field is set, a reference to the name of the DeviceRequest will match whatever subrequest is chosen by the scheduler.\n\nMust be a DNS label.", + "type": "string" + } + }, + "required": [ + "name" + ], + "type": "object" + }, + "io.k8s.api.resource.v1.DeviceRequestAllocationResult": { + "description": "DeviceRequestAllocationResult contains the allocation result for one request.", + "properties": { + "adminAccess": { + "description": "AdminAccess indicates that this device was allocated for administrative access. See the corresponding request field for a definition of mode.\n\nThis is an alpha field and requires enabling the DRAAdminAccess feature gate. Admin access is disabled if this field is unset or set to false, otherwise it is enabled.", + "type": "boolean" + }, + "bindingConditions": { + "description": "BindingConditions contains a copy of the BindingConditions from the corresponding ResourceSlice at the time of allocation.\n\nThis is an alpha field and requires enabling the DRADeviceBindingConditions and DRAResourceClaimDeviceStatus feature gates.", + "items": { + "default": "", + "type": "string" + }, + "type": "array", + "x-kubernetes-list-type": "atomic" + }, + "bindingFailureConditions": { + "description": "BindingFailureConditions contains a copy of the BindingFailureConditions from the corresponding ResourceSlice at the time of allocation.\n\nThis is an alpha field and requires enabling the DRADeviceBindingConditions and DRAResourceClaimDeviceStatus feature gates.", + "items": { + "default": "", + "type": "string" + }, + "type": "array", + "x-kubernetes-list-type": "atomic" + }, + "consumedCapacity": { + "additionalProperties": { + "$ref": "#/components/schemas/io.k8s.apimachinery.pkg.api.resource.Quantity" + }, + "description": "ConsumedCapacity tracks the amount of capacity consumed per device as part of the claim request. The consumed amount may differ from the requested amount: it is rounded up to the nearest valid value based on the device’s requestPolicy if applicable (i.e., may not be less than the requested amount).\n\nThe total consumed capacity for each device must not exceed the DeviceCapacity's Value.\n\nThis field is populated only for devices that allow multiple allocations. All capacity entries are included, even if the consumed amount is zero.", + "type": "object" + }, + "device": { + "default": "", + "description": "Device references one device instance via its name in the driver's resource pool. It must be a DNS label.", + "type": "string" + }, + "driver": { + "default": "", + "description": "Driver specifies the name of the DRA driver whose kubelet plugin should be invoked to process the allocation once the claim is needed on a node.\n\nMust be a DNS subdomain and should end with a DNS domain owned by the vendor of the driver. It should use only lower case characters.", + "type": "string" + }, + "pool": { + "default": "", + "description": "This name together with the driver name and the device name field identify which device was allocated (`//`).\n\nMust not be longer than 253 characters and may contain one or more DNS sub-domains separated by slashes.", + "type": "string" + }, + "request": { + "default": "", + "description": "Request is the name of the request in the claim which caused this device to be allocated. If it references a subrequest in the firstAvailable list on a DeviceRequest, this field must include both the name of the main request and the subrequest using the format
/.\n\nMultiple devices may have been allocated per request.", + "type": "string" + }, + "shareID": { + "description": "ShareID uniquely identifies an individual allocation share of the device, used when the device supports multiple simultaneous allocations. It serves as an additional map key to differentiate concurrent shares of the same device.", + "type": "string" + }, + "tolerations": { + "description": "A copy of all tolerations specified in the request at the time when the device got allocated.\n\nThe maximum number of tolerations is 16.\n\nThis is an alpha field and requires enabling the DRADeviceTaints feature gate.", + "items": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.resource.v1.DeviceToleration" + } + ], + "default": {} + }, + "type": "array", + "x-kubernetes-list-type": "atomic" + } + }, + "required": [ + "request", + "driver", + "pool", + "device" + ], + "type": "object" + }, + "io.k8s.api.resource.v1.DeviceSelector": { + "description": "DeviceSelector must have exactly one field set.", + "properties": { + "cel": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.resource.v1.CELDeviceSelector" + } + ], + "description": "CEL contains a CEL expression for selecting a device." + } + }, + "type": "object" + }, + "io.k8s.api.resource.v1.DeviceSubRequest": { + "description": "DeviceSubRequest describes a request for device provided in the claim.spec.devices.requests[].firstAvailable array. Each is typically a request for a single resource like a device, but can also ask for several identical devices.\n\nDeviceSubRequest is similar to ExactDeviceRequest, but doesn't expose the AdminAccess field as that one is only supported when requesting a specific device.", + "properties": { + "allocationMode": { + "description": "AllocationMode and its related fields define how devices are allocated to satisfy this subrequest. Supported values are:\n\n- ExactCount: This request is for a specific number of devices.\n This is the default. The exact number is provided in the\n count field.\n\n- All: This subrequest is for all of the matching devices in a pool.\n Allocation will fail if some devices are already allocated,\n unless adminAccess is requested.\n\nIf AllocationMode is not specified, the default mode is ExactCount. If the mode is ExactCount and count is not specified, the default count is one. Any other subrequests must specify this field.\n\nMore modes may get added in the future. Clients must refuse to handle requests with unknown modes.", + "type": "string" + }, + "capacity": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.resource.v1.CapacityRequirements" + } + ], + "description": "Capacity define resource requirements against each capacity.\n\nIf this field is unset and the device supports multiple allocations, the default value will be applied to each capacity according to requestPolicy. For the capacity that has no requestPolicy, default is the full capacity value.\n\nApplies to each device allocation. If Count > 1, the request fails if there aren't enough devices that meet the requirements. If AllocationMode is set to All, the request fails if there are devices that otherwise match the request, and have this capacity, with a value >= the requested amount, but which cannot be allocated to this request." + }, + "count": { + "description": "Count is used only when the count mode is \"ExactCount\". Must be greater than zero. If AllocationMode is ExactCount and this field is not specified, the default is one.", + "format": "int64", + "type": "integer" + }, + "deviceClassName": { + "default": "", + "description": "DeviceClassName references a specific DeviceClass, which can define additional configuration and selectors to be inherited by this subrequest.\n\nA class is required. Which classes are available depends on the cluster.\n\nAdministrators may use this to restrict which devices may get requested by only installing classes with selectors for permitted devices. If users are free to request anything without restrictions, then administrators can create an empty DeviceClass for users to reference.", + "type": "string" + }, + "name": { + "default": "", + "description": "Name can be used to reference this subrequest in the list of constraints or the list of configurations for the claim. References must use the format
/.\n\nMust be a DNS label.", + "type": "string" + }, + "selectors": { + "description": "Selectors define criteria which must be satisfied by a specific device in order for that device to be considered for this subrequest. All selectors must be satisfied for a device to be considered.", + "items": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.resource.v1.DeviceSelector" + } + ], + "default": {} + }, + "type": "array", + "x-kubernetes-list-type": "atomic" + }, + "tolerations": { + "description": "If specified, the request's tolerations.\n\nTolerations for NoSchedule are required to allocate a device which has a taint with that effect. The same applies to NoExecute.\n\nIn addition, should any of the allocated devices get tainted with NoExecute after allocation and that effect is not tolerated, then all pods consuming the ResourceClaim get deleted to evict them. The scheduler will not let new pods reserve the claim while it has these tainted devices. Once all pods are evicted, the claim will get deallocated.\n\nThe maximum number of tolerations is 16.\n\nThis is an alpha field and requires enabling the DRADeviceTaints feature gate.", + "items": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.api.resource.v1.DeviceToleration" + } + ], + "default": {} + }, + "type": "array", + "x-kubernetes-list-type": "atomic" + } + }, + "required": [ + "name", + "deviceClassName" + ], + "type": "object" + }, + "io.k8s.api.resource.v1.DeviceTaint": { + "description": "The device this taint is attached to has the \"effect\" on any claim which does not tolerate the taint and, through the claim, to pods using the claim.", + "properties": { + "effect": { + "default": "", + "description": "The effect of the taint on claims that do not tolerate the taint and through such claims on the pods using them.\n\nValid effects are None, NoSchedule and NoExecute. PreferNoSchedule as used for nodes is not valid here. More effects may get added in the future. Consumers must treat unknown effects like None.", + "type": "string" + }, + "key": { + "default": "", + "description": "The taint key to be applied to a device. Must be a label name.", + "type": "string" + }, + "timeAdded": { + "allOf": [ + { + "$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.Time" + } + ], + "description": "TimeAdded represents the time at which the taint was added. Added automatically during create or update if not set." + }, + "value": { + "description": "The taint value corresponding to the taint key. Must be a label value.", + "type": "string" + } + }, + "required": [ + "key", + "effect" + ], + "type": "object" + }, + "io.k8s.api.resource.v1.DeviceToleration": { + "description": "The ResourceClaim this DeviceToleration is attached to tolerates any taint that matches the triple using the matching operator .", + "properties": { + "effect": { + "description": "Effect indicates the taint effect to match. Empty means match all taint effects. When specified, allowed values are NoSchedule and NoExecute.", + "type": "string" + }, + "key": { + "description": "Key is the taint key that the toleration applies to. Empty means match all taint keys. If the key is empty, operator must be Exists; this combination means to match all values and all keys. Must be a label name.", + "type": "string" + }, + "operator": { + "default": "Equal", + "description": "Operator represents a key's relationship to the value. Valid operators are Exists and Equal. Defaults to Equal. Exists is equivalent to wildcard for value, so that a ResourceClaim can tolerate all taints of a particular category.", + "type": "string" + }, + "tolerationSeconds": { + "description": "TolerationSeconds represents the period of time the toleration (which must be of effect NoExecute, otherwise this field is ignored) tolerates the taint. By default, it is not set, which means tolerate the taint forever (do not evict). Zero and negative values will be treated as 0 (evict immediately) by the system. If larger than zero, the time when the pod needs to be evicted is calculated as