Skip to content

Commit

Permalink
state-get-v3: Add the 'io.balena.image.store': 'root' label to hostApps
Browse files Browse the repository at this point in the history
Change-type: patch
  • Loading branch information
thgreasi committed Jan 9, 2024
1 parent 5d1589f commit 2070d1d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
26 changes: 22 additions & 4 deletions src/features/device-state/routes/state-get-v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export function buildAppFromRelease(
application: AnyObject,
release: AnyObject,
config: Dictionary<string>,
defaultLabels?: Dictionary<string>,
): NonNullable<LocalStateApp['releases']> {
let composition: AnyObject = {};
const services: NonNullable<LocalStateApp['releases']>[string]['services'] =
Expand Down Expand Up @@ -135,7 +136,9 @@ export function buildAppFromRelease(
varListInsert(si.device_service_environment_variable, environment);
}

const labels: Dictionary<string> = {};
const labels: Dictionary<string> = {
...defaultLabels,
};
for (const { label_name, value } of [
...ipr.image_label,
...svc.service_label,
Expand Down Expand Up @@ -305,7 +308,14 @@ const getStateV3 = async (req: Request, uuid: string): Promise<StateV3> => {

const apps = {
...getSystemAppState(device, 'should_be_managed_by__release'),
...getSystemAppState(device, 'should_be_operated_by__release'),
...getSystemAppState(device, 'should_be_operated_by__release', {
// This label is necessary for older supervisors to properly detect the hostApp
// and ignore it, sinc `is_host: true` wasn't enough. W/o this the device would
// try to install the hostApp container like a normal user app and restart it
// constantly b/c the image doesn't have a CMD specified.
// See: https://github.com/balena-os/balena-supervisor/blob/v15.2.0/src/compose/app.ts#L839
'io.balena.image.store': 'root',
}),
...getUserAppState(device, config),
};

Expand Down Expand Up @@ -353,6 +363,7 @@ const getAppState = (
application: AnyObject,
release: AnyObject | undefined,
config: Dictionary<string>,
defaultLabels?: Dictionary<string>,
): StateV3[string]['apps'] => {
return {
[application.uuid]: {
Expand All @@ -361,7 +372,13 @@ const getAppState = (
is_host: application.is_host,
class: application.is_of__class,
...(release != null && {
releases: buildAppFromRelease(device, application, release, config),
releases: buildAppFromRelease(
device,
application,
release,
config,
defaultLabels,
),
}),
},
};
Expand All @@ -380,12 +397,13 @@ const getSystemAppState = (
targetReleaseField:
| 'should_be_managed_by__release'
| 'should_be_operated_by__release',
defaultLabels?: Dictionary<string>,
): StateV3[string]['apps'] | null => {
const release = device[targetReleaseField][0];
if (!release) {
return null;
}
const app = release.belongs_to__application[0];
// We use an empty config as we don't want any labels applied to the supervisor/hostApp due to user app config
return getAppState(device, app, release, {});
return getAppState(device, app, release, {}, defaultLabels);
};
4 changes: 3 additions & 1 deletion test/19_apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ versions.test((version, pineTest) => {
expect(stateGetHostApp.releases?.[intelNucHostAppRelease1.commit])
.to.have.property('services')
.that.has.property('main')
.that.is.an('object');
.that.is.an('object')
.and.has.property('labels')
.that.has.property('io.balena.image.store', 'root');

expect(stateGetHostApp, 'hostApp is undefined').to.not.be.undefined;
});
Expand Down

0 comments on commit 2070d1d

Please sign in to comment.