`ops.pebble` silently drops layer fields it doesn't know about

Open
#2,941 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
python
Domain
backend

Research direction

Start with Layer, Service, Check, and LogTarget in ops/pebble.py, then inspect add_layer() and get_plan() to trace how dictionaries are converted and returned. Compare the two proposed approaches and check how layer merging currently works. Done means unknown fields survive dictionary round trips, or are reported when dropped, with consistent behavior for dict and YAML inputs.

Written by the indexing model from the issue text.

Description

rainy day

ops.pebble only keeps the layer fields it knows about. Layer keeps summary, description, services, checks and log-targets, and Service (and Check and LogTarget) read a fixed list of keys. add_layer turns a dict into Layer(layer).to_yaml(), so anything else a charm passes is silently dropped before Pebble sees it, and get_plan() drops it on the way back too. A YAML string is passed through as it is, so the same layer behaves differently depending on its type.

The current example is a service's workload field (plan.go) and the workloads section. Neither Juju 3.6 nor Juju main registers the workloads section extension (only the standalone pebble run does), so this doesn't break anything under Juju today, hence rainy day. But whenever Pebble adds a field, a charm that passes it in a dict loses it without any warning until ops catches up.

We should do one of these:

  • Keep the keys we don't know about and pass them back out in to_dict(), so that a dict round-trips. This is the most forward-compatible, but merging a layer with an unknown field would need some thought.
  • Warn (or raise) when a key is dropped, so that it's at least visible.

I lean towards the first, with merging treating unknown fields as "replace".

Dominant language
Python
Stars
267
Forks
156
Avg merge
5d 3h
Merged PRs (30d)
43

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from canonical/operator

All issues in canonical/operator

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.