Commit Graph

1434 Commits

Author SHA1 Message Date
pipex
97ec2a4151 Remove unused code from dbus module 2022-10-17 10:15:36 -03:00
pipex
4de816d1e9 Fix bug in preloading config vars 2022-10-17 10:15:36 -03:00
Ken Bannister
91f93952db Allow most printable ASCII chars for service label key
Change-type: patch
Signed-off-by: Ken Bannister <kb2ma@runbox.com>
2022-10-14 20:50:25 -04:00
Felipe Lalanne
b4514631b1 Start state engine and API binder in parallel
The state engine and preloading is performed before the device gets a
chance to register, while this is desirable for preloaded apps, it
introduces a delay on registration which is known to cause issues since
the VPN is also trying to connect at the same time.

This triggers a simultaneous start of the device engine, the API binder
and the supevisor API to avoid delays.

Change-type: patch
2022-09-30 19:38:10 +00:00
Pagan Gazzard
0237bd7cf4 Update type dependencies
Change-type: patch
2022-10-03 14:38:42 -05:00
Felipe Lalanne
f19f70d690 Migrate update-lock tests as integration tests
Update-lock tests now use the actual filesystem for testing, instead of
relying on stubs and spies.

This commit also fixes a small bug with update-lock that would cause a
`PromiseRejectionHandledWarning` when the lock callback would throw.
2022-09-28 10:37:41 -03:00
Felipe Lalanne
a69fbf6eac Migrate volume-manager tests to integration
Now the tests are ran against the actual docker engine instead of
against mockerode.

The new tests actually caught a bug in
`volumeManager.removeOrphanedVolumes`, where that function would try to
remove volumes for stopped containers, causing an exception.
This commit also fixes that bug.
2022-09-28 10:37:41 -03:00
Felipe Lalanne
460659429d Update dependencies to fix NPM build
Change-type: patch
2022-09-26 15:26:48 -03:00
Felipe Lalanne
b168cc35a0 Remove mixpanel configurations
Mixpanel configurations and packages are no longer used. This removes
deadcode from the supervisor.
2022-09-20 14:22:24 -03:00
Felipe Lalanne
e00687408c Disable event tracking
The supervisor used to rely on specific event reporting for identifying
issues at runtime. As the platform has grown, it has become much more
difficult to get any signal from the event noise. Recently the API side
for these events has been disabled, meaning these events only
contribute to bandwidth consumption.  This commit disables the
event reporting feature of the supervisor which will be most likely
replaced by something like Sentry in the near future.

Change-type: minor
2022-09-20 14:19:26 -03:00
Pagan Gazzard
5518eb17bd Update to nodejs 16
Change-type: minor
2022-09-19 17:51:48 +01:00
Pagan Gazzard
96418d55b5 Update @balena/lint to 6.2.0
Change-type: patch
2022-09-19 16:41:28 +01:00
Pagan Gazzard
a4c13aa2e9 Update to typescript 4.8.2
Change-type: patch
2022-09-19 16:36:17 +01:00
Pagan Gazzard
65e69f3a83 Update to nodejs 14
Change-type: patch
2022-09-15 22:59:40 +01:00
Felipe Lalanne
f7bc30a310 Remove unnecessary check for docker status code 2022-09-14 10:41:32 -03:00
Felipe Lalanne
c6f911c36b Only install service if running is set to false
The supervisor supports target state `running: false` for services.
This state indicates that the service should be stopped if already
running, or that the container should just be created and never started
if the container does not exist. This commit fixes the latter behavior.

Although nothing in our platform currently sends this target state, this
enables some potential use cases, e.g. only starting some services
in manufacturing and starting the rest of the services when the device
actually connects.

Change-type: patch
Closes: #2014
2022-09-14 10:15:51 -03:00
Felipe Lalanne
3e45e9561e Fix withDefault type helper to work with boolean
`withDefault` is a type helper that allows to create a type that
defaults to a default value when trying to decode a nullish value.
That type was not correctly working with boolean types, causing `false`
values to be replaced by true. This would specifically cause issues when
parsing the target state, where a `running: false` in a service would
become a `running: true` due to the type decoding.

Change-type: patch
2022-09-13 20:08:32 +00:00
Felipe Lalanne
5a57647450 Fix filtering of the supervisor app on the target state
Under some conditions, an aarch64 device may get a reference to a armv7hf
supervisor on the target state. One of the ways this can happen is if
an aarch64 device is added to an armv7hf fleet and the target supervisor
is set before the device fully provisions.

If that happens, the previous filtering for the supervisor app (which
relied on the architecture in device-type.json) would
fail and the user would end up with two supervisor containers, one
running correctly and the other crash looping.

This fixes the filtering and just checks if the supervisor uuid/service
name belongs to a group of known uuids.

