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: make layers with label prefix "pebble-" reserved #403

Merged
merged 8 commits into from
Apr 8, 2024
9 changes: 3 additions & 6 deletions internals/overlord/planstate/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,10 @@ func (m *PlanManager) SetServiceArgs(serviceArgs map[string][]string) error {
defer m.planLock.Unlock()

newLayer := &plan.Layer{
// Labels with "pebble-*" prefix are (will be) reserved, see:
// Labels with "pebble-*" prefix are reserved, see:
// https://github.com/canonical/pebble/issues/220
// Validation for layer labels has been added, so after so after creating the
// Layer directly (not parsing from raw data), it won't need to be validated.
IronCore864 marked this conversation as resolved.
Show resolved Hide resolved
Label: "pebble-service-args",
Services: make(map[string]*plan.Service),
}
Expand All @@ -229,10 +231,5 @@ func (m *PlanManager) SetServiceArgs(serviceArgs map[string][]string) error {
}
}

err := newLayer.Validate()
if err != nil {
return err
}

return m.appendLayer(newLayer)
}
6 changes: 6 additions & 0 deletions internals/plan/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,12 @@ func (layer *Layer) Validate() error {
}
}

if strings.HasPrefix(layer.Label, "pebble-") {
IronCore864 marked this conversation as resolved.
Show resolved Hide resolved
return &FormatError{
Message: fmt.Sprintf("cannot use reserved layer label %q", layer.Label),
IronCore864 marked this conversation as resolved.
Show resolved Hide resolved
}
}

return nil
}

Expand Down
6 changes: 6 additions & 0 deletions internals/plan/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1933,3 +1933,9 @@ func (s *S) TestMergeServiceContextOverrides(c *C) {
WorkingDir: "/working/dir",
})
}

func (s *S) TestParseLayerReservedLabel(c *C) {
IronCore864 marked this conversation as resolved.
Show resolved Hide resolved
// Validate fails if layer label has the reserved prefix "pebble-"
_, err := plan.ParseLayer(0, "pebble-service-args", []byte("{}"))
IronCore864 marked this conversation as resolved.
Show resolved Hide resolved
c.Check(err, ErrorMatches, `cannot use reserved layer label "pebble-service-args"`)
}
Loading