From f009d3a3e99aa174b03b09eca39f9f6b773f0230 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20G=C3=BCnzler?= Date: Thu, 28 Jan 2021 12:59:22 +0100 Subject: [PATCH] Fix gpu label support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The device request object was created with untouched fields left unset. When comparing state to determine if a transition is required this would result in a mismatch between: { Driver: '', Count: 1, DeviceIDs: null, Capabilities: [Array], Options: null } and { Count: 1, Capabilities: [Array], } Which in turn resulted in the target service being continously restarted. The fix is to instantiate the object in full. Connects-to: https://github.com/balena-io/balena-supervisor/issues/1449 Connects-to: ae646a07ec6a6c96f7cb91f1d37898a94dbab47a Change-type: patch Signed-off-by: Robert Günzler --- src/compose/utils.ts | 3 +++ test/04-service.spec.ts | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/compose/utils.ts b/src/compose/utils.ts index 16be1890..42b71db0 100644 --- a/src/compose/utils.ts +++ b/src/compose/utils.ts @@ -402,8 +402,11 @@ export async function addFeaturesFromLabels( // bahavior of docker cli // https://github.com/balena-os/balena-engine-cli/blob/19.03-balena/opts/gpus.go#L81-L89 service.config.deviceRequests.push({ + Driver: '', Count: 1, + DeviceIDs: [], Capabilities: [['gpu']], + Options: {}, } as Dockerode.DeviceRequest), }; diff --git a/test/04-service.spec.ts b/test/04-service.spec.ts index 0b0bb145..4085484e 100644 --- a/test/04-service.spec.ts +++ b/test/04-service.spec.ts @@ -503,8 +503,11 @@ describe('compose/service', () => { describe('io.balena.features.gpu: Docker <-> Compose config', () => { const gpuDeviceRequest = { + Driver: '', + DeviceIDs: [], Count: 1, Capabilities: [['gpu']], + Options: {}, }; it('should succeed from compose object', async () => { const s = await Service.fromComposeObject(