Closes: #2006
Change-type: patch
2022-09-12 16:28:22 -03:00
Thodoris Greasidis
fadd514463 Set desired es-version for downstream modules that support it
Change-type: patch
2022-09-07 17:07:16 +03:00
Felipe Lalanne
48e0733c7e Remove side effects for module imports
The supervisor uses the following pattern for async module
initialization

```typescript
// module.ts

export const initialised = (async () => {
    // do some async initialization
})();

// somewhere else
import * as module from 'module';

async function setup() {
  await module.initialise;
}
```

The above pattern means that whenever the module is imported, the
initialisation procedure will be ran, which is an anti-pattern.

This converts any instance of this pattern into a function

```typescript
export const initialised = _.once(async () => {
    // do some async initialization
});
```

And anywhere else on the code it replaces the call with a

```typescript
await module.initialised();
```

Change-type: patch
2022-09-06 15:48:18 -04:00
Alexandru Costache
36544b7d6e Add custom DTB support for imx8mm-var-som
Change-type: patch
Signed-off-by: Alexandru Costache <alexandru@balena.io>
2022-09-06 16:33:35 +02:00
Felipe Lalanne
e0e1eacc6e Migrate lockfile tests to testfs
Since tests are ran in a container, lockfile tests no longer need to
mock the behavior of the `lockfile` binary.
2022-08-24 16:07:25 -04:00
Christina Wang
12b67742c8 Wait for Stopping services to stop before target apply success
This mitigates an edge case bug introduced in v13.1.3 where services that
are slow to exit may get stuck in a state of Downloaded if a service var is
changed then reverted rapidly. More detailed description in linked issue.

Change-type: patch
Closes: #1991
Signed-off-by: Christina Wang <christina@balena.io>
2022-08-02 14:34:25 -07:00
Felipe Lalanne
0c4e6ce421 Disable healthchecks failing on report errors
State report errors contribute to the supervisor failing healthchecks
and being restarted by the engine. There is not evidence of this
improving the connectivity situation and it is likely to make things
worst for the API as the first report is much more expensive than
subsequent partial reports.

