mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-02-07 11:50:27 +00:00
Merge pull request #1362 from balena-io/rgz/device-request-gpu
Add label to expose gpu to container
This commit is contained in:
commit
d0bcaa6fa2
@ -370,6 +370,7 @@ export class Service {
|
|||||||
command: [],
|
command: [],
|
||||||
cgroupParent: '',
|
cgroupParent: '',
|
||||||
devices,
|
devices,
|
||||||
|
deviceRequests: [],
|
||||||
dnsOpt: [],
|
dnsOpt: [],
|
||||||
entrypoint: '',
|
entrypoint: '',
|
||||||
extraHosts: [],
|
extraHosts: [],
|
||||||
@ -520,6 +521,7 @@ export class Service {
|
|||||||
capAdd: container.HostConfig.CapAdd || [],
|
capAdd: container.HostConfig.CapAdd || [],
|
||||||
capDrop: container.HostConfig.CapDrop || [],
|
capDrop: container.HostConfig.CapDrop || [],
|
||||||
devices: container.HostConfig.Devices || [],
|
devices: container.HostConfig.Devices || [],
|
||||||
|
deviceRequests: container.HostConfig.DeviceRequests || [],
|
||||||
networks,
|
networks,
|
||||||
memLimit: container.HostConfig.Memory || 0,
|
memLimit: container.HostConfig.Memory || 0,
|
||||||
memReservation: container.HostConfig.MemoryReservation || 0,
|
memReservation: container.HostConfig.MemoryReservation || 0,
|
||||||
@ -640,6 +642,7 @@ export class Service {
|
|||||||
Binds: binds,
|
Binds: binds,
|
||||||
CgroupParent: this.config.cgroupParent,
|
CgroupParent: this.config.cgroupParent,
|
||||||
Devices: this.config.devices,
|
Devices: this.config.devices,
|
||||||
|
DeviceRequests: this.config.deviceRequests,
|
||||||
Dns: this.config.dns,
|
Dns: this.config.dns,
|
||||||
DnsOptions: this.config.dnsOpt,
|
DnsOptions: this.config.dnsOpt,
|
||||||
DnsSearch: this.config.dnsSearch,
|
DnsSearch: this.config.dnsSearch,
|
||||||
|
@ -100,6 +100,7 @@ export interface ServiceConfig {
|
|||||||
command: string[];
|
command: string[];
|
||||||
cgroupParent: string;
|
cgroupParent: string;
|
||||||
devices: DockerDevice[];
|
devices: DockerDevice[];
|
||||||
|
deviceRequests: Dockerode.DeviceRequest[];
|
||||||
dns: string | string[];
|
dns: string | string[];
|
||||||
dnsOpt: string[];
|
dnsOpt: string[];
|
||||||
dnsSearch: string | string[];
|
dnsSearch: string | string[];
|
||||||
|
@ -373,6 +373,15 @@ export function addFeaturesFromLabels(
|
|||||||
'io.balena.features.sysfs': () => service.config.volumes.push('/sys:/sys'),
|
'io.balena.features.sysfs': () => service.config.volumes.push('/sys:/sys'),
|
||||||
'io.balena.features.procfs': () =>
|
'io.balena.features.procfs': () =>
|
||||||
service.config.volumes.push('/proc:/proc'),
|
service.config.volumes.push('/proc:/proc'),
|
||||||
|
'io.balena.features.gpu': () =>
|
||||||
|
// TODO once the compose-spec has an implementation we
|
||||||
|
// should probably follow that, for now we copy the
|
||||||
|
// 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({
|
||||||
|
Count: 1,
|
||||||
|
Capabilities: [['gpu']],
|
||||||
|
} as Dockerode.DeviceRequest),
|
||||||
};
|
};
|
||||||
|
|
||||||
_.each(features, (fn, label) => {
|
_.each(features, (fn, label) => {
|
||||||
|
@ -464,6 +464,42 @@ describe('compose/service', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('io.balena.features.gpu: Docker <-> Compose config', () => {
|
||||||
|
const gpuDeviceRequest = {
|
||||||
|
Count: 1,
|
||||||
|
Capabilities: [['gpu']],
|
||||||
|
};
|
||||||
|
it('should succeed from compose object', () => {
|
||||||
|
const s = Service.fromComposeObject(
|
||||||
|
{
|
||||||
|
appId: 123,
|
||||||
|
serviceId: 123,
|
||||||
|
serviceName: 'test',
|
||||||
|
labels: {
|
||||||
|
'io.balena.features.gpu': '1',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ appName: 'test' } as any,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(s.config)
|
||||||
|
.to.have.property('deviceRequests')
|
||||||
|
.that.deep.equals([gpuDeviceRequest]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should succeed from docker container', () => {
|
||||||
|
const dockerCfg = _.cloneDeep(
|
||||||
|
require('./data/docker-states/simple/inspect.json'),
|
||||||
|
);
|
||||||
|
dockerCfg.HostConfig.DeviceRequests = [gpuDeviceRequest];
|
||||||
|
const s = Service.fromDockerContainer(dockerCfg);
|
||||||
|
|
||||||
|
expect(s.config)
|
||||||
|
.to.have.property('deviceRequests')
|
||||||
|
.that.deep.equals([gpuDeviceRequest]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('Docker <-> Compose config', () => {
|
describe('Docker <-> Compose config', () => {
|
||||||
const omitConfigForComparison = (config: ServiceConfig) =>
|
const omitConfigForComparison = (config: ServiceConfig) =>
|
||||||
_.omit(config, ['running', 'networks']);
|
_.omit(config, ['running', 'networks']);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user