feat(planstate): add extension support#17
Draft
flotter wants to merge 9 commits intoplan-section-supportfrom
Draft
feat(planstate): add extension support#17flotter wants to merge 9 commits intoplan-section-supportfrom
flotter wants to merge 9 commits intoplan-section-supportfrom
Conversation
084f087 to
16d6dc9
Compare
2b30244 to
10a1398
Compare
5ff2951 to
e55b435
Compare
bfab837 to
ac9bf66
Compare
58f54e6 to
662fd6a
Compare
843bca0 to
38da84a
Compare
d3ae02c to
8de6590
Compare
38da84a to
f5eff8e
Compare
743147c to
9a51cfe
Compare
f5eff8e to
a1d6300
Compare
…nical#493) This means that not every request/response needs to acquire the state lock, as shown by the removal of the custom response type in the /v1/health endpoint. Note that there's a test, TestHealthStateLockNotHeldSuccess, that specifically tests that the state lock is not held during /v1/health requests. If we accidentally introduce locking again, that will fail. Fixes canonical#366.
5d9bef2 to
37d9be4
Compare
The plan library was originally written as a configuration schema for
the services manager (servstate). Over time the need arose to support
configurations for other managers such as checks (checkstate) and
log-targets (logstate). The configuration schema for these managers,
closely related to the services manager, has since also been built in to
the plan library.
The services manager and its related checks and log-targets
functionality will always be part of the Pebble core. However, as Pebble
is getting more functionality (additional managers) and also used as a
core in derivative projects, a more modular and dynamic approach to
extending the schema is needed.
Add an the ```SectionExtension``` interface for use by managers who
wishes to register a schema extension during Pebble startup.
Inside each layer, top level entries are now referred to as
```sections``` (built-in sections includes ```summary```,
```description```, ```services```, ```log-targets``` and ```checks```).
Each section has an associated ```field``` that is the top level key,
and if supplied by an extension, an opaque backing type ```Section```.
**SectionExtension interface:**
```
// SectionExtension allows the plan layer schema to be extended without
// adding centralised schema knowledge to the plan library.
type SectionExtension interface {
// ParseSection returns a newly allocated concrete type containing the
// unmarshalled section content.
ParseSection(data yaml.Node) (LayerSection, error)
// CombineSections returns a newly allocated concrete type containing the
// result of combining the supplied sections in order.
CombineSections(sections ...LayerSection) (LayerSection, error)
// ValidatePlan takes the complete plan as input, and allows the
// extension to validate the plan. This can be used for cross section
// dependency validation.
ValidatePlan(plan *Plan) error
}
type Section interface {
// Validate checks whether the section is valid, returning an error if not.
Validate() error
// IsZero reports whether the section is empty.
IsZero() bool
}
```
**Example usage:**
```
// New SectionExtension type
type fooExtension struct{}
func (f *fooExtension) ParseSection(data yaml.Node) (LayerSection, error) {...}
func (f *fooExtension) CombineSections(sections ...LayerSection) (LayerSection, error) {...}
func (f *fooExtension) ValidatePlan(plan *Plan) error {...}
// New Section type
type FooSection struct {
Entries map[string]Bar `yaml:",inline,omitempty"`
}
type Bar struct {
Name string `yaml:"name,omitempty"`
}
func (s *FooSection) Validate() error {...}
func (s *FooSection) IsZero() bool {...}
```
```
// Early startup
plan.RegisterExtension("foo", &fooExtension{})
:
// Load layers containing new section
newPlan := plan.ReadDir(layersDir)
:
// Show plan
yaml.Marshal(newPlan)
```
Example YAML output:
```
foo:
bar1:
name: test1
bar2:
name: test2
```
37d9be4 to
5966f30
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.