Change-type: patch
Closes: #1986
2022-07-18 15:53:26 -04:00
Felipe Lalanne
861e902d7f Allow directories to be used as lockfiles
Some libraries, like [proper-lockfile](https://www.npmjs.com/package/proper-lockfile)
use directories instead of files for locking. This PR allows the supervisor to be able to
work with those types of locks when lock override is requested.

Closes: #1978
Change-type: patch
2022-07-13 13:05:38 -04:00
Christina Wang
0fc79e87d9 Allow host config patch regardless of running applications
Host config shouldn't be tied to applications in the first place, but
needs to be done so because it uses update locks to determine when it's
safe to patch host config, and update locks are tied to apps.

Change-type: patch
Signed-off-by: Christina Wang <christina@balena.io>
2022-07-06 12:41:51 -07:00
Christina Wang
a7a0821a3e Read hostname from config.json with container /etc/hostname as backup
We don't need to read the host's hostname through /mnt/root/etc/hostname,
because the hostname is written to config.json on a change. When the hostname
has never changed, it won't be found in config.json, so we can default to
the Supervisor container's /etc/hostname as it will match the host's
/etc/hostname, the network mode being `host`.

Closes: #1968
Change-type: patch
Signed-off-by: Christina Wang <christina@balena.io>
2022-06-15 11:31:36 -07:00
Christina Wang
dfb6bcf0e6 Add custom DTB support for Variscite Dart DT family
Closes: #1963
Relates-to: https://github.com/balena-os/balena-variscite-mx8/pull/134
Relates-to: https://github.com/balena-io/open-balena-api/issues/1033
Change-type: patch
Signed-off-by: Christina Wang <christina@balena.io>
2022-06-14 11:26:45 -07:00
Christina Wang
ffa1c73418 Better document mocked-dbus, add missing dbus interface methods
Change-type: patch
Signed-off-by: Christina Wang <christina@balena.io>
2022-06-09 11:41:50 -07:00
Felipe Lalanne
99efd12acd Do not send name as part of the current state
This fixes a race condition that could occur with the first current
state report, where if the device managed to send the current state
report first, then the device name on the cloud would be set to `local`
(see #1959).

Closes: #1959
Change-type: patch
2022-06-07 15:14:21 -04:00
Christina Wang
be1c01039a Don't use config.get for appId when checking locks in host config PATCH
Change-type: patch
Signed-off-by: Christina Wang <christina@balena.io>
2022-06-06 12:15:23 -07:00
20k-ultra
aad5a9efc5 Use locks before shutdown/reboot instead of stopping containers
Closes: #1940
Change-type: patch
Signed-off-by: 20k-ultra <3946250+20k-ultra@users.noreply.github.com>
2022-06-02 00:31:42 -04:00
20k-ultra
471f0f0615 Refactor update-lock.lock to accept an array of applications to lock
Change-type: patch
Signed-off-by: 20k-ultra <3946250+20k-ultra@users.noreply.github.com>
2022-06-02 00:31:42 -04:00
20k-ultra
ef7371a7ef Refactor update-lock function to avoid callback hell
Change-type: patch
Signed-off-by: 20k-ultra <3946250+20k-ultra@users.noreply.github.com>
2022-06-02 00:31:42 -04:00
Christina Wang
6ccd2178c1 Use Mounts API for engine socket feature label
When upgrading to this Supervisor version, containers using the
engine feature label will be restarted.

Relates-to: https://github.com/balena-os/balena-supervisor/pull/1780
Closes: https://github.com/balena-os/balena-engine/issues/220
Closes: #1933
Change-type: major
Signed-off-by: Christina Wang <christina@balena.io>
2022-05-17 23:57:28 +00:00
Felipe Lalanne
af1a60f7c6 Throw a more explanatory error if migrating apps.json fails 2022-05-26 16:58:15 -04:00
Felipe Lalanne
303c805008 Fix check for preloaded v2 target state 2022-05-24 17:55:05 -04:00
Christina Wang
95bf4718d6 Only migrate apps.json on preload after target has been set
Change-type: patch
Signed-off-by: Christina Wang <christina@balena.io>
Signed-off-by: Felipe Lalanne <felipe@balena.io>
2022-05-24 17:54:38 -04:00
Felipe Lalanne
76553c6b4a Trim newlines from sysinfo files
Change-type: patch
2022-05-23 14:08:08 -04:00
Felipe Lalanne
29867ccf17 Fix serial number support for variscite boards
Closes: #1950

Change-type: patch
2022-05-23 10:29:22 -04:00
Christina Wang
2896444988 Log anonymous volumes
Signed-off-by: Christina Wang <christina@balena.io>
2022-05-17 11:08:23 -07:00
Christina Wang
0a9c7282e8 Add compose support for volumes defined with long syntax
balena-compose already supports this, and with this PR, Supervisor can
have the option of using HostConfig.Mounts for internal bind mounts such as
ones added by feature labels. This will be handled in a future PR.

The only blocker to having users use long syntax is adding this feature
to target state. This PR does not add that feature.

Relates-to: https://github.com/balena-os/balena-supervisor/pull/1780
Relates-to: https://github.com/balena-os/balena-engine/issues/220
Relates-to: #1933
Change-type: patch
Signed-off-by: Christina Wang <christina@balena.io>
2022-05-17 11:08:23 -07:00
20k-ultra
67f9c44a6c Prevent throttling reports when nothing was sent
Change-type: patch
Signed-off-by: 20k-ultra <3946250+20k-ultra@users.noreply.github.com>
2022-05-16 15:19:55 -04:00
Felipe Lalanne
a5ede01b18 Avoid splash image failures if image is corrupt
Splash image backend would throw if the image is not a valid png during
the write step. This could prevent the device from provisioning if some
corruption happens at some point.

Change-type: patch
2022-05-03 15:30:18 +00:00
Felipe Lalanne
c04955354a Use write + sync when writing configs to /mnt/boot
This commit updates all backends that write to /mnt/boot to do it
through a new `lib/host-utils` module. Writes are now done using write +
sync as rename is not an atomic operation in vfat.

The change also applies for writes through the `/v1/host-config`
endpoint.

Finally this change includes some improvements on tests.

Change-type: patch
2022-05-03 11:23:00 -04:00
20k-ultra
2e81a7328e Use delay instead of interval to recursively report state
Change-type: patch
Signed-off-by: 20k-ultra <3946250+20k-ultra@users.noreply.github.com>
2022-04-27 23:16:38 -04:00
20k-ultra
5437aea786 Remove in memory storage of started/stopped containers
Change-type: patch
Signed-off-by: 20k-ultra <3946250+20k-ultra@users.noreply.github.com>
2022-04-19 22:27:15 -04:00
20k-ultra
ca9945bdfb Only start a container once in its lifetime
This will ensure the restart policy specified is not violated

Change-type: patch
Closes: #1668
Signed-off-by: 20k-ultra <3946250+20k-ultra@users.noreply.github.com>
2022-04-19 22:27:15 -04:00
Christina Wang
babe10e2a7 Move Supervisor-specific from lockfile.ts to update-lock.ts to
make lockfile module more generic

BASE_LOCK_DIR, LOCKFILE_UID moved to update-lock.ts

Signed-off-by: Christina Wang <christina@balena.io>
2022-04-12 12:02:57 -07:00
Christina Wang
cfd3f03e4a Make lockfile cleanup multi-app aware
When disposing of resources which include Supervisor-created lockfiles,
only dispose of lockfiles for the specified user application.

Signed-off-by: Christina Wang <christina@balena.io>
2022-04-12 12:02:28 -07:00