Skip to content

Commit 86b9986

Browse files
authored
Merge pull request kubernetes#128299 from SergeyKanzhelev/updateDHS
Update Device Health fields description for KEP-4680
2 parents eb5c896 + 5cfaf47 commit 86b9986

File tree

9 files changed

+176
-41
lines changed

9 files changed

+176
-41
lines changed

api/openapi-spec/swagger.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/openapi-spec/v3/api__v1_openapi.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6617,7 +6617,7 @@
66176617
"x-kubernetes-map-type": "atomic"
66186618
},
66196619
"io.k8s.api.core.v1.ResourceHealth": {
6620-
"description": "ResourceHealth represents the health of a resource. It has the latest device health information. This is a part of KEP https://kep.k8s.io/4680 and historical health changes are planned to be added in future iterations of a KEP.",
6620+
"description": "ResourceHealth represents the health of a resource. It has the latest device health information. This is a part of KEP https://kep.k8s.io/4680.",
66216621
"properties": {
66226622
"health": {
66236623
"description": "Health of the resource. can be one of:\n - Healthy: operates as normal\n - Unhealthy: reported unhealthy. We consider this a temporary health issue\n since we do not have a mechanism today to distinguish\n temporary and permanent issues.\n - Unknown: The status cannot be determined.\n For example, Device Plugin got unregistered and hasn't been re-registered since.\n\nIn future we may want to introduce the PermanentlyUnhealthy Status.",
@@ -6817,11 +6817,11 @@
68176817
"properties": {
68186818
"name": {
68196819
"default": "",
6820-
"description": "Name of the resource. Must be unique within the pod and match one of the resources from the pod spec.",
6820+
"description": "Name of the resource. Must be unique within the pod and in case of non-DRA resource, match one of the resources from the pod spec. For DRA resources, the value must be \"claim:<claim_name>/<request>\". When this status is reported about a container, the \"claim_name\" and \"request\" must match one of the claims of this container.",
68216821
"type": "string"
68226822
},
68236823
"resources": {
6824-
"description": "List of unique Resources health. Each element in the list contains an unique resource ID and resource health. At a minimum, ResourceID must uniquely identify the Resource allocated to the Pod on the Node for the lifetime of a Pod. See ResourceID type for it's definition.",
6824+
"description": "List of unique resources health. Each element in the list contains an unique resource ID and its health. At a minimum, for the lifetime of a Pod, resource ID must uniquely identify the resource allocated to the Pod on the Node. If other Pod on the same Node reports the status with the same resource ID, it must be the same resource they share. See ResourceID type definition for a specific format it has in various use cases.",
68256825
"items": {
68266826
"allOf": [
68276827
{

pkg/apis/core/types.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2788,11 +2788,17 @@ type ContainerStatus struct {
27882788
}
27892789

27902790
type ResourceStatus struct {
2791+
// Name of the resource. Must be unique within the pod and in case of non-DRA resource, match one of the resources from the pod spec.
2792+
// For DRA resources, the value must be "claim:<claim_name>/<request>".
2793+
// When this status is reported about a container, the "claim_name" and "request" must match one of the claims of this container.
2794+
// +required
27912795
Name ResourceName
2792-
// List of unique Resources health. Each element in the list contains a unique resource ID and resource health.
2793-
// At a minimum, ResourceID must uniquely identify the Resource
2794-
// allocated to the Pod on the Node for the lifetime of a Pod.
2795-
// See ResourceID type for it's definition.
2796+
// List of unique resources health. Each element in the list contains an unique resource ID and its health.
2797+
// At a minimum, for the lifetime of a Pod, resource ID must uniquely identify the resource allocated to the Pod on the Node.
2798+
// If other Pod on the same Node reports the status with the same resource ID, it must be the same resource they share.
2799+
// See ResourceID type definition for a specific format it has in various use cases.
2800+
// +listType=map
2801+
// +listMapKey=resourceID
27962802
Resources []ResourceHealth
27972803

27982804
// allow to extend this struct in future with the overall health fields or things like Device Plugin version
@@ -2801,12 +2807,13 @@ type ResourceStatus struct {
28012807
// ResourceID is calculated based on the source of this resource health information.
28022808
// For DevicePlugin:
28032809
//
2804-
// deviceplugin:DeviceID, where DeviceID is from the Device structure of DevicePlugin's ListAndWatchResponse type: https://github.com/kubernetes/kubernetes/blob/eda1c780543a27c078450e2f17d674471e00f494/staging/src/k8s.io/kubelet/pkg/apis/deviceplugin/v1alpha/api.proto#L61-L73
2810+
// DeviceID, where DeviceID is how device plugin identifies the device. The same DeviceID can be found in PodResources API.
28052811
//
28062812
// DevicePlugin ID is usually a constant for the lifetime of a Node and typically can be used to uniquely identify the device on the node.
2813+
//
28072814
// For DRA:
28082815
//
2809-
// dra:<driver name>/<pool name>/<device name>: such a device can be looked up in the information published by that DRA driver to learn more about it. It is designed to be globally unique in a cluster.
2816+
// <driver name>/<pool name>/<device name>: such a device can be looked up in the information published by that DRA driver to learn more about it. It is designed to be globally unique in a cluster.
28102817
type ResourceID string
28112818

28122819
type ResourceHealthStatus string
@@ -2818,7 +2825,7 @@ const (
28182825
)
28192826

28202827
// ResourceHealth represents the health of a resource. It has the latest device health information.
2821-
// This is a part of KEP https://kep.k8s.io/4680 and historical health changes are planned to be added in future iterations of a KEP.
2828+
// This is a part of KEP https://kep.k8s.io/4680.
28222829
type ResourceHealth struct {
28232830
// ResourceID is the unique identifier of the resource. See the ResourceID type for more information.
28242831
ResourceID ResourceID

pkg/apis/core/validation/validation.go

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8260,17 +8260,39 @@ func validateContainerStatusAllocatedResourcesStatus(containerStatuses []core.Co
82608260
// ignore missing container, see https://github.com/kubernetes/kubernetes/issues/124915
82618261
if containerFound {
82628262
found := false
8263+
var errorStr string
82638264

8264-
// get container resources from the spec
8265-
containerResources := container.Resources
8266-
for resourceName := range containerResources.Requests {
8267-
if resourceName == allocatedResource.Name {
8268-
found = true
8269-
break
8265+
if strings.HasPrefix(string(allocatedResource.Name), "claim:") {
8266+
// assume it is a claim name
8267+
8268+
errorStr = "must match one of the container's resource claims in a format 'claim:<claimName>/<request>' or 'claim:<claimName>' if request is empty"
8269+
8270+
for _, c := range container.Resources.Claims {
8271+
name := "claim:" + c.Name
8272+
if c.Request != "" {
8273+
name += "/" + c.Request
8274+
}
8275+
8276+
if name == string(allocatedResource.Name) {
8277+
found = true
8278+
break
8279+
}
8280+
}
8281+
8282+
} else {
8283+
// assume it is a resource name
8284+
8285+
errorStr = "must match one of the container's resource requests"
8286+
8287+
for resourceName := range container.Resources.Requests {
8288+
if resourceName == allocatedResource.Name {
8289+
found = true
8290+
break
8291+
}
82708292
}
82718293
}
82728294
if !found {
8273-
allErrors = append(allErrors, field.Invalid(fldPath.Index(i).Child("allocatedResourcesStatus").Index(j).Child("name"), allocatedResource.Name, "must match one of the container's resource requirements"))
8295+
allErrors = append(allErrors, field.Invalid(fldPath.Index(i).Child("allocatedResourcesStatus").Index(j).Child("name"), allocatedResource.Name, errorStr))
82748296
}
82758297
}
82768298

pkg/apis/core/validation/validation_test.go

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24787,7 +24787,109 @@ func TestValidateContainerStatusAllocatedResourcesStatus(t *testing.T) {
2478724787
},
2478824788
},
2478924789
wantFieldErrors: field.ErrorList{
24790-
field.Invalid(fldPath.Index(0).Child("allocatedResourcesStatus").Index(1).Child("name"), core.ResourceName("test.device/test2"), "must match one of the container's resource requirements"),
24790+
field.Invalid(fldPath.Index(0).Child("allocatedResourcesStatus").Index(1).Child("name"), core.ResourceName("test.device/test2"), "must match one of the container's resource requests"),
24791+
},
24792+
},
24793+
24794+
"allow claims and request that are in spec": {
24795+
containers: []core.Container{
24796+
{
24797+
Name: "container-1",
24798+
Resources: core.ResourceRequirements{
24799+
Claims: []core.ResourceClaim{
24800+
{
24801+
Name: "claim.name",
24802+
Request: "request.name",
24803+
},
24804+
},
24805+
},
24806+
},
24807+
},
24808+
containerStatuses: []core.ContainerStatus{
24809+
{
24810+
Name: "container-1",
24811+
AllocatedResourcesStatus: []core.ResourceStatus{
24812+
{
24813+
Name: "claim:claim.name/request.name",
24814+
Resources: []core.ResourceHealth{
24815+
{
24816+
ResourceID: "driver/pool/device-name",
24817+
Health: core.ResourceHealthStatusHealthy,
24818+
},
24819+
},
24820+
},
24821+
},
24822+
},
24823+
},
24824+
wantFieldErrors: field.ErrorList{},
24825+
},
24826+
24827+
"allow claims that are in spec without the request": {
24828+
containers: []core.Container{
24829+
{
24830+
Name: "container-1",
24831+
Resources: core.ResourceRequirements{
24832+
Claims: []core.ResourceClaim{
24833+
{
24834+
Name: "claim.name",
24835+
},
24836+
},
24837+
},
24838+
},
24839+
},
24840+
containerStatuses: []core.ContainerStatus{
24841+
{
24842+
Name: "container-1",
24843+
AllocatedResourcesStatus: []core.ResourceStatus{
24844+
{
24845+
Name: "claim:claim.name",
24846+
Resources: []core.ResourceHealth{
24847+
{
24848+
ResourceID: "driver/pool/device-name",
24849+
Health: core.ResourceHealthStatusHealthy,
24850+
},
24851+
},
24852+
},
24853+
},
24854+
},
24855+
},
24856+
wantFieldErrors: field.ErrorList{},
24857+
},
24858+
24859+
"don't allow claims that are not in spec": {
24860+
containers: []core.Container{
24861+
{
24862+
Name: "container-1",
24863+
Resources: core.ResourceRequirements{
24864+
Claims: []core.ResourceClaim{
24865+
{
24866+
Name: "other-claim.name",
24867+
},
24868+
},
24869+
Requests: core.ResourceList{
24870+
"claim.name": resource.MustParse("1"),
24871+
},
24872+
},
24873+
},
24874+
},
24875+
containerStatuses: []core.ContainerStatus{
24876+
{
24877+
Name: "container-1",
24878+
AllocatedResourcesStatus: []core.ResourceStatus{
24879+
{
24880+
Name: "claim:claim.name",
24881+
Resources: []core.ResourceHealth{
24882+
{
24883+
ResourceID: "driver/pool/device-name",
24884+
Health: core.ResourceHealthStatusHealthy,
24885+
},
24886+
},
24887+
},
24888+
},
24889+
},
24890+
},
24891+
wantFieldErrors: field.ErrorList{
24892+
field.Invalid(fldPath.Index(0).Child("allocatedResourcesStatus").Index(0).Child("name"), core.ResourceName("claim:claim.name"), "must match one of the container's resource claims in a format 'claim:<claimName>/<request>' or 'claim:<claimName>' if request is empty"),
2479124893
},
2479224894
},
2479324895

pkg/generated/openapi/zz_generated.openapi.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/api/core/v1/generated.proto

Lines changed: 8 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)