mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-02-20 17:52:51 +00:00
Cleanup unused methods and dependencies on db ids
This commit is contained in:
parent
381abeadb9
commit
f1cd3d367c
@ -169,7 +169,7 @@ export async function getRequiredSteps(
|
||||
imageManager.getDownloadingImageNames(),
|
||||
imageManager.getAvailable(),
|
||||
]);
|
||||
const containerIdsByAppId = await getAppContainerIds(currentApps);
|
||||
const containerIdsByAppId = getAppContainerIds(currentApps);
|
||||
|
||||
return await inferNextSteps(currentApps, targetApps, {
|
||||
ignoreImages,
|
||||
@ -776,9 +776,10 @@ function saveAndRemoveImages(
|
||||
(svc) =>
|
||||
_.find(availableImages, {
|
||||
dockerImageId: svc.config.image,
|
||||
// There is no 1-1 mapping between services and images
|
||||
// on disk, so the only way to compare is by imageId
|
||||
imageId: svc.imageId,
|
||||
// There is no way to compare a current service to an image by
|
||||
// name, the only way to do it is by both commit and service name
|
||||
commit: svc.commit,
|
||||
serviceName: svc.serviceName,
|
||||
}) ?? _.find(availableImages, { dockerImageId: svc.config.image }),
|
||||
),
|
||||
) as imageManager.Image[];
|
||||
@ -878,14 +879,21 @@ function saveAndRemoveImages(
|
||||
.concat(imagesToRemove.map((image) => ({ action: 'removeImage', image })));
|
||||
}
|
||||
|
||||
async function getAppContainerIds(currentApps: InstancedAppState) {
|
||||
function getAppContainerIds(currentApps: InstancedAppState) {
|
||||
const containerIds: { [appId: number]: Dictionary<string> } = {};
|
||||
await Promise.all(
|
||||
_.map(currentApps, async (_app, appId) => {
|
||||
const intAppId = parseInt(appId, 10);
|
||||
containerIds[intAppId] = await serviceManager.getContainerIdMap(intAppId);
|
||||
}),
|
||||
);
|
||||
Object.keys(currentApps).forEach((appId) => {
|
||||
const intAppId = parseInt(appId, 10);
|
||||
const app = currentApps[intAppId];
|
||||
const services = app.services || ([] as Service[]);
|
||||
containerIds[intAppId] = services.reduce(
|
||||
(ids, s) => ({
|
||||
...ids,
|
||||
...(s.serviceName &&
|
||||
s.containerId && { [s.serviceName]: s.containerId }),
|
||||
}),
|
||||
{} as Dictionary<string>,
|
||||
);
|
||||
});
|
||||
|
||||
return containerIds;
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ import * as _ from 'lodash';
|
||||
|
||||
import * as config from '../config';
|
||||
|
||||
import * as applicationManager from './application-manager';
|
||||
import type { Image } from './images';
|
||||
import * as images from './images';
|
||||
import Network from './network';
|
||||
@ -57,7 +56,6 @@ interface CompositionStepArgs {
|
||||
skipLock?: boolean;
|
||||
};
|
||||
} & BaseCompositionStepArgs;
|
||||
stopAll: BaseCompositionStepArgs;
|
||||
start: {
|
||||
target: Service;
|
||||
} & BaseCompositionStepArgs;
|
||||
@ -209,12 +207,6 @@ export function getExecutors(app: {
|
||||
},
|
||||
);
|
||||
},
|
||||
stopAll: async (step) => {
|
||||
await applicationManager.stopAll({
|
||||
force: step.force,
|
||||
skipLock: step.skipLock,
|
||||
});
|
||||
},
|
||||
start: async (step) => {
|
||||
const container = await serviceManager.start(step.target);
|
||||
app.callbacks.containerStarted(container.id);
|
||||
|
@ -371,12 +371,6 @@ export async function getAvailable(): Promise<Image[]> {
|
||||
);
|
||||
}
|
||||
|
||||
export function getDownloadingImageIds(): number[] {
|
||||
return Object.values(runningTasks)
|
||||
.filter((t) => t.context.status === 'Downloading')
|
||||
.map((t) => t.context.imageId);
|
||||
}
|
||||
|
||||
export function getDownloadingImageNames(): string[] {
|
||||
return Object.values(runningTasks)
|
||||
.filter((t) => t.context.status === 'Downloading')
|
||||
|
@ -84,9 +84,11 @@ export const getAll = async (
|
||||
return services.filter((s) => s != null) as Service[];
|
||||
};
|
||||
|
||||
export async function get(service: Service) {
|
||||
async function get(service: Service) {
|
||||
// Get the container ids for special network handling
|
||||
const containerIds = await getContainerIdMap(service.appId!);
|
||||
const containerIds = await getContainerIdMap(
|
||||
service.appUuid || service.appId,
|
||||
);
|
||||
const services = (
|
||||
await getAll(`service-name=${service.serviceName}`)
|
||||
).filter((currentService) =>
|
||||
@ -217,17 +219,8 @@ export async function remove(service: Service) {
|
||||
}
|
||||
}
|
||||
}
|
||||
export function getAllByAppId(appId: number) {
|
||||
return getAll(`app-id=${appId}`);
|
||||
}
|
||||
|
||||
export async function stopAllByAppId(appId: number) {
|
||||
for (const app of await getAllByAppId(appId)) {
|
||||
await kill(app, { removeContainer: false });
|
||||
}
|
||||
}
|
||||
|
||||
export async function create(service: Service) {
|
||||
async function create(service: Service) {
|
||||
const mockContainerId = config.newUniqueKey();
|
||||
try {
|
||||
const existing = await get(service);
|
||||
@ -255,12 +248,21 @@ export async function create(service: Service) {
|
||||
);
|
||||
}
|
||||
|
||||
// Get all created services so far
|
||||
if (service.appId == null) {
|
||||
// New services need to have an appUuid
|
||||
if (service.appUuid == null) {
|
||||
throw new InternalInconsistencyError(
|
||||
'Attempt to start a service without an existing application ID',
|
||||
'Attempt to start a service without an existing app uuid',
|
||||
);
|
||||
}
|
||||
|
||||
// We cannot get rid of appIds yet
|
||||
if (service.appId == null) {
|
||||
throw new InternalInconsistencyError(
|
||||
'Attempt to start a service without an existing app id',
|
||||
);
|
||||
}
|
||||
|
||||
// Get all created services so far, there
|
||||
const serviceContainerIds = await getContainerIdMap(service.appId);
|
||||
const conf = service.toDockerContainer({
|
||||
deviceName,
|
||||
@ -480,10 +482,16 @@ export async function attachToRunning() {
|
||||
}
|
||||
}
|
||||
|
||||
export async function getContainerIdMap(
|
||||
appId: number,
|
||||
async function getContainerIdMap(
|
||||
appIdOrUuid: number | string,
|
||||
): Promise<Dictionary<string>> {
|
||||
return _(await getAllByAppId(appId))
|
||||
const [byAppId, byAppUuid] = await Promise.all([
|
||||
getAll(`app-id=${appIdOrUuid}`),
|
||||
getAll(`app-uuid=${appIdOrUuid}`),
|
||||
]);
|
||||
|
||||
const containerList = _.unionBy(byAppId, byAppUuid, 'containerId');
|
||||
return _(containerList)
|
||||
.keyBy('serviceName')
|
||||
.mapValues('containerId')
|
||||
.value() as Dictionary<string>;
|
||||
|
@ -49,12 +49,6 @@ export class InvalidNetGatewayError extends TypedError {}
|
||||
|
||||
export class DeltaStillProcessingError extends TypedError {}
|
||||
|
||||
export class InvalidAppIdError extends TypedError {
|
||||
public constructor(public appId: any) {
|
||||
super(`Invalid appId: ${appId}`);
|
||||
}
|
||||
}
|
||||
|
||||
export class UpdatesLockedError extends TypedError {}
|
||||
|
||||
export function isHttpConflictError(err: { statusCode: number }): boolean {
|
||||
|
@ -44,9 +44,9 @@ describe('SupervisorAPI [V1 Endpoints]', () => {
|
||||
`http://127.0.0.1:${mockedAPI.mockedOptions.listenPort}`,
|
||||
);
|
||||
const services = [
|
||||
{ appId: 2, serviceId: 640681, serviceName: 'one' },
|
||||
{ appId: 2, serviceId: 640682, serviceName: 'two' },
|
||||
{ appId: 2, serviceId: 640683, serviceName: 'three' },
|
||||
{ appId: 2, appUuid: 'deadbeef', serviceId: 640681, serviceName: 'one' },
|
||||
{ appId: 2, appUuid: 'deadbeef', serviceId: 640682, serviceName: 'two' },
|
||||
{ appId: 2, appUuid: 'deadbeef', serviceId: 640683, serviceName: 'three' },
|
||||
];
|
||||
const containers = services.map((service) => mockedAPI.mockService(service));
|
||||
const images = services.map((service) => mockedAPI.mockImage(service));
|
||||
@ -61,6 +61,7 @@ describe('SupervisorAPI [V1 Endpoints]', () => {
|
||||
|
||||
targetStateCacheMock.resolves({
|
||||
appId: 2,
|
||||
appUuid: 'deadbeef',
|
||||
commit: 'abcdef2',
|
||||
name: 'test-app2',
|
||||
source: 'https://api.balena-cloud.com',
|
||||
|
@ -1,820 +0,0 @@
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Sanity-check the conversion and remove this comment.
|
||||
|
||||
export let availableImages: any;
|
||||
export let currentState: any;
|
||||
export let targetState: any;
|
||||
|
||||
targetState = [];
|
||||
targetState[0] = {
|
||||
local: {
|
||||
name: 'aDeviceWithDifferentName',
|
||||
config: {
|
||||
RESIN_HOST_CONFIG_gpu_mem: '512',
|
||||
RESIN_HOST_LOG_TO_DISPLAY: '1',
|
||||
},
|
||||
apps: {
|
||||
1234: {
|
||||
appId: 1234,
|
||||
name: 'superapp',
|
||||
commit: 'afafafa',
|
||||
releaseId: 2,
|
||||
services: {
|
||||
'23': {
|
||||
appId: 1234,
|
||||
serviceName: 'aservice',
|
||||
commit: 'afafafa',
|
||||
imageId: 12345,
|
||||
image: 'registry2.resin.io/superapp/edfabc:latest',
|
||||
environment: {
|
||||
FOO: 'bar',
|
||||
},
|
||||
privileged: false,
|
||||
volumes: [],
|
||||
labels: {},
|
||||
running: true,
|
||||
},
|
||||
'24': {
|
||||
appId: 1234,
|
||||
serviceName: 'anotherService',
|
||||
commit: 'afafafa',
|
||||
imageId: 12346,
|
||||
image: 'registry2.resin.io/superapp/afaff:latest',
|
||||
environment: {
|
||||
FOO: 'bro',
|
||||
},
|
||||
volumes: [],
|
||||
privileged: false,
|
||||
labels: {},
|
||||
running: true,
|
||||
},
|
||||
},
|
||||
volumes: {},
|
||||
networks: {},
|
||||
},
|
||||
},
|
||||
},
|
||||
dependent: { apps: {}, devices: {} },
|
||||
};
|
||||
|
||||
targetState[1] = {
|
||||
local: {
|
||||
name: 'aDeviceWithDifferentName',
|
||||
config: {
|
||||
RESIN_HOST_CONFIG_gpu_mem: '512',
|
||||
RESIN_HOST_LOG_TO_DISPLAY: '1',
|
||||
},
|
||||
apps: {
|
||||
1234: {
|
||||
appId: 1234,
|
||||
name: 'superapp',
|
||||
commit: 'afafafa',
|
||||
releaseId: 2,
|
||||
services: {
|
||||
'23': {
|
||||
appId: 1234,
|
||||
serviceName: 'aservice',
|
||||
commit: 'afafafa',
|
||||
imageId: 12345,
|
||||
image: 'registry2.resin.io/superapp/edfabc:latest',
|
||||
environment: {
|
||||
FOO: 'bar',
|
||||
ADDITIONAL_ENV_VAR: 'foo',
|
||||
},
|
||||
privileged: false,
|
||||
volumes: [],
|
||||
labels: {},
|
||||
running: true,
|
||||
},
|
||||
},
|
||||
volumes: {},
|
||||
networks: {},
|
||||
},
|
||||
},
|
||||
},
|
||||
dependent: { apps: {}, devices: {} },
|
||||
};
|
||||
|
||||
targetState[2] = {
|
||||
local: {
|
||||
name: 'aDeviceWithDifferentName',
|
||||
config: {
|
||||
RESIN_HOST_CONFIG_gpu_mem: '512',
|
||||
RESIN_HOST_LOG_TO_DISPLAY: '1',
|
||||
},
|
||||
apps: {
|
||||
1234: {
|
||||
appId: 1234,
|
||||
name: 'superapp',
|
||||
commit: 'afafafa',
|
||||
releaseId: 2,
|
||||
services: {
|
||||
'23': {
|
||||
appId: 1234,
|
||||
serviceName: 'aservice',
|
||||
commit: 'afafafa',
|
||||
imageId: 12345,
|
||||
image: 'registry2.resin.io/superapp/edfabc:latest',
|
||||
environment: {
|
||||
FOO: 'bar',
|
||||
ADDITIONAL_ENV_VAR: 'foo',
|
||||
},
|
||||
privileged: false,
|
||||
volumes: [],
|
||||
labels: {},
|
||||
running: true,
|
||||
},
|
||||
'24': {
|
||||
appId: 1234,
|
||||
serviceName: 'anotherService',
|
||||
commit: 'afafafa',
|
||||
imageId: 12347,
|
||||
image: 'registry2.resin.io/superapp/foooo:latest',
|
||||
depends_on: ['aservice'],
|
||||
environment: {
|
||||
FOO: 'bro',
|
||||
ADDITIONAL_ENV_VAR: 'foo',
|
||||
},
|
||||
volumes: [],
|
||||
privileged: false,
|
||||
labels: {},
|
||||
running: true,
|
||||
},
|
||||
},
|
||||
volumes: {},
|
||||
networks: {},
|
||||
},
|
||||
},
|
||||
},
|
||||
dependent: { apps: {}, devices: {} },
|
||||
};
|
||||
|
||||
targetState[3] = {
|
||||
local: {
|
||||
name: 'aDeviceWithDifferentName',
|
||||
config: {
|
||||
RESIN_HOST_CONFIG_gpu_mem: '512',
|
||||
RESIN_HOST_LOG_TO_DISPLAY: '1',
|
||||
},
|
||||
apps: {
|
||||
1234: {
|
||||
appId: 1234,
|
||||
name: 'superapp',
|
||||
commit: 'afafafa',
|
||||
releaseId: 2,
|
||||
services: {
|
||||
'23': {
|
||||
appId: 1234,
|
||||
serviceName: 'aservice',
|
||||
commit: 'afafafa',
|
||||
imageId: 12345,
|
||||
image: 'registry2.resin.io/superapp/edfabc:latest',
|
||||
environment: {
|
||||
FOO: 'bar',
|
||||
ADDITIONAL_ENV_VAR: 'foo',
|
||||
},
|
||||
privileged: false,
|
||||
volumes: [],
|
||||
labels: {},
|
||||
running: true,
|
||||
},
|
||||
'24': {
|
||||
appId: 1234,
|
||||
serviceName: 'anotherService',
|
||||
commit: 'afafafa',
|
||||
imageId: 12347,
|
||||
image: 'registry2.resin.io/superapp/foooo:latest',
|
||||
environment: {
|
||||
FOO: 'bro',
|
||||
ADDITIONAL_ENV_VAR: 'foo',
|
||||
},
|
||||
volumes: [],
|
||||
privileged: false,
|
||||
labels: {
|
||||
'io.resin.update.strategy': 'kill-then-download',
|
||||
},
|
||||
running: true,
|
||||
},
|
||||
},
|
||||
volumes: {},
|
||||
networks: {},
|
||||
},
|
||||
},
|
||||
},
|
||||
dependent: { apps: {}, devices: {} },
|
||||
};
|
||||
|
||||
targetState[4] = {
|
||||
local: {
|
||||
name: 'aDeviceWithDifferentName',
|
||||
config: {
|
||||
RESIN_HOST_CONFIG_gpu_mem: '512',
|
||||
RESIN_HOST_LOG_TO_DISPLAY: '1',
|
||||
},
|
||||
apps: {
|
||||
1234: {
|
||||
appId: 1234,
|
||||
name: 'superapp',
|
||||
commit: 'afafafa',
|
||||
releaseId: 2,
|
||||
services: {
|
||||
'23': {
|
||||
appId: 1234,
|
||||
serviceName: 'aservice',
|
||||
commit: 'afafafa',
|
||||
imageId: 12345,
|
||||
image: 'registry2.resin.io/superapp/edfabc:latest',
|
||||
environment: {
|
||||
FOO: 'THIS VALUE CHANGED',
|
||||
ADDITIONAL_ENV_VAR: 'foo',
|
||||
},
|
||||
privileged: false,
|
||||
volumes: [],
|
||||
labels: {},
|
||||
running: true,
|
||||
},
|
||||
'24': {
|
||||
appId: 1234,
|
||||
serviceName: 'anotherService',
|
||||
commit: 'afafafa',
|
||||
imageId: 12347,
|
||||
image: 'registry2.resin.io/superapp/foooo:latest',
|
||||
depends_on: ['aservice'],
|
||||
environment: {
|
||||
FOO: 'bro',
|
||||
ADDITIONAL_ENV_VAR: 'foo',
|
||||
},
|
||||
volumes: [],
|
||||
privileged: false,
|
||||
labels: {},
|
||||
running: true,
|
||||
},
|
||||
},
|
||||
volumes: {},
|
||||
networks: {},
|
||||
},
|
||||
},
|
||||
},
|
||||
dependent: { apps: {}, devices: {} },
|
||||
};
|
||||
|
||||
targetState[5] = {
|
||||
local: {
|
||||
name: 'aDeviceWithDifferentName',
|
||||
config: {
|
||||
RESIN_HOST_CONFIG_gpu_mem: '512',
|
||||
RESIN_HOST_LOG_TO_DISPLAY: '1',
|
||||
},
|
||||
apps: {
|
||||
1234: {
|
||||
appId: 1234,
|
||||
name: 'superapp',
|
||||
commit: 'afafafa',
|
||||
releaseId: 2,
|
||||
services: {
|
||||
'23': {
|
||||
appId: 1234,
|
||||
serviceName: 'aservice',
|
||||
commit: 'afafafa',
|
||||
imageId: 12345,
|
||||
image: 'registry2.resin.io/superapp/edfabc:latest',
|
||||
environment: {
|
||||
FOO: 'THIS VALUE CHANGED',
|
||||
ADDITIONAL_ENV_VAR: 'foo',
|
||||
},
|
||||
privileged: false,
|
||||
volumes: [],
|
||||
labels: {},
|
||||
running: true,
|
||||
},
|
||||
'24': {
|
||||
appId: 1234,
|
||||
serviceName: 'anotherService',
|
||||
commit: 'afafafa',
|
||||
imageId: 12347,
|
||||
image: 'registry2.resin.io/superapp/foooo:latest',
|
||||
environment: {
|
||||
FOO: 'bro',
|
||||
ADDITIONAL_ENV_VAR: 'foo',
|
||||
},
|
||||
volumes: [],
|
||||
privileged: false,
|
||||
labels: {},
|
||||
running: true,
|
||||
},
|
||||
},
|
||||
volumes: {},
|
||||
networks: {},
|
||||
},
|
||||
},
|
||||
},
|
||||
dependent: { apps: {}, devices: {} },
|
||||
};
|
||||
|
||||
targetState[6] = {
|
||||
local: {
|
||||
name: 'volumeTest',
|
||||
config: {},
|
||||
apps: {
|
||||
12345: {
|
||||
appId: 12345,
|
||||
name: 'volumeApp',
|
||||
commit: 'asd',
|
||||
releaseId: 3,
|
||||
services: {},
|
||||
volumes: {},
|
||||
networks: {},
|
||||
},
|
||||
},
|
||||
},
|
||||
dependent: { apps: {}, devices: {} },
|
||||
};
|
||||
|
||||
currentState = [];
|
||||
currentState[0] = {
|
||||
local: {
|
||||
name: 'aDeviceWithDifferentName',
|
||||
config: {
|
||||
RESIN_HOST_CONFIG_gpu_mem: '512',
|
||||
RESIN_HOST_LOG_TO_DISPLAY: '1',
|
||||
},
|
||||
apps: {
|
||||
1234: {
|
||||
appId: 1234,
|
||||
name: 'superapp',
|
||||
commit: 'afafafa',
|
||||
releaseId: 2,
|
||||
services: {
|
||||
23: {
|
||||
appId: 1234,
|
||||
serviceId: 23,
|
||||
releaseId: 2,
|
||||
commit: 'afafafa',
|
||||
serviceName: 'aservice',
|
||||
imageId: 12345,
|
||||
image: 'id1',
|
||||
environment: {
|
||||
FOO: 'bar',
|
||||
ADDITIONAL_ENV_VAR: 'foo',
|
||||
},
|
||||
privileged: false,
|
||||
restart: 'always',
|
||||
volumes: [
|
||||
'/tmp/balena-supervisor/services/1234/aservice:/tmp/resin',
|
||||
'/tmp/balena-supervisor/services/1234/aservice:/tmp/balena',
|
||||
],
|
||||
labels: {
|
||||
'io.resin.app-id': '1234',
|
||||
'io.resin.service-id': '23',
|
||||
'io.resin.supervised': 'true',
|
||||
'io.resin.service-name': 'aservice',
|
||||
},
|
||||
running: true,
|
||||
createdAt: new Date(),
|
||||
containerId: '1',
|
||||
networkMode: 'default',
|
||||
networks: { default: { aliases: ['aservice'] } },
|
||||
command: ['someCommand'],
|
||||
entrypoint: ['theEntrypoint'],
|
||||
},
|
||||
24: {
|
||||
appId: 1234,
|
||||
serviceId: 24,
|
||||
releaseId: 2,
|
||||
commit: 'afafafa',
|
||||
serviceName: 'anotherService',
|
||||
imageId: 12346,
|
||||
image: 'id0',
|
||||
environment: {
|
||||
FOO: 'bro',
|
||||
ADDITIONAL_ENV_VAR: 'foo',
|
||||
},
|
||||
volumes: [
|
||||
'/tmp/balena-supervisor/services/1234/anotherService:/tmp/resin',
|
||||
'/tmp/balena-supervisor/services/1234/anotherService:/tmp/balena',
|
||||
],
|
||||
privileged: false,
|
||||
restart: 'always',
|
||||
labels: {
|
||||
'io.resin.app-id': '1234',
|
||||
'io.resin.service-id': '24',
|
||||
'io.resin.supervised': 'true',
|
||||
'io.resin.service-name': 'anotherService',
|
||||
},
|
||||
running: false,
|
||||
createdAt: new Date(),
|
||||
containerId: '2',
|
||||
networkMode: 'default',
|
||||
networks: { default: { aliases: ['anotherService'] } },
|
||||
command: ['someCommand'],
|
||||
entrypoint: ['theEntrypoint'],
|
||||
},
|
||||
},
|
||||
volumes: {},
|
||||
networks: { default: {} },
|
||||
},
|
||||
},
|
||||
},
|
||||
dependent: { apps: {}, devices: {} },
|
||||
};
|
||||
|
||||
currentState[1] = {
|
||||
local: {
|
||||
name: 'aDeviceWithDifferentName',
|
||||
config: {
|
||||
RESIN_HOST_CONFIG_gpu_mem: '512',
|
||||
RESIN_HOST_LOG_TO_DISPLAY: '1',
|
||||
},
|
||||
apps: {
|
||||
1234: {
|
||||
appId: 1234,
|
||||
name: 'superapp',
|
||||
commit: 'afafafa',
|
||||
releaseId: 2,
|
||||
services: {},
|
||||
volumes: {},
|
||||
networks: { default: {} },
|
||||
},
|
||||
},
|
||||
},
|
||||
dependent: { apps: {}, devices: {} },
|
||||
};
|
||||
|
||||
currentState[2] = {
|
||||
local: {
|
||||
name: 'aDeviceWithDifferentName',
|
||||
config: {
|
||||
RESIN_HOST_CONFIG_gpu_mem: '512',
|
||||
RESIN_HOST_LOG_TO_DISPLAY: '1',
|
||||
},
|
||||
apps: {
|
||||
1234: {
|
||||
appId: 1234,
|
||||
name: 'superapp',
|
||||
commit: 'afafafa',
|
||||
releaseId: 2,
|
||||
services: {
|
||||
23: {
|
||||
appId: 1234,
|
||||
serviceId: 23,
|
||||
releaseId: 2,
|
||||
commit: 'afafafa',
|
||||
expose: [],
|
||||
ports: [],
|
||||
serviceName: 'aservice',
|
||||
imageId: 12345,
|
||||
image: 'id1',
|
||||
environment: {
|
||||
FOO: 'THIS VALUE CHANGED',
|
||||
ADDITIONAL_ENV_VAR: 'foo',
|
||||
},
|
||||
privileged: false,
|
||||
restart: 'always',
|
||||
volumes: [
|
||||
'/tmp/balena-supervisor/services/1234/aservice:/tmp/resin',
|
||||
'/tmp/balena-supervisor/services/1234/aservice:/tmp/balena',
|
||||
],
|
||||
labels: {
|
||||
'io.resin.app-id': '1234',
|
||||
'io.resin.service-id': '23',
|
||||
'io.resin.supervised': 'true',
|
||||
'io.resin.service-name': 'aservice',
|
||||
},
|
||||
running: true,
|
||||
createdAt: new Date(),
|
||||
containerId: '1',
|
||||
networkMode: 'default',
|
||||
networks: { default: { aliases: ['aservice'] } },
|
||||
command: ['someCommand'],
|
||||
entrypoint: ['theEntrypoint'],
|
||||
},
|
||||
},
|
||||
volumes: {},
|
||||
networks: { default: {} },
|
||||
},
|
||||
},
|
||||
},
|
||||
dependent: { apps: {}, devices: {} },
|
||||
};
|
||||
|
||||
currentState[3] = {
|
||||
local: {
|
||||
name: 'aDeviceWithDifferentName',
|
||||
config: {
|
||||
RESIN_HOST_CONFIG_gpu_mem: '512',
|
||||
RESIN_HOST_LOG_TO_DISPLAY: '1',
|
||||
},
|
||||
apps: {
|
||||
1234: {
|
||||
appId: 1234,
|
||||
name: 'superapp',
|
||||
commit: 'afafafa',
|
||||
releaseId: 2,
|
||||
services: {
|
||||
23: {
|
||||
appId: 1234,
|
||||
serviceId: 23,
|
||||
serviceName: 'aservice',
|
||||
imageId: 12345,
|
||||
releaseId: 2,
|
||||
commit: 'afafafa',
|
||||
expose: [],
|
||||
ports: [],
|
||||
image: 'id1',
|
||||
environment: {
|
||||
FOO: 'THIS VALUE CHANGED',
|
||||
ADDITIONAL_ENV_VAR: 'foo',
|
||||
},
|
||||
privileged: false,
|
||||
restart: 'always',
|
||||
volumes: [
|
||||
'/tmp/balena-supervisor/services/1234/aservice:/tmp/resin',
|
||||
'/tmp/balena-supervisor/services/1234/aservice:/tmp/balena',
|
||||
],
|
||||
labels: {
|
||||
'io.resin.app-id': '1234',
|
||||
'io.resin.service-id': '23',
|
||||
'io.resin.supervised': 'true',
|
||||
'io.resin.service-name': 'aservice',
|
||||
},
|
||||
running: true,
|
||||
createdAt: new Date(0),
|
||||
containerId: '1',
|
||||
networkMode: 'default',
|
||||
networks: { default: { aliases: ['aservice'] } },
|
||||
command: ['someCommand'],
|
||||
entrypoint: ['theEntrypoint'],
|
||||
},
|
||||
24: {
|
||||
appId: 1234,
|
||||
serviceId: 23,
|
||||
serviceName: 'aservice',
|
||||
imageId: 12345,
|
||||
releaseId: 2,
|
||||
commit: 'afafafa',
|
||||
expose: [],
|
||||
ports: [],
|
||||
image: 'id1',
|
||||
environment: {
|
||||
FOO: 'THIS VALUE CHANGED',
|
||||
ADDITIONAL_ENV_VAR: 'foo',
|
||||
},
|
||||
privileged: false,
|
||||
restart: 'always',
|
||||
volumes: [
|
||||
'/tmp/balena-supervisor/services/1234/aservice:/tmp/resin',
|
||||
'/tmp/balena-supervisor/services/1234/aservice:/tmp/balena',
|
||||
],
|
||||
labels: {
|
||||
'io.resin.app-id': '1234',
|
||||
'io.resin.service-id': '23',
|
||||
'io.resin.supervised': 'true',
|
||||
'io.resin.service-name': 'aservice',
|
||||
},
|
||||
running: true,
|
||||
createdAt: new Date(1),
|
||||
containerId: '2',
|
||||
networkMode: 'default',
|
||||
networks: { default: { aliases: ['aservice'] } },
|
||||
command: ['someCommand'],
|
||||
entrypoint: ['theEntrypoint'],
|
||||
},
|
||||
},
|
||||
volumes: {},
|
||||
networks: { default: {} },
|
||||
},
|
||||
},
|
||||
},
|
||||
dependent: { apps: {}, devices: {} },
|
||||
};
|
||||
|
||||
currentState[4] = {
|
||||
local: {
|
||||
name: 'aDeviceWithDifferentName',
|
||||
config: {
|
||||
RESIN_HOST_CONFIG_gpu_mem: '512',
|
||||
RESIN_HOST_LOG_TO_DISPLAY: '1',
|
||||
},
|
||||
apps: {
|
||||
1234: {
|
||||
appId: 1234,
|
||||
name: 'superapp',
|
||||
commit: 'afafafa',
|
||||
releaseId: 2,
|
||||
services: {
|
||||
24: {
|
||||
appId: 1234,
|
||||
serviceId: 24,
|
||||
releaseId: 2,
|
||||
commit: 'afafafa',
|
||||
serviceName: 'anotherService',
|
||||
imageId: 12346,
|
||||
image: 'id0',
|
||||
environment: {
|
||||
FOO: 'bro',
|
||||
ADDITIONAL_ENV_VAR: 'foo',
|
||||
},
|
||||
volumes: [
|
||||
'/tmp/balena-supervisor/services/1234/anotherService:/tmp/resin',
|
||||
'/tmp/balena-supervisor/services/1234/anotherService:/tmp/balena',
|
||||
],
|
||||
privileged: false,
|
||||
restart: 'always',
|
||||
labels: {
|
||||
'io.resin.app-id': '1234',
|
||||
'io.resin.service-id': '24',
|
||||
'io.resin.supervised': 'true',
|
||||
'io.resin.service-name': 'anotherService',
|
||||
},
|
||||
running: false,
|
||||
createdAt: new Date(),
|
||||
containerId: '2',
|
||||
networkMode: 'default',
|
||||
networks: { default: { aliases: ['aservice'] } },
|
||||
command: ['someCommand'],
|
||||
entrypoint: ['theEntrypoint'],
|
||||
},
|
||||
},
|
||||
volumes: {},
|
||||
networks: { default: {} },
|
||||
},
|
||||
},
|
||||
},
|
||||
dependent: { apps: {}, devices: {} },
|
||||
};
|
||||
|
||||
currentState[5] = {
|
||||
local: {
|
||||
name: 'volumeTest',
|
||||
config: {},
|
||||
apps: {
|
||||
12345: {
|
||||
appId: 12345,
|
||||
name: 'volumeApp',
|
||||
commit: 'asd',
|
||||
releaseId: 3,
|
||||
services: {},
|
||||
volumes: {},
|
||||
networks: { default: {} },
|
||||
},
|
||||
12: {
|
||||
appId: 12,
|
||||
name: 'previous-app',
|
||||
commit: '123',
|
||||
releaseId: 10,
|
||||
services: {},
|
||||
networks: {},
|
||||
volumes: {
|
||||
my_volume: {},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
dependent: { apps: {}, devices: {} },
|
||||
};
|
||||
|
||||
currentState[6] = {
|
||||
local: {
|
||||
name: 'aDeviceWithDifferentName',
|
||||
config: {
|
||||
RESIN_HOST_CONFIG_gpu_mem: '512',
|
||||
RESIN_HOST_LOG_TO_DISPLAY: '1',
|
||||
},
|
||||
apps: {
|
||||
1234: {
|
||||
appId: 1234,
|
||||
name: 'superapp',
|
||||
commit: 'afafafa',
|
||||
releaseId: 2,
|
||||
services: {
|
||||
23: {
|
||||
appId: 1234,
|
||||
serviceId: 23,
|
||||
releaseId: 2,
|
||||
commit: 'afafafa',
|
||||
serviceName: 'aservice',
|
||||
imageId: 12345,
|
||||
image: 'id1',
|
||||
environment: {
|
||||
FOO: 'bar',
|
||||
ADDITIONAL_ENV_VAR: 'foo',
|
||||
},
|
||||
privileged: false,
|
||||
restart: 'always',
|
||||
volumes: [
|
||||
'/tmp/balena-supervisor/services/1234/aservice:/tmp/resin',
|
||||
'/tmp/balena-supervisor/services/1234/aservice:/tmp/balena',
|
||||
],
|
||||
labels: {
|
||||
'io.resin.app-id': '1234',
|
||||
'io.resin.service-id': '23',
|
||||
'io.resin.supervised': 'true',
|
||||
'io.resin.service-name': 'aservice',
|
||||
},
|
||||
running: true,
|
||||
createdAt: new Date(),
|
||||
containerId: '1',
|
||||
networkMode: 'default',
|
||||
networks: { default: { aliases: ['aservice'] } },
|
||||
command: ['someCommand'],
|
||||
entrypoint: ['theEntrypoint'],
|
||||
},
|
||||
24: {
|
||||
appId: 1234,
|
||||
serviceId: 24,
|
||||
releaseId: 2,
|
||||
commit: 'afafafa',
|
||||
serviceName: 'anotherService',
|
||||
imageId: 12346,
|
||||
image: 'id0',
|
||||
environment: {
|
||||
FOO: 'bro',
|
||||
ADDITIONAL_ENV_VAR: 'foo',
|
||||
},
|
||||
volumes: [
|
||||
'/tmp/balena-supervisor/services/1234/anotherService:/tmp/resin',
|
||||
'/tmp/balena-supervisor/services/1234/anotherService:/tmp/balena',
|
||||
],
|
||||
privileged: false,
|
||||
restart: 'always',
|
||||
labels: {
|
||||
'io.resin.app-id': '1234',
|
||||
'io.resin.service-id': '24',
|
||||
'io.resin.supervised': 'true',
|
||||
'io.resin.service-name': 'anotherService',
|
||||
},
|
||||
running: true,
|
||||
createdAt: new Date(),
|
||||
containerId: '2',
|
||||
networkMode: 'default',
|
||||
networks: { default: { aliases: ['anotherService'] } },
|
||||
command: ['someCommand'],
|
||||
entrypoint: ['theEntrypoint'],
|
||||
},
|
||||
},
|
||||
volumes: {},
|
||||
networks: { default: {} },
|
||||
},
|
||||
},
|
||||
},
|
||||
dependent: { apps: {}, devices: {} },
|
||||
};
|
||||
|
||||
availableImages = [];
|
||||
availableImages[0] = [
|
||||
{
|
||||
name: 'registry2.resin.io/superapp/afaff:latest',
|
||||
appId: 1234,
|
||||
serviceId: 24,
|
||||
serviceName: 'anotherService',
|
||||
imageId: 12346,
|
||||
releaseId: 2,
|
||||
dependent: 0,
|
||||
dockerImageId: 'id0',
|
||||
},
|
||||
{
|
||||
name: 'registry2.resin.io/superapp/edfabc:latest',
|
||||
appId: 1234,
|
||||
serviceId: 23,
|
||||
serviceName: 'aservice',
|
||||
imageId: 12345,
|
||||
releaseId: 2,
|
||||
dependent: 0,
|
||||
dockerImageId: 'id1',
|
||||
},
|
||||
];
|
||||
availableImages[1] = [
|
||||
{
|
||||
name: 'registry2.resin.io/superapp/foooo:latest',
|
||||
appId: 1234,
|
||||
serviceId: 24,
|
||||
serviceName: 'anotherService',
|
||||
imageId: 12347,
|
||||
releaseId: 2,
|
||||
dependent: 0,
|
||||
dockerImageId: 'id2',
|
||||
},
|
||||
{
|
||||
name: 'registry2.resin.io/superapp/edfabc:latest',
|
||||
appId: 1234,
|
||||
serviceId: 23,
|
||||
serviceName: 'aservice',
|
||||
imageId: 12345,
|
||||
releaseId: 2,
|
||||
dependent: 0,
|
||||
dockerImageId: 'id1',
|
||||
},
|
||||
];
|
||||
|
||||
availableImages[2] = [
|
||||
{
|
||||
name: 'registry2.resin.io/superapp/foooo:latest',
|
||||
appId: 1234,
|
||||
serviceId: 24,
|
||||
serviceName: 'anotherService',
|
||||
imageId: 12347,
|
||||
releaseId: 2,
|
||||
dependent: 0,
|
||||
dockerImageId: 'id2',
|
||||
},
|
||||
];
|
@ -10,7 +10,6 @@ import Volume from '../../src/compose/volume';
|
||||
const originalVolGetAll = volumeManager.getAll;
|
||||
const originalSvcGetAll = serviceManager.getAll;
|
||||
const originalNetGetAll = networkManager.getAll;
|
||||
const originalGetDl = imageManager.getDownloadingImageIds;
|
||||
const originalNeedsClean = imageManager.isCleanupNeeded;
|
||||
const originalImageAvailable = imageManager.getAvailable;
|
||||
const originalNetworkReady = networkManager.supervisorNetworkReady;
|
||||
@ -45,14 +44,10 @@ function unmockManagers() {
|
||||
}
|
||||
|
||||
export function mockImages(
|
||||
downloading: number[],
|
||||
_downloading: number[],
|
||||
cleanup: boolean,
|
||||
available: imageManager.Image[],
|
||||
) {
|
||||
// @ts-expect-error Assigning to a RO property
|
||||
imageManager.getDownloadingImageIds = () => {
|
||||
return downloading;
|
||||
};
|
||||
// @ts-expect-error Assigning to a RO property
|
||||
imageManager.isCleanupNeeded = async () => cleanup;
|
||||
// @ts-expect-error Assigning to a RO property
|
||||
@ -60,8 +55,6 @@ export function mockImages(
|
||||
}
|
||||
|
||||
function unmockImages() {
|
||||
// @ts-expect-error Assigning to a RO property
|
||||
imageManager.getDownloadingImageIds = originalGetDl;
|
||||
// @ts-expect-error Assigning to a RO property
|
||||
imageManager.isCleanupNeeded = originalNeedsClean;
|
||||
// @ts-expect-error Assigning to a RO property
|
||||
|
@ -185,7 +185,6 @@ function buildRoutes(): Router {
|
||||
|
||||
// TO-DO: Create a cleaner way to restore previous values.
|
||||
const originalVolGetAll = volumeManager.getAllByAppId;
|
||||
const originalSvcGetAppId = serviceManager.getAllByAppId;
|
||||
const originalSvcGetStatus = serviceManager.getState;
|
||||
const originalReadyForUpdates = apiBinder.__get__('readyForUpdates');
|
||||
|
||||
@ -195,9 +194,6 @@ function setupStubs() {
|
||||
volumeManager.getAllByAppId = async () => STUBBED_VALUES.volumes;
|
||||
// @ts-expect-error Assigning to a RO property
|
||||
serviceManager.getState = async () => STUBBED_VALUES.services;
|
||||
// @ts-expect-error Assigning to a RO property
|
||||
serviceManager.getAllByAppId = async (appId) =>
|
||||
_.filter(STUBBED_VALUES.services, (service) => service.appId === appId);
|
||||
}
|
||||
|
||||
function restoreStubs() {
|
||||
@ -206,8 +202,6 @@ function restoreStubs() {
|
||||
volumeManager.getAllByAppId = originalVolGetAll;
|
||||
// @ts-expect-error Assigning to a RO property
|
||||
serviceManager.getState = originalSvcGetStatus;
|
||||
// @ts-expect-error Assigning to a RO property
|
||||
serviceManager.getAllByAppId = originalSvcGetAppId;
|
||||
}
|
||||
|
||||
export = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user