-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Append to existing apps.json preload state instead of overwriting #242
base: master
Are you sure you want to change the base?
Conversation
8ed207a
to
08bff28
Compare
681e5c7
to
d068f5d
Compare
e3a74c6
to
1575c86
Compare
57b64ff
to
8e1ab6d
Compare
5e4a78c
to
4f6b4d6
Compare
Validation on a devenv with a draft v3 state endpoint: [x] Preloading on an image with preloaded
[x] Preloading on an image without
|
87a7189
to
85e0fb0
Compare
715f3e9
to
fc0dc06
Compare
Update the supervisor repository regex so the supervisor version can be correctly extracted from the images. Change-type: patch Signed-off-by: Alex Gonzalez <[email protected]>
If the image we are preloading to contains an existing `apps.json` append the preloaded app to it instead of overwriting it. Fixes balena-io/balena-cli#2262 Change-type: patch Signed-off-by: Alex Gonzalez <[email protected]>
Newer supervisors support v3 target state that support multiple apps in the target state and use a uuid as index. Fixes #245 Change-type: patch Signed-off-by: Alex Gonzalez <[email protected]>
fc0dc06
to
e9a611b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small things while it is still a draft -- I'd have approved the PR if it wasn't a draft. :-)
@@ -739,6 +739,15 @@ class Preloader extends EventEmitter { | |||
} | |||
} | |||
|
|||
_supervisorLT13() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid logic duplication, _supervisorLT7
could be renamed _supervisorLT
and take the version as a parameter. To preserve the existing "typo safety feature", the version strings could be assigned to module-level constants. For example:
const v7 = '7.0.0';
const v13 = '13.0.0';
class Preloader extends EventEmitter {
...
_supervisorLT(version) {
try {
return compareVersions(this.supervisorVersion, version) === -1;
...
}
this._supervisorLT7()
→this._supervisorLT(v7)
this._supervisorLT13()
→this._supervisorLT(v13)
for service in app['services']: | ||
image_name = app['services'][service]['image'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The image
property is guaranteed to exist, right? Otherwise, .get()
could be used instead of the bracket syntax to avoid a KeyError
, plus providing the empty string as a default value:
for service in app['services']: | |
image_name = app['services'][service]['image'] | |
for service in app['services'].values(): | |
image_name = service.get('image', '') |
get_images_and_supervisor_version() | ||
) | ||
|
||
for uuid in list(current_state['apps'].keys()): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A line of code can be deleted (app = current_state['apps'][uuid]
) later on by using items()
instead of keys()
:
for uuid in list(current_state['apps'].keys()): | |
for [uuid, app] in current_state['apps'].items(): |
In Python 3 (the version used by preload), keys()
values()
items()
return iterators and list()
can be used to create an indexable list/array out of the iterators where needed, but it doesn't look needed here.
raise Exception("State version mismatch") | ||
|
||
# Halt if user apps are present in current state | ||
app = current_state['apps'][uuid] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line can be deleted if the [uuid, app]
unpacking suggested in another comment is used.
This is to remain in draft state until the v3 target state API changes are merged
If the image we are preloading to contains an existing
apps.json
appendthe preloaded app to it instead of overwriting it.
Fixes balena-io/balena-cli#2262
Relates to balena-io/balena-cli#2263
Change-type: patch
Signed-off-by: Alex Gonzalez [email protected]
Tested on a
raspberrypi4-64-2.75.0+rev1
image that does not contain a preloadedapps.json
, and on a genericx86-64-ext development build with an existingapps.json
with preloaded state.