canonical / pebble

Take control of your internal daemons!
GNU General Public License v3.0
136 stars 51 forks source link

feat: make layers with label prefix "pebble-" reserved #403

Closed IronCore864 closed 3 months ago

IronCore864 commented 3 months ago

Making layers with label "pebble-*" reserved for pebble use only.

Closes https://github.com/canonical/pebble/issues/220.

Test:

/home/ubuntu/PEBBLE_HOME
└── layers
    └── 001-pebble-test.yaml

1 directory, 1 file
$ go run ./cmd/pebble run
cannot run daemon: cannot load plan: cannot use reserved layer label "pebble-test"
exit status 1
IronCore864 commented 3 months ago

Hi @benhoyt, I'm creating a draft PR, I'm not sure if this is the right way to implement it:

In order to use pebble-service-args in PlanManager.SetServiceArgs after making pebble-* as reserved layer label, the function SetServiceArgs has to check if the returned err, if the error suggests a reserved label is used, ignore it, because pebble itself should be able to use reserved label, right?

Then I found out Layer.Validate() currently returns only type FormatError, in which case, I'd have to check on the error message, something like strings.Contains(err.Error(), "cannot use reserved layer label").

But I think in Go it is generally recommended to avoid relying on error messages and it's better to handle errors based on types, right?

So in my draft I created another type ReservedLabelError, and in SetServiceArgs I ignore the error if it's this type. Does this make sense?