From 84748c7d4e626edf2dc2c6984ffd306c35865d21 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 9 May 2020 11:55:08 +0200 Subject: [PATCH] API: split types for Resources Reservations and Limits This introduces A new type (`Limit`), which allows Limits and "Reservations" to have different options, as it's not possible to make "Reservations" for some kind of limits. The `GenericResources` have been removed from the new type; the API did not handle specifying `GenericResources` as a _Limit_ (only as _Reservations_), and this field would therefore always be empty (omitted) in the `Limits` case. Signed-off-by: Sebastiaan van Stijn --- api/swagger.yaml | 16 +++++++++++++++- api/types/swarm/task.go | 11 +++++++++-- daemon/cluster/convert/service.go | 2 +- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/api/swagger.yaml b/api/swagger.yaml index f48e7057a9..dbfcf652f0 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -625,6 +625,20 @@ definitions: type: "integer" format: "int64" + Limit: + description: | + An object describing a limit on resources which can be requested by a task. + type: "object" + properties: + NanoCPUs: + type: "integer" + format: "int64" + example: 4000000000 + MemoryBytes: + type: "integer" + format: "int64" + example: 8272408576 + ResourceObject: description: | An object describing the resources which can be advertised by a node and @@ -3262,7 +3276,7 @@ definitions: properties: Limits: description: "Define resources limits." - $ref: "#/definitions/ResourceObject" + $ref: "#/definitions/Limit" Reservation: description: "Define resources reservation." $ref: "#/definitions/ResourceObject" diff --git a/api/types/swarm/task.go b/api/types/swarm/task.go index 9f193df37c..baeef685e0 100644 --- a/api/types/swarm/task.go +++ b/api/types/swarm/task.go @@ -91,13 +91,20 @@ type TaskSpec struct { Runtime RuntimeType `json:",omitempty"` } -// Resources represents resources (CPU/Memory). +// Resources represents resources (CPU/Memory) which can be advertised by a +// node and requested to be reserved for a task. type Resources struct { NanoCPUs int64 `json:",omitempty"` MemoryBytes int64 `json:",omitempty"` GenericResources []GenericResource `json:",omitempty"` } +// Limit describes limits on resources which can be requested by a task. +type Limit struct { + NanoCPUs int64 `json:",omitempty"` + MemoryBytes int64 `json:",omitempty"` +} + // GenericResource represents a "user defined" resource which can // be either an integer (e.g: SSD=3) or a string (e.g: SSD=sda1) type GenericResource struct { @@ -125,7 +132,7 @@ type DiscreteGenericResource struct { // ResourceRequirements represents resources requirements. type ResourceRequirements struct { - Limits *Resources `json:",omitempty"` + Limits *Limit `json:",omitempty"` Reservations *Resources `json:",omitempty"` } diff --git a/daemon/cluster/convert/service.go b/daemon/cluster/convert/service.go index 144bc4cc93..1daabd0156 100644 --- a/daemon/cluster/convert/service.go +++ b/daemon/cluster/convert/service.go @@ -401,7 +401,7 @@ func resourcesFromGRPC(res *swarmapi.ResourceRequirements) *types.ResourceRequir if res != nil { resources = &types.ResourceRequirements{} if res.Limits != nil { - resources.Limits = &types.Resources{ + resources.Limits = &types.Limit{ NanoCPUs: res.Limits.NanoCPUs, MemoryBytes: res.Limits.MemoryBytes, }