Talking to a pebble inside a sidecar

This is not about a roadtrip with my friend Rocky McStoneface. This is about a little helper class I wrote when I was trying to find a way to fetch some state from a running Juju unit on microk8s.

This class, called RemotePebbleClient, allows you to interact with a pebble client in a charm’s sidecar container pretty much like the charm instance would.

Whereas a charm running on ‘myunit/0’ would:

container = self.unit.get_container('myworkload')
print(container.get_plan())  # or whatever

Using this class you can:

container = RemotePebbleClient('myworkload', unit='myunit/0', model='foo')
print(container.get_plan())  # or whatever

What happens behind the scenes is that RemotePebbleClient.get_plan() is in fact Popening:

juju ssh --container myworkload /charm/bin/pebble plan"

And casting that back to a pebble.Plan.

What more fun things could we use this for?

I was looking for a way to simply instantiate a pebble.Client locally and point it at my remote unit’s IP to have it ‘really’ talk over that same socket, but I stumbled against my ignorance of how that works and gave up after a few hours. If you can help, let me know!

1 Like