Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

Add convenience bindings in __init__ #5

Open
ca-scribner opened this issue Nov 22, 2021 · 1 comment
Open

Add convenience bindings in __init__ #5

ca-scribner opened this issue Nov 22, 2021 · 1 comment

Comments

@ca-scribner
Copy link
Contributor

I liked what @DnPlas did in the training operator where she bound a few commonly used things from the model to local attributes in __init__. Should we add some standard ones to our template? Yes, these are things that are already available (via self.model... etc), but to new people they're hard to find (and sometimes interpret, for example namespace). At a minimum, bindings tend to read better in the code.

I'm thinking something like:

def __init__(...):
  self._name = self.model.app.name
  self._namespace = self.model.name  # Or even better, we put in the template the more robust namespace solution @jnsgruk proposed a few weeks back, I think to handle when something is accidentally deployed into the controller model?
  self._model_name = self.model.name
  # (other things)
@jnsgruk
Copy link
Member

jnsgruk commented Nov 23, 2021

I'm not sure about including this in the template itself. Particularly given that not all charms will necessarily use them, and in particular, the variable _namespace makes little sense in the context of a machine charm.... (I accept that the template has containers/pebble stuff in it...)

ca-scribner pushed a commit to ca-scribner/operator-template-1 that referenced this issue May 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants