balena-cli icon indicating copy to clipboard operation
balena-cli copied to clipboard

Allow setting local mode without cloud access

Open lmbarros opened this issue 3 years ago • 2 comments

Expected Behavior

User would like a way to enable local while offline. This is the use case:

While completely offline at all times we should be able too:

  1. Burn a preloaded or pre-downloaded development Balena image to a sd card
  2. Boot the device and put it into local-mode
  3. Update the device using balena push (which isn't working at the moment)

Actual Behavior

It seems this is currently not possible.

lmbarros avatar Dec 21 '21 18:12 lmbarros

[lmbarros] This issue has attached support thread https://jel.ly.fish/f41e427a-0614-4e64-8abd-48612060f364

jellyfish-bot avatar Dec 21 '21 18:12 jellyfish-bot

The implementation of the balena device local-mode command: https://github.com/balena-io/balena-cli/blob/v12.55.8/lib/commands/device/local-mode.ts#L87-L99

... basically consists of calls to the balena SDK's models.device.enableLocalMode() and related functions, whose implementation is basically setting a device configuration variable through the balenaCloud API: https://github.com/balena-io/balena-sdk/blob/v16.3.0/lib/models/device.ts#L1730

    configVar.set(device.id, LOCAL_MODE_ENV_VAR, '1');

From there, the balenaCloud API would presumably notify the supervisor on the device through the VPN link, or failing that, the supervisor would regularly poll its "target state" from the balenaCloud API.

Therefore, I gather that the current platform architecture requires the device to be online. I think that for this to be possible offline, the first step would be for the supervisor to offer a local API call to allow itself to be switched into local mode, which raises the question of source of truth: if the cloud states that the device should not be in local mode but the CLI made a local supervisor API call for the supervisor to switch into local mode, what should the supervisor do? I gather that the supervisor currently has local endpoints to get and set its target state: GET /v2/local/target-state POST /v2/local/target-state ... but I understand that those endpoints can only be used while the device is already in local mode, and there is no way to switch the supervisor into and out of local mode other than going through the balenaCloud API. This understanding needs confirmation though.

Anyway, I don't think this issue is actionable in the balena CLI without first going through a platform product / architecture discussion. The JF Pattern attached to the support thread could be a starting point.

pdcastro avatar Dec 21 '21 21:12 pdcastro