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(planstate): add extension support #17

Draft
wants to merge 9 commits into
base: plan-section-support
Choose a base branch
from

Conversation

flotter
Copy link
Owner

@flotter flotter commented Aug 1, 2024

No description provided.

@flotter flotter force-pushed the plan-section-support branch 9 times, most recently from 084f087 to 16d6dc9 Compare August 8, 2024 18:05
@flotter flotter force-pushed the plan-manager-sections branch from 2b30244 to 10a1398 Compare August 13, 2024 14:14
@flotter flotter force-pushed the plan-section-support branch 2 times, most recently from 5ff2951 to e55b435 Compare August 19, 2024 18:44
@flotter flotter force-pushed the plan-manager-sections branch 2 times, most recently from bfab837 to ac9bf66 Compare August 19, 2024 21:53
@flotter flotter force-pushed the plan-section-support branch from 58f54e6 to 662fd6a Compare August 20, 2024 06:54
@flotter flotter force-pushed the plan-manager-sections branch 3 times, most recently from 843bca0 to 38da84a Compare August 26, 2024 14:04
@flotter flotter force-pushed the plan-section-support branch from d3ae02c to 8de6590 Compare August 26, 2024 14:35
@flotter flotter force-pushed the plan-manager-sections branch from 38da84a to f5eff8e Compare August 26, 2024 14:36
@flotter flotter force-pushed the plan-section-support branch from 743147c to 9a51cfe Compare August 28, 2024 14:38
@flotter flotter force-pushed the plan-manager-sections branch from f5eff8e to a1d6300 Compare August 28, 2024 19:21
…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.
@flotter flotter force-pushed the plan-manager-sections branch from 5d9bef2 to 37d9be4 Compare August 30, 2024 06:51
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          
```
@flotter flotter force-pushed the plan-manager-sections branch from 37d9be4 to 5966f30 Compare August 30, 2024 06:55
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.

2 participants