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 Dec 20, 2023
1 parent b12b8c6 commit 40ca521
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
23 changes: 19 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,11 @@ 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 needed for older supervisors to properly detect the hostApp
// since the `is_host: true` wasn't enough.
'io.balena.image.store': 'root',
}),
...getUserAppState(device, config),
};

Expand Down Expand Up @@ -353,6 +360,7 @@ const getAppState = (
application: AnyObject,
release: AnyObject | undefined,
config: Dictionary<string>,
defaultLabels?: Dictionary<string>,
): StateV3[string]['apps'] => {
return {
[application.uuid]: {
Expand All @@ -361,7 +369,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 +394,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 @@ -163,7 +163,9 @@ describe('Apps', function () {
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 40ca521

Please sign in to comment.