docs: grab workload version in k8s tutorial#2559
Draft
tromai wants to merge 8 commits into
Draft
Conversation
tromai
commented
Jun 10, 2026
tromai
commented
Jun 11, 2026
benhoyt
reviewed
Jun 12, 2026
| return "1.0.4" | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True) |
Collaborator
There was a problem hiding this comment.
Let's avoid autouse fixtures unless absolutely necessary, as they can be quite confusing action-at-a-distance. Something like:
@pytest.fixture
def fake_version(monkeypath):
monkeypath.setattr(...)
def test_pebble_layer(fake_version):
...
Comment on lines
+243
to
+256
| def _on_demo_server_pebble_ready(self, event: ops.PebbleReadyEvent) -> None: | ||
| """Define and start a workload using the Pebble API.""" | ||
| # Get a reference the container attribute on the PebbleReadyEvent | ||
| container = event.workload | ||
| # Add initial Pebble config layer using the Pebble API | ||
| container.add_layer("fastapi_demo", self._get_pebble_layer(), combine=True) | ||
| # Make Pebble reevaluate its plan, ensuring any services are started if enabled. | ||
| container.replan() | ||
| # Set the workload version of this charm. | ||
| version = fastapi_demo.get_version(port=8000) | ||
| self.unit.set_workload_version(version) | ||
| # Learn more about statuses at | ||
| # https://documentation.ubuntu.com/juju/3.6/reference/status/ | ||
| self.unit.status = ops.ActiveStatus() |
Collaborator
There was a problem hiding this comment.
It's hard to tell what's being added here. Could we consider something like this?
Suggested change
| def _on_demo_server_pebble_ready(self, event: ops.PebbleReadyEvent) -> None: | |
| """Define and start a workload using the Pebble API.""" | |
| # Get a reference the container attribute on the PebbleReadyEvent | |
| container = event.workload | |
| # Add initial Pebble config layer using the Pebble API | |
| container.add_layer("fastapi_demo", self._get_pebble_layer(), combine=True) | |
| # Make Pebble reevaluate its plan, ensuring any services are started if enabled. | |
| container.replan() | |
| # Set the workload version of this charm. | |
| version = fastapi_demo.get_version(port=8000) | |
| self.unit.set_workload_version(version) | |
| # Learn more about statuses at | |
| # https://documentation.ubuntu.com/juju/3.6/reference/status/ | |
| self.unit.status = ops.ActiveStatus() | |
| def _on_demo_server_pebble_ready(self, event: ops.PebbleReadyEvent) -> None: | |
| # ... previous lines ... | |
| # Set the workload version of this charm. | |
| version = fastapi_demo.get_version(port=8000) | |
| self.unit.set_workload_version(version) |
| # version. If the workload has an API or some other way of getting the | ||
| # version, the test should get it from there and use that to compare to the | ||
| # unit setting. | ||
| assert version == "1.0.4" |
Collaborator
There was a problem hiding this comment.
Consider using something a bit more general, to avoid updates if the demo-server is updated with a minor or patch release:
Suggested change
| assert version == "1.0.4" | |
| assert version.startswith("1.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2282.
I open this as a draft for an initial review of the structure and direction of this update. My changes now are for the first tutorial chapter: creating a minimal k8s charm. After the content is finalized, I will port them to the remaining chapters.