Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

pipex
Copy link

@pipex pipex commented Sep 27, 2024

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

@kb2ma
Copy link

kb2ma commented Oct 4, 2024

The logic looks sound here, but it really jumps outside the logic framework in getHupActionType(). One alternative might be to define takeoverTargetVersion as a property of ActionConfig, which helps indicate it is a special case. Then below where those properties are looked up in getHupActionType(), first test if it's a takeover -- If targetTakeoverVersion is defined, currentVersion is less than tTV, and targetVersion is greater than tTV, then change the actionName to 'takeover'. Otherwise the action remains 'balenahup'.

We also could expand the value of takeoverTargetVersion to be an array if necessary.

@pipex
Copy link
Author

pipex commented Oct 21, 2024

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 else clause

} else {
// Takeover overrides the checks below for the device type
if (this.isTakeoverRequired(deviceType, currentVersion, targetVersion)) {
return 'takeover';
}
actionName = 'balenahup';
}
for the targetTakeoverVersion which is pretty close to what we do with the isTakeoverRequired

Please correct me if I'm misunderstanding your point

@kb2ma
Copy link

kb2ma commented Oct 22, 2024

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 getHUPActionType(), the actionName initially would be 'balenahup'. Then takeoverTargetVersion would be read where the other actionConfig version values currently are read. Finally, at the end of getHUPActionType() there are some validation conditionals. Maybe just before those add the logic to see if takeoverTargetVersion is being crossed for balenahup, and if so return 'takeover' instead.

What I meant by jumping out of the flow is two things:

  • The current logic in getHUPActionType() returns immediately if isTakeoverRequired() is true
  • The definition of DeviceTypeConfig includes a special case for takeover minTargetVersion, which I found confusing

So the definition for jetson-xavier-nx-device-emmc could be like below, which also could be an array of strings for multiple jumps.

		'jetson-xavier-nx-devkit-emmc': {
			balenahup: {
				// NOTE: this version is here as a placeholder for
				// testing. Replace with the correct version before merging
				takeoverTargetVersion: '5.1.45+rev1',

I would say the key that makes this approach reasonable/possible is that getHUPActionType() returns only the name of the action.

@pipex
Copy link
Author

pipex commented Oct 22, 2024

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.

takeover minTargetVersion, which I found confusing

I agree this is confusing

I'll make the changes

@kb2ma
Copy link

kb2ma commented Oct 22, 2024

@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:

  1. Add all 3 device types: jetson-xavier, jetson-xavier-nx-devkit, jetson-xavier-nx-devkit-emmc
  2. Set the targetTakeoverVersion to 99.99.99 so it won't be invoked
  3. Merge this PR

Then all we need to do is create a PR that sets the right version for those three DTs.

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.
@@ -72,7 +72,7 @@ export class HUPActionHelper {
deviceType: string,
currentVersion: string,
targetVersion: string,
) {
): ActionName | 'takeover' {
Copy link

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.

Copy link

@kb2ma kb2ma Oct 24, 2024

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.

Copy link
Author

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

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

actions: { [K in ActionName]: ActionConfig };
but that also seems just as dirty?

I'm not entirely sure what is the best course of action

@kb2ma
Copy link

kb2ma commented Oct 24, 2024

Inspected the rework but have not tested yet. Overall looks good except for the comment above on ActionName.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants