Skip to content

Commit 8daf7e8

Browse files
Added support of Generic resources in compose file
Signed-off-by: Renaud Gaubert <[email protected]>
1 parent 6ef981a commit 8daf7e8

6 files changed

Lines changed: 93 additions & 17 deletions

File tree

cli/compose/convert/service.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,9 +510,25 @@ func convertResources(source composetypes.Resources) (*swarm.ResourceRequirement
510510
return nil, err
511511
}
512512
}
513+
514+
var generic []swarm.GenericResource
515+
for _, res := range source.Reservations.GenericResources {
516+
var r swarm.GenericResource
517+
518+
if res.DiscreteResourceSpec != nil {
519+
r.DiscreteResourceSpec = &swarm.DiscreteGenericResource{
520+
Kind: res.DiscreteResourceSpec.Kind,
521+
Value: res.DiscreteResourceSpec.Value,
522+
}
523+
}
524+
525+
generic = append(generic, r)
526+
}
527+
513528
resources.Reservations = &swarm.Resources{
514-
NanoCPUs: cpus,
515-
MemoryBytes: int64(source.Reservations.MemoryBytes),
529+
NanoCPUs: cpus,
530+
MemoryBytes: int64(source.Reservations.MemoryBytes),
531+
GenericResources: generic,
516532
}
517533
}
518534
return resources, nil

cli/compose/loader/full-example.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "3.4"
1+
version: "3.5"
22

33
services:
44
foo:
@@ -16,7 +16,6 @@ services:
1616
labels: [FOO=BAR]
1717

1818

19-
2019
cap_add:
2120
- ALL
2221

@@ -54,6 +53,13 @@ services:
5453
reservations:
5554
cpus: '0.0001'
5655
memory: 20M
56+
generic_resources:
57+
- discrete_resource_spec:
58+
kind: 'gpu'
59+
value: 2
60+
- discrete_resource_spec:
61+
kind: 'ssd'
62+
value: 1
5763
restart_policy:
5864
condition: on-failure
5965
delay: 5s

cli/compose/loader/loader_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,20 @@ func TestFullExample(t *testing.T) {
879879
Reservations: &types.Resource{
880880
NanoCPUs: "0.0001",
881881
MemoryBytes: 20 * 1024 * 1024,
882+
GenericResources: []types.GenericResource{
883+
{
884+
DiscreteResourceSpec: &types.DiscreteGenericResource{
885+
Kind: "gpu",
886+
Value: 2,
887+
},
888+
},
889+
{
890+
DiscreteResourceSpec: &types.DiscreteGenericResource{
891+
Kind: "ssd",
892+
Value: 1,
893+
},
894+
},
895+
},
882896
},
883897
},
884898
RestartPolicy: &types.RestartPolicy{

cli/compose/schema/bindata.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/compose/schema/data/config_schema_v3.5.json

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,23 @@
354354
"resources": {
355355
"type": "object",
356356
"properties": {
357-
"limits": {"$ref": "#/definitions/resource"},
358-
"reservations": {"$ref": "#/definitions/resource"}
357+
"limits": {
358+
"type": "object",
359+
"properties": {
360+
"cpus": {"type": "string"},
361+
"memory": {"type": "string"}
362+
},
363+
"additionalProperties": false
364+
},
365+
"reservations": {
366+
"type": "object",
367+
"properties": {
368+
"cpus": {"type": "string"},
369+
"memory": {"type": "string"},
370+
"generic_resources": {"$ref": "#/definitions/generic_resources"}
371+
},
372+
"additionalProperties": false
373+
}
359374
},
360375
"additionalProperties": false
361376
},
@@ -390,14 +405,23 @@
390405
"additionalProperties": false
391406
},
392407

393-
"resource": {
394-
"id": "#/definitions/resource",
395-
"type": "object",
396-
"properties": {
397-
"cpus": {"type": "string"},
398-
"memory": {"type": "string"}
399-
},
400-
"additionalProperties": false
408+
"generic_resources": {
409+
"id": "#/definitions/generic_resources",
410+
"type": "array",
411+
"items": {
412+
"type": "object",
413+
"properties": {
414+
"discrete_resource_spec": {
415+
"type": "object",
416+
"properties": {
417+
"kind": {"type": "string"},
418+
"value": {"type": "number"}
419+
},
420+
"additionalProperties": false
421+
}
422+
},
423+
"additionalProperties": false
424+
}
401425
},
402426

403427
"network": {

0 commit comments

Comments
 (0)