Skip to content

feat: track snap version#165

Merged
james-garner-canonical merged 2 commits intocanonical:mainfrom
skatsaounis:feat-track-snap-version
Aug 12, 2025
Merged

feat: track snap version#165
james-garner-canonical merged 2 commits intocanonical:mainfrom
skatsaounis:feat-track-snap-version

Conversation

@skatsaounis
Copy link
Contributor

@skatsaounis skatsaounis commented Aug 11, 2025

Keep track of the snap version, if such version is available so that it could be used from a charm to set the workload version.

For example, an operator charm could set the version like this:

def _on_start(self, _event: ops.StartEvent) -> None:
    self.unit.status = ops.MaintenanceStatus("starting...")
    maas = SnapCache()["maas"]
    workload_version = maas.version if maas.version is not None else maas.revision
    self.unit.set_workload_version(workload_version)

Copy link
Contributor

@james-garner-canonical james-garner-canonical left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi there, thanks for your contribution. The changes seem broadly reasonable, but there are a couple of changes that would be necessary before merging.

Firstly, let's validate this change in integration tests -- just checking that the exposed version field contains a string as expected in one of the existing tests would be sufficient.

Secondly, adding a new, required argument to the public Snap class is not a backwards compatible change, particularly when added in the middle of other positional arguments. See separate comment for suggested resolution.

Also, I wonder if version is always guaranteed to be populated, or if it's up to the developer of the snap -- let's be defensive here.

Oh and if you could update the PR description with a description of the changes and the motivation, that would be great, thanks!

@james-garner-canonical
Copy link
Contributor

james-garner-canonical commented Aug 12, 2025

PS: don't forget to sign the CLA. EDIT: actually, what's going on with the cla-check workflow? EDIT: apparently we may be able to resolve the issue by closing and the reopening the PR, will try later.

@skatsaounis
Copy link
Contributor Author

Hi @james-garner-canonical

Thank you very much for the review. I hope that my second commit answers all your suggestions. My initial understanding is that the version is something guaranteed to be required, but maybe you are right that version None can sometimes be allowed.

I will shortly update the PR description with some content about the introduction of version metadata.

Copy link
Contributor

@james-garner-canonical james-garner-canonical left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks!

@james-garner-canonical james-garner-canonical merged commit 23c8fc9 into canonical:main Aug 12, 2025
8 checks passed
@skatsaounis skatsaounis deleted the feat-track-snap-version branch August 12, 2025 09:18
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