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

snap.py's management() does not install snap if arg.revision == snap_latest_revision #128

Open
ca-scribner opened this issue May 30, 2024 · 3 comments

Comments

@ca-scribner
Copy link

When revision is defined in the snap_installation.yaml, management() installs the snap and holds the revision here:

https://github.com/canonical/k8s-operator/blob/5290074ca8b8d041f86656af6d10c40ee2282f99/charms/worker/k8s/src/snap.py#L116C1-L120C29

        elif isinstance(args, SnapStoreArgument) and args.revision:
            if which.revision != args.revision:
                log.info("Ensuring %s snap revision=%s", args.name, args.revision)
                which.ensure(**args.dict(exclude_none=True))
                which.hold()

where which.revision is the revision of the snap as pulled from the SnapCache() (likely the revision of latest/stable). Because the snap is only installed above if which.revision != args.revision, requesting the revision of the current latest/stable snap results in no snap being installed and the .hold() not being applied

@addyess mentioned a bug in snapd that if you refresh to the snap you're currently on, you still restart the services, so this might be an attempt at defending against that problem? afaict though, the newest version of the snap library has some protections against this. So probably we can do:

elif isinstance(args, SnapStoreArgument) and args.revision:
#             if which.revision != args.revision:  <--- removed
            log.info("Ensuring %s snap revision=%s", args.name, args.revision)
            which.ensure(**args.dict(exclude_none=True))
            which.hold()
@addyess
Copy link
Contributor

addyess commented May 30, 2024

@ca-scribner yes -- the library has that protection -- but i noticed that which.hold() will also cause the snap library to run refresh with the --hold args and i don't know if this TOO will restart the snap services.

@ca-scribner
Copy link
Author

yep good call, and I dont see an easy way of working around that with the lib.

You could probably avoid some unnecessary refreshes by checking if hold is on and if revision is correct. But if revision is correct and hold is off, this looks like it'll refresh the snap in order to set hold

@ca-scribner
Copy link
Author

ca-scribner commented Jun 3, 2024

(Whoops, meant to post this on Friday. Sorry!)

Ah, here's a win.

afaict snap refresh --hold=forever snapname does not restart the service, it just changes the hold status. I'm confirming this by watching snap log snapname then doing snap refresh --hold=forever. I dont see any log activity, so I think we're good to do a refresh --hold=forever any time

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

No branches or pull requests

2 participants