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 14, 2023
1 parent 952d2b7 commit bc7fd4c
Showing 1 changed file with 19 additions and 4 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);
};

0 comments on commit bc7fd4c

Please sign in to comment.