From 8774dee09ef81b4f4b9b9623c21b59eda01105c9 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Wed, 27 Mar 2024 11:20:37 +0100 Subject: [PATCH 1/3] DRA api: explicitly reserve finalizer for Kubernetes The k8s.io in the string and conventions around finalizers for DRA driver controllers implied that this is for use by Kubernetes, but it's better to be explicit about this. --- staging/src/k8s.io/api/resource/v1alpha2/types.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/staging/src/k8s.io/api/resource/v1alpha2/types.go b/staging/src/k8s.io/api/resource/v1alpha2/types.go index 9005144cf69..2441f17eca4 100644 --- a/staging/src/k8s.io/api/resource/v1alpha2/types.go +++ b/staging/src/k8s.io/api/resource/v1alpha2/types.go @@ -26,6 +26,8 @@ import ( const ( // Finalizer is the finalizer that gets set for claims // which were allocated through a builtin controller. + // Reserved for use by Kubernetes, DRA driver controllers must + // use their own finalizer. Finalizer = "dra.k8s.io/delete-protection" ) From 1a13b0aa3333d04ae67a6fcdd21c8e2a042dc0c2 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Wed, 27 Mar 2024 11:22:35 +0100 Subject: [PATCH 2/3] DRA api: ResourceHandle.DriverName is required It was already required via validation, but not declared as such by the OpenAPI. --- api/openapi-spec/swagger.json | 3 +++ .../v3/apis__resource.k8s.io__v1alpha2_openapi.json | 4 ++++ pkg/generated/openapi/zz_generated.openapi.go | 2 ++ staging/src/k8s.io/api/resource/v1alpha2/types.go | 2 +- .../k8s.io/client-go/applyconfigurations/internal/internal.go | 1 + 5 files changed, 11 insertions(+), 1 deletion(-) diff --git a/api/openapi-spec/swagger.json b/api/openapi-spec/swagger.json index c5d57305c66..7fa6b9173c7 100644 --- a/api/openapi-spec/swagger.json +++ b/api/openapi-spec/swagger.json @@ -15792,6 +15792,9 @@ "description": "If StructuredData is set, then it needs to be used instead of Data." } }, + "required": [ + "driverName" + ], "type": "object" }, "io.k8s.api.resource.v1alpha2.ResourceRequest": { diff --git a/api/openapi-spec/v3/apis__resource.k8s.io__v1alpha2_openapi.json b/api/openapi-spec/v3/apis__resource.k8s.io__v1alpha2_openapi.json index 6ad77830054..ac93252ae8a 100644 --- a/api/openapi-spec/v3/apis__resource.k8s.io__v1alpha2_openapi.json +++ b/api/openapi-spec/v3/apis__resource.k8s.io__v1alpha2_openapi.json @@ -1205,6 +1205,7 @@ "type": "string" }, "driverName": { + "default": "", "description": "DriverName specifies the name of the resource driver whose kubelet plugin should be invoked to process this ResourceHandle's data once it lands on a node. This may differ from the DriverName set in ResourceClaimStatus this ResourceHandle is embedded in.", "type": "string" }, @@ -1217,6 +1218,9 @@ "description": "If StructuredData is set, then it needs to be used instead of Data." } }, + "required": [ + "driverName" + ], "type": "object" }, "io.k8s.api.resource.v1alpha2.ResourceRequest": { diff --git a/pkg/generated/openapi/zz_generated.openapi.go b/pkg/generated/openapi/zz_generated.openapi.go index 1fc94fee217..ed1a245d287 100644 --- a/pkg/generated/openapi/zz_generated.openapi.go +++ b/pkg/generated/openapi/zz_generated.openapi.go @@ -46488,6 +46488,7 @@ func schema_k8sio_api_resource_v1alpha2_ResourceHandle(ref common.ReferenceCallb "driverName": { SchemaProps: spec.SchemaProps{ Description: "DriverName specifies the name of the resource driver whose kubelet plugin should be invoked to process this ResourceHandle's data once it lands on a node. This may differ from the DriverName set in ResourceClaimStatus this ResourceHandle is embedded in.", + Default: "", Type: []string{"string"}, Format: "", }, @@ -46506,6 +46507,7 @@ func schema_k8sio_api_resource_v1alpha2_ResourceHandle(ref common.ReferenceCallb }, }, }, + Required: []string{"driverName"}, }, }, Dependencies: []string{ diff --git a/staging/src/k8s.io/api/resource/v1alpha2/types.go b/staging/src/k8s.io/api/resource/v1alpha2/types.go index 2441f17eca4..fa0f2cd707f 100644 --- a/staging/src/k8s.io/api/resource/v1alpha2/types.go +++ b/staging/src/k8s.io/api/resource/v1alpha2/types.go @@ -188,7 +188,7 @@ type ResourceHandle struct { // plugin should be invoked to process this ResourceHandle's data once it // lands on a node. This may differ from the DriverName set in // ResourceClaimStatus this ResourceHandle is embedded in. - DriverName string `json:"driverName,omitempty" protobuf:"bytes,1,opt,name=driverName"` + DriverName string `json:"driverName" protobuf:"bytes,1,name=driverName"` // Data contains the opaque data associated with this ResourceHandle. It is // set by the controller component of the resource driver whose name diff --git a/staging/src/k8s.io/client-go/applyconfigurations/internal/internal.go b/staging/src/k8s.io/client-go/applyconfigurations/internal/internal.go index 0d753b07b15..f3314a39ee2 100644 --- a/staging/src/k8s.io/client-go/applyconfigurations/internal/internal.go +++ b/staging/src/k8s.io/client-go/applyconfigurations/internal/internal.go @@ -12413,6 +12413,7 @@ var schemaYAML = typed.YAMLObject(`types: - name: driverName type: scalar: string + default: "" - name: structuredData type: namedType: io.k8s.api.resource.v1alpha2.StructuredResourceHandle From acfaf8c27590c78fe9900f8c7c1e99927392c20e Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Wed, 27 Mar 2024 12:03:24 +0100 Subject: [PATCH 3/3] DRA: sync internal API doc comments This had been done before for types.go, but namedresources.go still had one small diff. While at it, fix some typos. --- api/openapi-spec/swagger.json | 4 ++-- api/openapi-spec/v3/api__v1_openapi.json | 2 +- .../v3/apis__resource.k8s.io__v1alpha2_openapi.json | 2 +- pkg/apis/core/types.go | 2 +- pkg/apis/resource/namedresources.go | 12 ++++++++++-- pkg/generated/openapi/zz_generated.openapi.go | 4 ++-- staging/src/k8s.io/api/core/v1/generated.proto | 2 +- staging/src/k8s.io/api/core/v1/types.go | 2 +- .../api/core/v1/types_swagger_doc_generated.go | 2 +- .../src/k8s.io/api/resource/v1alpha2/generated.proto | 2 +- .../k8s.io/api/resource/v1alpha2/namedresources.go | 2 +- 11 files changed, 22 insertions(+), 14 deletions(-) diff --git a/api/openapi-spec/swagger.json b/api/openapi-spec/swagger.json index 7fa6b9173c7..1720628f809 100644 --- a/api/openapi-spec/swagger.json +++ b/api/openapi-spec/swagger.json @@ -9349,7 +9349,7 @@ "type": "string" }, "resourceClaimName": { - "description": "ResourceClaimName is the name of the ResourceClaim that was generated for the Pod in the namespace of the Pod. It this is unset, then generating a ResourceClaim was not necessary. The pod.spec.resourceClaims entry can be ignored in this case.", + "description": "ResourceClaimName is the name of the ResourceClaim that was generated for the Pod in the namespace of the Pod. If this is unset, then generating a ResourceClaim was not necessary. The pod.spec.resourceClaims entry can be ignored in this case.", "type": "string" } }, @@ -15026,7 +15026,7 @@ "description": "NamedResourcesFilter is used in ResourceFilterModel.", "properties": { "selector": { - "description": "Selector is a CEL expression which must evaluate to true if a resource instance is suitable. The language is as defined in https://kubernetes.io/docs/reference/using-api/cel/\n\nIn addition, for each type NamedResourcesin AttributeValue there is a map that resolves to the corresponding value of the instance under evaluation. For example:\n\n attributes.quantity[\"a\"].isGreaterThan(quantity(\"0\")) &&\n attributes.stringslice[\"b\"].isSorted()", + "description": "Selector is a CEL expression which must evaluate to true if a resource instance is suitable. The language is as defined in https://kubernetes.io/docs/reference/using-api/cel/\n\nIn addition, for each type in NamedResourcesAttributeValue there is a map that resolves to the corresponding value of the instance under evaluation. For example:\n\n attributes.quantity[\"a\"].isGreaterThan(quantity(\"0\")) &&\n attributes.stringslice[\"b\"].isSorted()", "type": "string" } }, diff --git a/api/openapi-spec/v3/api__v1_openapi.json b/api/openapi-spec/v3/api__v1_openapi.json index 7d42bbcac86..3cd70a449db 100644 --- a/api/openapi-spec/v3/api__v1_openapi.json +++ b/api/openapi-spec/v3/api__v1_openapi.json @@ -5221,7 +5221,7 @@ "type": "string" }, "resourceClaimName": { - "description": "ResourceClaimName is the name of the ResourceClaim that was generated for the Pod in the namespace of the Pod. It this is unset, then generating a ResourceClaim was not necessary. The pod.spec.resourceClaims entry can be ignored in this case.", + "description": "ResourceClaimName is the name of the ResourceClaim that was generated for the Pod in the namespace of the Pod. If this is unset, then generating a ResourceClaim was not necessary. The pod.spec.resourceClaims entry can be ignored in this case.", "type": "string" } }, diff --git a/api/openapi-spec/v3/apis__resource.k8s.io__v1alpha2_openapi.json b/api/openapi-spec/v3/apis__resource.k8s.io__v1alpha2_openapi.json index ac93252ae8a..abe72129b03 100644 --- a/api/openapi-spec/v3/apis__resource.k8s.io__v1alpha2_openapi.json +++ b/api/openapi-spec/v3/apis__resource.k8s.io__v1alpha2_openapi.json @@ -244,7 +244,7 @@ "properties": { "selector": { "default": "", - "description": "Selector is a CEL expression which must evaluate to true if a resource instance is suitable. The language is as defined in https://kubernetes.io/docs/reference/using-api/cel/\n\nIn addition, for each type NamedResourcesin AttributeValue there is a map that resolves to the corresponding value of the instance under evaluation. For example:\n\n attributes.quantity[\"a\"].isGreaterThan(quantity(\"0\")) &&\n attributes.stringslice[\"b\"].isSorted()", + "description": "Selector is a CEL expression which must evaluate to true if a resource instance is suitable. The language is as defined in https://kubernetes.io/docs/reference/using-api/cel/\n\nIn addition, for each type in NamedResourcesAttributeValue there is a map that resolves to the corresponding value of the instance under evaluation. For example:\n\n attributes.quantity[\"a\"].isGreaterThan(quantity(\"0\")) &&\n attributes.stringslice[\"b\"].isSorted()", "type": "string" } }, diff --git a/pkg/apis/core/types.go b/pkg/apis/core/types.go index 4fa9ca3738d..90770f2792d 100644 --- a/pkg/apis/core/types.go +++ b/pkg/apis/core/types.go @@ -3477,7 +3477,7 @@ type PodResourceClaimStatus struct { Name string // ResourceClaimName is the name of the ResourceClaim that was - // generated for the Pod in the namespace of the Pod. It this is + // generated for the Pod in the namespace of the Pod. If this is // unset, then generating a ResourceClaim was not necessary. The // pod.spec.resourceClaims entry can be ignored in this case. ResourceClaimName *string diff --git a/pkg/apis/resource/namedresources.go b/pkg/apis/resource/namedresources.go index 7cdb0748c02..4e96d9b0a41 100644 --- a/pkg/apis/resource/namedresources.go +++ b/pkg/apis/resource/namedresources.go @@ -92,8 +92,16 @@ type NamedResourcesRequest struct { // NamedResourcesFilter is used in ResourceFilterModel. type NamedResourcesFilter struct { - // Selector is a selector like the one in Request. It must be true for - // a resource instance to be suitable for a claim using the class. + // Selector is a CEL expression which must evaluate to true if a + // resource instance is suitable. The language is as defined in + // https://kubernetes.io/docs/reference/using-api/cel/ + // + // In addition, for each type in NamedResourcesAttributeValue there is a map that + // resolves to the corresponding value of the instance under evaluation. + // For example: + // + // attributes.quantity["a"].isGreaterThan(quantity("0")) && + // attributes.stringslice["b"].isSorted() Selector string } diff --git a/pkg/generated/openapi/zz_generated.openapi.go b/pkg/generated/openapi/zz_generated.openapi.go index ed1a245d287..66e5d4f60e1 100644 --- a/pkg/generated/openapi/zz_generated.openapi.go +++ b/pkg/generated/openapi/zz_generated.openapi.go @@ -26996,7 +26996,7 @@ func schema_k8sio_api_core_v1_PodResourceClaimStatus(ref common.ReferenceCallbac }, "resourceClaimName": { SchemaProps: spec.SchemaProps{ - Description: "ResourceClaimName is the name of the ResourceClaim that was generated for the Pod in the namespace of the Pod. It this is unset, then generating a ResourceClaim was not necessary. The pod.spec.resourceClaims entry can be ignored in this case.", + Description: "ResourceClaimName is the name of the ResourceClaim that was generated for the Pod in the namespace of the Pod. If this is unset, then generating a ResourceClaim was not necessary. The pod.spec.resourceClaims entry can be ignored in this case.", Type: []string{"string"}, Format: "", }, @@ -45215,7 +45215,7 @@ func schema_k8sio_api_resource_v1alpha2_NamedResourcesFilter(ref common.Referenc Properties: map[string]spec.Schema{ "selector": { SchemaProps: spec.SchemaProps{ - Description: "Selector is a CEL expression which must evaluate to true if a resource instance is suitable. The language is as defined in https://kubernetes.io/docs/reference/using-api/cel/\n\nIn addition, for each type NamedResourcesin AttributeValue there is a map that resolves to the corresponding value of the instance under evaluation. For example:\n\n attributes.quantity[\"a\"].isGreaterThan(quantity(\"0\")) &&\n attributes.stringslice[\"b\"].isSorted()", + Description: "Selector is a CEL expression which must evaluate to true if a resource instance is suitable. The language is as defined in https://kubernetes.io/docs/reference/using-api/cel/\n\nIn addition, for each type in NamedResourcesAttributeValue there is a map that resolves to the corresponding value of the instance under evaluation. For example:\n\n attributes.quantity[\"a\"].isGreaterThan(quantity(\"0\")) &&\n attributes.stringslice[\"b\"].isSorted()", Default: "", Type: []string{"string"}, Format: "", diff --git a/staging/src/k8s.io/api/core/v1/generated.proto b/staging/src/k8s.io/api/core/v1/generated.proto index 021e45e890a..96c50d0fefc 100644 --- a/staging/src/k8s.io/api/core/v1/generated.proto +++ b/staging/src/k8s.io/api/core/v1/generated.proto @@ -3813,7 +3813,7 @@ message PodResourceClaimStatus { optional string name = 1; // ResourceClaimName is the name of the ResourceClaim that was - // generated for the Pod in the namespace of the Pod. It this is + // generated for the Pod in the namespace of the Pod. If this is // unset, then generating a ResourceClaim was not necessary. The // pod.spec.resourceClaims entry can be ignored in this case. // diff --git a/staging/src/k8s.io/api/core/v1/types.go b/staging/src/k8s.io/api/core/v1/types.go index 803679c48ba..a20d54cd33d 100644 --- a/staging/src/k8s.io/api/core/v1/types.go +++ b/staging/src/k8s.io/api/core/v1/types.go @@ -3929,7 +3929,7 @@ type PodResourceClaimStatus struct { Name string `json:"name" protobuf:"bytes,1,name=name"` // ResourceClaimName is the name of the ResourceClaim that was - // generated for the Pod in the namespace of the Pod. It this is + // generated for the Pod in the namespace of the Pod. If this is // unset, then generating a ResourceClaim was not necessary. The // pod.spec.resourceClaims entry can be ignored in this case. // diff --git a/staging/src/k8s.io/api/core/v1/types_swagger_doc_generated.go b/staging/src/k8s.io/api/core/v1/types_swagger_doc_generated.go index 5470aebc559..6c46a70e4d3 100644 --- a/staging/src/k8s.io/api/core/v1/types_swagger_doc_generated.go +++ b/staging/src/k8s.io/api/core/v1/types_swagger_doc_generated.go @@ -1708,7 +1708,7 @@ func (PodResourceClaim) SwaggerDoc() map[string]string { var map_PodResourceClaimStatus = map[string]string{ "": "PodResourceClaimStatus is stored in the PodStatus for each PodResourceClaim which references a ResourceClaimTemplate. It stores the generated name for the corresponding ResourceClaim.", "name": "Name uniquely identifies this resource claim inside the pod. This must match the name of an entry in pod.spec.resourceClaims, which implies that the string must be a DNS_LABEL.", - "resourceClaimName": "ResourceClaimName is the name of the ResourceClaim that was generated for the Pod in the namespace of the Pod. It this is unset, then generating a ResourceClaim was not necessary. The pod.spec.resourceClaims entry can be ignored in this case.", + "resourceClaimName": "ResourceClaimName is the name of the ResourceClaim that was generated for the Pod in the namespace of the Pod. If this is unset, then generating a ResourceClaim was not necessary. The pod.spec.resourceClaims entry can be ignored in this case.", } func (PodResourceClaimStatus) SwaggerDoc() map[string]string { diff --git a/staging/src/k8s.io/api/resource/v1alpha2/generated.proto b/staging/src/k8s.io/api/resource/v1alpha2/generated.proto index 4a6a5bab6c5..fcdaaf6ad17 100644 --- a/staging/src/k8s.io/api/resource/v1alpha2/generated.proto +++ b/staging/src/k8s.io/api/resource/v1alpha2/generated.proto @@ -145,7 +145,7 @@ message NamedResourcesFilter { // resource instance is suitable. The language is as defined in // https://kubernetes.io/docs/reference/using-api/cel/ // - // In addition, for each type NamedResourcesin AttributeValue there is a map that + // In addition, for each type in NamedResourcesAttributeValue there is a map that // resolves to the corresponding value of the instance under evaluation. // For example: // diff --git a/staging/src/k8s.io/api/resource/v1alpha2/namedresources.go b/staging/src/k8s.io/api/resource/v1alpha2/namedresources.go index b80c5c1432f..7c255b45cba 100644 --- a/staging/src/k8s.io/api/resource/v1alpha2/namedresources.go +++ b/staging/src/k8s.io/api/resource/v1alpha2/namedresources.go @@ -111,7 +111,7 @@ type NamedResourcesFilter struct { // resource instance is suitable. The language is as defined in // https://kubernetes.io/docs/reference/using-api/cel/ // - // In addition, for each type NamedResourcesin AttributeValue there is a map that + // In addition, for each type in NamedResourcesAttributeValue there is a map that // resolves to the corresponding value of the instance under evaluation. // For example: //