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

feat: poc parsing juju env in one place - alternative draft #1314

Closed

Conversation

IronCore864
Copy link
Contributor

@IronCore864 IronCore864 commented Aug 13, 2024

Parse all JUJU_* env vars in one place.

Closes #1075.

Alternative version where variables are grouped with explicit types.

See the first version here: #1313.

Typing is explicitly not None except juju_charm_dir, juju_debug, and juju_dispatch_path because the original code tests whether they are in os.environ or not.

chore: poc parsing juju env in one place

chore: refactor _JuJuContext to a dataclass
Copy link
Contributor

@dimaqq dimaqq left a comment

Choose a reason for hiding this comment

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

While in general, "flat is better than nested", I think that 1 level of nesting is just fine, assuming that the net difference is, roughly, writing something like

assert ctx.notice
if ctx.notice.type == "...": ...

instead of

assert ctx.notice_id
if ctx.notice_type == "...": ...

On the other hand, if nesting grew deeper, I wouldn't be so sure.

juju_action: '_JujuAction'
juju_charm_dir: Optional[str]
juju_debug: Optional[str]
juju_departing_unit: str
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that this field should be scoped under relation

juju_dispatch_path: Optional[str]
juju_notice: '_JujuNotice'
juju_pebble_check_name: str
juju_relation: '_JujuRelation'
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer that the top-level field is optional, rather than its components

juju_remote_app: str
juju_remote_unit: str
juju_secret: '_JujuSecret'
juju_storage_id: str
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 this field is called "storage tag" in juju codebase. The change is from 3 years ago, maybe we can follow that lead? wdyt?

juju_remote_unit: str
juju_secret: '_JujuSecret'
juju_storage_id: str
juju_workload_name: str
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this should be scoped under "container"

juju_departing_unit: str
juju_dispatch_path: Optional[str]
juju_notice: '_JujuNotice'
juju_pebble_check_name: str
Copy link
Contributor

Choose a reason for hiding this comment

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

I imagine this too should be scoped under... a check? a container? a notice? Ugh this is getting difficult...

Copy link
Contributor

Choose a reason for hiding this comment

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

It indeed gets messy. It shouldn't really be under notice because notices are meant to be an implementation detail of check events. It's really check and notice both under container, but I don't think we want to be three levels deep (I'm not even convinced of two levels).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, I'm with Tony on this one, and this is part of the reason that hierarchies -- while seeming enticing at first -- are often not ideal. Sometimes it's unclear which hierarchy something belongs in, and sometimes a thing belongs in multiple hierarchies.

In addition, if we're going for nested, I don't like how we have to have all these different classes, like _JujuRelation (and it's actually not a relation, it's an "extended relation identifier" or something).

So I'm much more in favour of flat, 1-level for this, as #1313 does.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Additionally, we convert to "proper" types further down, like converting notice id/type/key to LazyNotice in the notice events. I think that's another reason to keep the types here flat and simple.

@IronCore864
Copy link
Contributor Author

After discussion, we will use a flat structure without nested objects, and we will put all fields as Optional[str] or Optional[int]. Closing this PoC in favour of the other one, changes will be made in the other PR.

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.

Hook context: Add a clear boundary between ops and juju
4 participants