mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-03-12 07:23:58 +00:00
Merge pull request #2053 from balena-os/fix-unmanaged-target-state-behavior
Allow local target state to be applied in unmanaged mode
This commit is contained in:
commit
fbdd43d00a
@ -32,7 +32,7 @@ type ContractRequirements = {
|
|||||||
|
|
||||||
const contractRequirementVersions: ContractRequirements = {};
|
const contractRequirementVersions: ContractRequirements = {};
|
||||||
|
|
||||||
export function intialiseContractRequirements(opts: {
|
export function initializeContractRequirements(opts: {
|
||||||
supervisorVersion: string;
|
supervisorVersion: string;
|
||||||
deviceType: string;
|
deviceType: string;
|
||||||
l4tVersion?: string;
|
l4tVersion?: string;
|
||||||
|
@ -6,7 +6,6 @@ import * as config from '../config';
|
|||||||
import * as db from '../db';
|
import * as db from '../db';
|
||||||
import * as volumeManager from '../compose/volume-manager';
|
import * as volumeManager from '../compose/volume-manager';
|
||||||
import * as serviceManager from '../compose/service-manager';
|
import * as serviceManager from '../compose/service-manager';
|
||||||
import * as deviceState from '../device-state';
|
|
||||||
import * as applicationManager from '../compose/application-manager';
|
import * as applicationManager from '../compose/application-manager';
|
||||||
import {
|
import {
|
||||||
StatusError,
|
StatusError,
|
||||||
@ -62,7 +61,6 @@ async function createVolumeFromLegacyData(
|
|||||||
*/
|
*/
|
||||||
export async function normaliseLegacyDatabase() {
|
export async function normaliseLegacyDatabase() {
|
||||||
await apiBinder.initialized();
|
await apiBinder.initialized();
|
||||||
await deviceState.initialized();
|
|
||||||
|
|
||||||
if (apiBinder.balenaApi == null) {
|
if (apiBinder.balenaApi == null) {
|
||||||
throw new InternalInconsistencyError(
|
throw new InternalInconsistencyError(
|
||||||
@ -268,15 +266,11 @@ export async function fromV2TargetState(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert v2 to v3 target apps. If local is false
|
* Retrieves the appUuid for an app from balena API
|
||||||
* it will query the API to get the app uuid
|
* @param appId
|
||||||
*/
|
*/
|
||||||
export async function fromV2TargetApps(
|
const getUUIDFromAPI = async (appId: number) => {
|
||||||
apps: TargetAppsV2,
|
|
||||||
local = false,
|
|
||||||
): Promise<TargetApps> {
|
|
||||||
await apiBinder.initialized();
|
await apiBinder.initialized();
|
||||||
await deviceState.initialized();
|
|
||||||
|
|
||||||
if (apiBinder.balenaApi == null) {
|
if (apiBinder.balenaApi == null) {
|
||||||
throw new InternalInconsistencyError(
|
throw new InternalInconsistencyError(
|
||||||
@ -285,7 +279,7 @@ export async function fromV2TargetApps(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { balenaApi } = apiBinder;
|
const { balenaApi } = apiBinder;
|
||||||
const getUUIDFromAPI = async (appId: number) => {
|
|
||||||
const appDetails = await balenaApi.get({
|
const appDetails = await balenaApi.get({
|
||||||
resource: 'application',
|
resource: 'application',
|
||||||
id: appId,
|
id: appId,
|
||||||
@ -301,6 +295,14 @@ export async function fromV2TargetApps(
|
|||||||
return appDetails.uuid;
|
return appDetails.uuid;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert v2 to v3 target apps. If local is false
|
||||||
|
* it will query the API to get the app uuid
|
||||||
|
*/
|
||||||
|
export async function fromV2TargetApps(
|
||||||
|
apps: TargetAppsV2,
|
||||||
|
local = false,
|
||||||
|
): Promise<TargetApps> {
|
||||||
return (
|
return (
|
||||||
(
|
(
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
|
@ -8,7 +8,7 @@ import * as v1 from './device-api/v1';
|
|||||||
import * as v2 from './device-api/v2';
|
import * as v2 from './device-api/v2';
|
||||||
import logMonitor from './logging/monitor';
|
import logMonitor from './logging/monitor';
|
||||||
|
|
||||||
import { intialiseContractRequirements } from './lib/contracts';
|
import { initializeContractRequirements } from './lib/contracts';
|
||||||
import { normaliseLegacyDatabase } from './lib/legacy';
|
import { normaliseLegacyDatabase } from './lib/legacy';
|
||||||
import * as osRelease from './lib/os-release';
|
import * as osRelease from './lib/os-release';
|
||||||
import log from './lib/supervisor-console';
|
import log from './lib/supervisor-console';
|
||||||
@ -42,7 +42,7 @@ export class Supervisor {
|
|||||||
|
|
||||||
const conf = await config.getMany(startupConfigFields);
|
const conf = await config.getMany(startupConfigFields);
|
||||||
|
|
||||||
intialiseContractRequirements({
|
initializeContractRequirements({
|
||||||
supervisorVersion: version,
|
supervisorVersion: version,
|
||||||
deviceType: await config.get('deviceType'),
|
deviceType: await config.get('deviceType'),
|
||||||
l4tVersion: await osRelease.getL4tVersion(),
|
l4tVersion: await osRelease.getL4tVersion(),
|
||||||
|
@ -8,7 +8,7 @@ import * as deviceState from '~/src/device-state';
|
|||||||
import { appsJsonBackup, loadTargetFromFile } from '~/src/device-state/preload';
|
import { appsJsonBackup, loadTargetFromFile } from '~/src/device-state/preload';
|
||||||
import { TargetState } from '~/src/types';
|
import { TargetState } from '~/src/types';
|
||||||
import { promises as fs } from 'fs';
|
import { promises as fs } from 'fs';
|
||||||
import { intialiseContractRequirements } from '~/lib/contracts';
|
import { initializeContractRequirements } from '~/lib/contracts';
|
||||||
|
|
||||||
import { testfs } from 'mocha-pod';
|
import { testfs } from 'mocha-pod';
|
||||||
import { createDockerImage } from '~/test-lib/docker-helper';
|
import { createDockerImage } from '~/test-lib/docker-helper';
|
||||||
@ -21,7 +21,7 @@ describe('device-state', () => {
|
|||||||
|
|
||||||
// Set the device uuid
|
// Set the device uuid
|
||||||
await config.set({ uuid: 'local' });
|
await config.set({ uuid: 'local' });
|
||||||
intialiseContractRequirements({
|
initializeContractRequirements({
|
||||||
supervisorVersion: '11.0.0',
|
supervisorVersion: '11.0.0',
|
||||||
deviceType: 'intel-nuc',
|
deviceType: 'intel-nuc',
|
||||||
});
|
});
|
||||||
|
@ -5,7 +5,7 @@ import * as semver from 'semver';
|
|||||||
import * as constants from '~/lib/constants';
|
import * as constants from '~/lib/constants';
|
||||||
import {
|
import {
|
||||||
containerContractsFulfilled,
|
containerContractsFulfilled,
|
||||||
intialiseContractRequirements,
|
initializeContractRequirements,
|
||||||
validateContract,
|
validateContract,
|
||||||
} from '~/lib/contracts';
|
} from '~/lib/contracts';
|
||||||
import * as osRelease from '~/lib/os-release';
|
import * as osRelease from '~/lib/os-release';
|
||||||
@ -14,7 +14,7 @@ import * as fsUtils from '~/lib/fs-utils';
|
|||||||
|
|
||||||
describe('lib/contracts', () => {
|
describe('lib/contracts', () => {
|
||||||
before(() => {
|
before(() => {
|
||||||
intialiseContractRequirements({
|
initializeContractRequirements({
|
||||||
supervisorVersion,
|
supervisorVersion,
|
||||||
deviceType: 'intel-nuc',
|
deviceType: 'intel-nuc',
|
||||||
l4tVersion: '32.2',
|
l4tVersion: '32.2',
|
||||||
@ -436,7 +436,7 @@ describe('L4T version detection', () => {
|
|||||||
execStub.restore();
|
execStub.restore();
|
||||||
}
|
}
|
||||||
seedExec(version);
|
seedExec(version);
|
||||||
intialiseContractRequirements({
|
initializeContractRequirements({
|
||||||
supervisorVersion,
|
supervisorVersion,
|
||||||
deviceType: 'intel-nuc',
|
deviceType: 'intel-nuc',
|
||||||
l4tVersion: await osRelease.getL4tVersion(),
|
l4tVersion: await osRelease.getL4tVersion(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user