Commit Graph

1263 Commits

Author SHA1 Message Date
Felipe Lalanne
4cdf26f82f Improve supervisor API behavior when locks are set
This PR adds the following

* Supervisor v1 API application actions now return HTTP status code 423 when locks
  are preventing the action to be performed. Previously this resulted in a
  503 error
* Supervisor API v2 service actions now returns HTTP status code 423 when locks are
  preventing the action to be performed. Previously, this resulted in an
  exception logged by the supervisor and the API query timing out
* Supervisor API `/v2/applications/:appId/start-service` now does not
  check for a lock. Lock handling in v2 actions is now performed by each
  step executor
* `/v1/apps/:appId/start` now queries the target state and uses that
  information to execute the start step (as v2 does). Previously start
  resulted in `cannot get appId from undefined`
* Extra tests for API methods

Change-type: patch
Connects-to: #1523
Signed-off-by: Felipe Lalanne <felipe@balena.io>
2020-12-14 10:43:41 -03:00
Felipe Lalanne
a8c4a6683a Add config.txt support for Alliance rpi3
Change-type: patch
Signed-off-by: Felipe Lalanne <felipe@balena.io>
2020-12-11 09:46:48 -03:00
Cameron Diver
2c1fb7110e Add config.txt support for Rocktech rpi
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-12-10 11:14:35 +00:00
Miguel Casqueira
8b37df492b Patched /v1/restart exception
Change-type: patch
Closes: #1509
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-11-30 15:42:49 -05:00
Rich Bayliss
02aeb4fc1c fix: Scoped keys breaking livepush with existing cloud images on the device
Closes: #1512
Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
2020-11-16 12:55:40 -05:00
Felipe Lalanne
e4e895630f Ensure the first target state request is applied
During first time run of the supervisor, the target state is queried
by `reportInitialEnv`. Since this happens early on the initialization
process, this target state report is missed by any listeners and this
can lead to the initial target state not beeing applied (see #1455).

This PR ensures that target state is re-emitted if there were no
listeners setup on call to update.

Change-type: patch
Signed-off-by: Felipe Lalanne <felipe@balena.io>
Connects-to: #1455
2020-11-13 10:19:27 -03:00
Rich Bayliss
bc9bdd1094
validation: Ensure commit lookup has a bound value
Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
2020-11-11 11:01:20 +00:00
Rich Bayliss
591598e102
fix: Scoped keys not working in LocalMode
Some endpoints filter data based on the scope of the API key
used to make the request. When in LocalMode the check was not
being made correctly and all apps were considered out of scope.

Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
2020-11-11 10:58:58 +00:00
Cameron Diver
f08316dc57 Allow storing commits against their appIds
This paves the way for running multiple applications and storing
information related to the application against the application itself. A
couple of hacks have been added to v1 and v2 endpoints to maintain
compatability but these should eventually be removed with the addition
of a v3 api.

Change-type: minor
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-11-10 10:50:08 +00:00
Felipe Lalanne
01477e41b8 Mount docker socket under /host/run for services
Currently, when the label `io.balena.features.balena-socket` is set,
the balena engine socket is mounted under `/run/balena-engine.sock`.

This causes a problem when using systemd inside the container, since
this service remounts `/run` and `/run/lock` as tmpfs, causing the
socket to become unavailable.

Making a mount of the socket into `/host/run` solves this issue. This is
the same approach taken with DBUS.

Change-type: patch
Signed-off-by: Felipe Lalanne <felipe@balena.io>
Connects-to: #1494
2020-10-29 15:54:31 -03:00
Cameron Diver
9d19a45701 Use root mount point to find device-type.json
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-10-28 13:03:40 +00:00
Thomas Manning
2c83864f22 Change log source from docker to journalctl
Change-type: minor
Signed-off-by: Thomas Manning <thomasm@balena.io>
2020-10-28 16:09:42 +10:00
Felipe Lalanne
f5183df356 Change source of deviceType to device-type.json
The source of truth for the device-type should be
device-type.json instead of config.json

Change-type: patch
Signed-off-by: Felipe Lalanne <felipe@balena.io>
Connects-to: #1472
2020-10-27 09:40:18 -03:00
Miguel Casqueira
77333f1e11 Fixed evaluating if updates are needed to reach target state
Closes: #1476
Change-type: patch
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-10-26 14:54:04 -04:00
Miguel Casqueira
edf23871d9 Improved log message when networks do not match
Change-type: patch
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-10-19 12:01:50 -04:00
ab77
0fd9b63762
Fixes check allowing preloading in local (unmanaged) mode
* adds apiEndpoint empty string check

Change-type: patch
2020-10-16 15:19:22 -07:00
Felipe Lalanne
4795c336d0 Handle delete of multiple images with same dockerImageId
A docker-compose.yml with the following structure

```
version: '2.1'
services:
  app_1:
    build: ./noisy-1
    image: noisy1
  app_2:
    build: ./noisy-1
    image: noisy1
  app_3:
    build: ./noisy-1
    image: noisy1
```

Will lead to the supervisor creating multiple image database entries
with the same dockerId (this is because of how the engine handles this
particular case). This case is not handled by the removal process
leading to image pile up and increased disk usage.

Change-type: patch
Signed-off-by: Felipe Lalanne <felipe@balena.io>
Connects-to: #1434
2020-10-16 14:06:10 -04:00
Felipe Lalanne
dd5f62227a Improve calculation for used system memory
The memory information reported by the supervisor currently
estimates the value of used memory as `MemTotal - MemFree`.
However, linux systems will try to cache and buffer as much
memory as possible, which will affect the output of `MemFree`
(from /proc/meminfo) and in consequence the memory usage seen
by the user on the dashboard, which will appear much greater than
it is.

The correct calculation should be `MemTotal - MemFree - Buffers - Cached`,
which the calculation performed by `htop` and the `free` commands.

Change-type: patch
Signed-off-by: Felipe Lalanne <felipe@balena.io>
Connects-to: #1471
2020-10-14 13:15:17 -03:00
Cameron Diver
a2ceb5c931 Refactor system information filtering
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-10-12 15:44:07 +01:00
Cameron Diver
0e3c026392 Attempt a state report once every maxReportFrequency
With the addition of the system information feature (CPU temp) etc if
there wasn't any changes in the docker or config state of the device,
updates in system information would not be sent to the API. Now we
attempt to send data once every maxReportFrequency (although this does
not mean that we will be sending data that often, we still only send the
delta, if one exists)

Change-type: patch
Closes: #1481
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-10-12 11:53:19 +01:00
Cameron Diver
975129188a Remove superfluous current state reporting code from api-binder
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-10-12 11:53:19 +01:00
Thomas Manning
1eeff698ac Add features label io.balena.features.journal-logs
Change-type: patch
Signed-off-by: Thomas Manning <thomasm@balena.io>
2020-10-12 15:37:35 +10:00
Matthew McGinn
8e65466f2d version: drop SUPERVISOR_VERSION env var
In order to make supervisor upgrades more transparent, lets move away
from this env var since it requires a container restart any time the supervisor
is upgraded. We should ultimately move towards providing the supervisors
set of capabilities, but that can come later

Connects-to: #1447
Change-type: major
Signed-off-by: Matthew McGinn <matthew@balena.io>
2020-09-29 11:22:30 -04:00
Felipe Lalanne
adffde932e Fix supervisor deadlock during migration
Due to the singleton work, when performing migration M00005 and there
are apps with services created in the database, a deadlock occurs
during database initialization due to a circular
dependency for generating scoped keys.

Change-type: patch
Signed-off-by: Felipe Lalanne <felipe@balena.io>
Connects-to: #1468
2020-09-28 23:52:36 -03:00
Miguel Casqueira
90981a00be Correctly evaluate if scheduledApply.delay is not set
Closes: #1428
Change-type: patch
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-09-25 13:14:09 -04:00
Felipe Lalanne
a5f3002e70 Fix config checks for ConfigFS backend
When trying to apply SSDT overlays in Up Board, the supervisor currently
gets stuck in a loop trying to apply target state. See #1465

This was due to a bug in parsing the configuration, which lead to
the method bootConfigChangeRequired returning true when no change was
needed.

Change-type: patch
Signed-off-by: Felipe Lalanne <felipe@balena.io>
Connects-to: #1465
2020-09-24 16:45:57 -03:00
Matthew McGinn
eebadebb53 mixpanel: superisor_version -> supervisor_version
Change-type: patch
Signed-off-by: Matthew McGinn <matthew@balena.io>
2020-09-24 10:43:43 -04:00
Rich Bayliss
c08de8701e api: Implement scoped Supervisor API keys
Each service, when requesting access to the Supervisor API, will
now get an individual key which can be scoped to specific resources.
In this iteration the default scope will be to the application that
the service belongs to.

We also have a `global` scope which is used by the cloud API when in
managed mode.

Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
2020-09-17 11:25:56 +00:00
Miguel Casqueira
07e644d0b6 Refactor extra_uEnv backend to match with more devices
Change-type: patch
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-09-15 14:19:59 -04:00
Rich Bayliss
96c68166a1
application-manager: Convert to a singleton
Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-09-14 11:23:36 +01:00
Rich Bayliss
e3864915bc
device-state: Convert to a singleton
Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-09-14 09:31:12 +01:00
Rich Bayliss
d50f7791e1
api-binder: Convert to a singleton
Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-09-14 09:31:12 +01:00
Cameron Diver
f305a333ba Add device system information to state endpoint patch
Change-type: minor
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-09-03 14:40:29 +01:00
Miguel Casqueira
662826d349 added support for configuring ODMDATA
Closes: 1206
Change-type: minor
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-08-29 09:05:27 -04:00
Rich Bayliss
f0c2a3cba7
bug: Resolve mDNS API URLs
Due to switching to Alpine the ability to resolve mDNS
hostnames was lost. This patch overrides the lookup and
manually resolves the names.

Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
2020-08-27 11:34:18 +01:00
Miguel Casqueira
7ea49bf4fb Preventing removing all configurations if device has no backends
Closes: #1437
Change-type: patch
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-08-24 13:41:17 -04:00
Cameron Diver
de4c1b2538 Don't enforce the vc4-fkms-v3d dtoverlay on rpi4
Change-type: patch
Closes: #1404
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-08-20 10:21:02 +01:00
Pagan Gazzard
379730a9e1 Update typed-error to 3.x
Update typed-error from 2.0.0 to 3.2.1

Change-type: patch
2020-08-19 10:07:54 +01:00
Pagan Gazzard
90fab43022 Update pinejs-client-request to 7.2.1
Update pinejs-client-request from 7.1.0 to 7.2.1

Change-type: patch
2020-08-18 18:28:10 +01:00
Miguel Casqueira
1d62209505 Refactor device-config to support configuring multiple backends
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-08-12 15:05:03 -04:00
Miguel Casqueira
ff404456b3 Refactor configurable backend class names
Change-type: patch
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-08-12 14:29:58 -04:00
Rich Bayliss
5aecd94e24
bug: Firewall not blocking supervisor access from outside the device
Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
2020-08-12 13:43:33 +01:00
Rich Bayliss
e9b536a889
bug: Allow DNS through firewall for local containers
We provide a local DNS server for containers to use and this
was not allowed through the firewall when enabled.

Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
2020-08-11 15:17:06 +01:00
Cameron Diver
aa823c1cfc Fix device-tag fetching function
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-08-05 13:30:34 +01:00
Pagan Gazzard
511cbbe74e Update pinejs-client-request and make use of a named key
Update pinejs-client-request from 7.0.0 to 7.1.0

Change-type: patch
2020-08-03 09:27:11 +00:00
Nitish Agarwal
11cac2dd69 Fixes #1299 v1 start/stop endpoint issue with service access.
Change-Type: patch
Signed-off-by: Nitish Agarwal <1592163+nitishagar@users.noreply.github.com>
2020-07-31 23:08:50 +05:30
Rich Bayliss
59561132cc
bug: Fix undefined containerId object
Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
2020-07-31 11:51:15 +01:00
Miguel Casqueira
9b37ce96f9 fix matching extra_uEnv backend with unsupported devices
Change-type: patch
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-07-30 14:04:37 -04:00
Pagan Gazzard
ffe3da6261 Fix an issue with reporting initial config using a stale target state
Change-type: patch
2020-07-30 10:48:54 +01:00
Matthew McGinn
15c57a86b4
fix up "atleast" -> "at least"
Change-type: patch
Signed-off-by: Matthew McGinn <matthew@balena.io>
2020-07-29 11:55:22 -04:00