-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add takeover action for some device types #35
Conversation
Change-type: minor
0482414
to
f522a6b
Compare
The logic looks sound here, but it really jumps outside the logic framework in We also could expand the value of takeoverTargetVersion to be an array if necessary. |
I agree that is another way to do it, but I think that also jumps outside the logic no? You would still need to check in the balena-hup-action-utils/lib/index.ts Lines 122 to 128 in f522a6b
targetTakeoverVersion which is pretty close to what we do with the isTakeoverRequired
Please correct me if I'm misunderstanding your point |
If takeoverTargetVersion is a property of ActionConfig, we could consider takeover as a special case for balenahup -- and that is essentially its purpose. So in What I meant by jumping out of the flow is two things:
So the definition for jetson-xavier-nx-device-emmc could be like below, which also could be an array of strings for multiple jumps.
I would say the key that makes this approach reasonable/possible is that getHUPActionType() returns only the name of the action. |
Yes, I like this, it makes takeover kind of a special case of balenahup instead of its own process which is a good way to model it.
I agree this is confusing I'll make the changes |
@pipex, I was thinking about how to stage this work so it's easy to pull the trigger when all the other pieces are ready. How about this plan:
Then all we need to do is create a PR that sets the right version for those three DTs. |
lib/index.ts
Outdated
@@ -72,7 +72,7 @@ export class HUPActionHelper { | |||
deviceType: string, | |||
currentVersion: string, | |||
targetVersion: string, | |||
) { | |||
): ActionName | 'takeover' { |
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.
Why not just make 'takeover' another ActionName? As is, this likely forces clients to add this extra option as well. For example, see balena-proxy services.action-backend.actions.config.ts
.
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.
After more review I see how this decision is a judgement call. I'd still rather keep the names simple for clients and modify the type definition for the ActionsConfig as needed (just for action?). A comment for ActionName will help explain how it's different.
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.
That was the first thing I did, but I would have to create an additional item here
balena-hup-action-utils/lib/config.ts
Line 20 in 8f8a770
actions: { |
For those actions minSourceVersion
and minTargetVersion
are required and those values don't really make sense for takeover (or I don't know what to use)
I guess I could omit takeover
in the type definition here
balena-hup-action-utils/lib/types.ts
Line 34 in 8f8a770
actions: { [K in ActionName]: ActionConfig }; |
I'm not entirely sure what is the best course of action
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.
@pipex I created PR #37 that adds a commit with changes to add 'takeover' as an action name. It builds OK with balena-proxy. I didn't define an ActionConfig because that seemed simplest. But really we also could define one with empty string values for minSourceVersion
and minTargetVersion
.
I think it's perfectly fine to use comments in the implementation to explain the use of 'takeover'. We could modify the abstractions to accommodate how 'takeover' is used, but I don't see the value when we're not sure how our use of takeover will evolve.
As you say above, because of my implementation I modified the actions definition so an entry is optional. IMO, I would rather keep the interface to getHUPActionType()
simple/unchanged. Let the implementation jump through whatever hoops are required to make it work.
I also added the expected minTakeoverVersion
for the three device types.
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.
@kb2ma I think the problem with doing it like that is that making the ActionConfig optional removes some guarantees that are used by the code in getHUPActionType()
.
The code below expects minSourceVersion
and minTargetVersion
to always be defined. The type in config.ts also enforces it and the code won't compile if you add an action without those values.
balena-hup-action-utils/lib/index.ts
Lines 143 to 159 in 8f8a770
const { | |
minSourceVersion, | |
targetMajorVersion, | |
minTargetVersion, | |
minTakeoverVersion, | |
maxTargetVersion, | |
} = { | |
...actionsConfig.actions[actionName], | |
...defaultActions[actionName], | |
...deviceActions[actionName], | |
}; | |
if (bSemver.lt(currentVersion, minSourceVersion)) { | |
throw new HUPActionError( | |
`Current OS version must be >= ${minSourceVersion}`, | |
); | |
} |
I think that if we want to use takeover
as action we could set some nonsense values for those two variables (e.g v99.99.99) and add a comment about the reason for that configuration.
After that we'll be able to return takeover
from getHUPActionType
maintaining the type guarantees
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.
Added a new commit with the proposed change. Included the new jetson xavier versions
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.
Good compromise. We always can add some metadata to ActionConfig in the future to differentiate takeover from the others. Let me try building and using this locally on my BoB.
Inspected the rework but have not tested yet. Overall looks good except for the comment above on ActionName. |
This commit adds `minTakeoverVersion` to indicate a version jump that requires a takeover instead of `balenahup`. This is used by `getHupActionType` to identify the need for a takeover update.
Also define expected minTakeoverVersion for Xavier device types
8f8a770
to
dfc8274
Compare
@@ -33,6 +33,15 @@ export const actionsConfig: ActionsConfig = { | |||
minSourceVersion: '2.0.0+rev1', | |||
minTargetVersion: '2.2.0+rev1', | |||
}, | |||
takeover: { | |||
// Takeover is a possible action returned by getHUPActionType |
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.
Nice comment!
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.
Tested a few different ways; works as expected.
This is a proof of concept on how we could repurpose this module to indicate that a
takeover
is needed between certain versions for some device types.Change-type: minor