feat(systemd): add resource plugin for systemd unit files#8970
feat(systemd): add resource plugin for systemd unit files#8970ScMofeoluwa wants to merge 2 commits into
Conversation
Adds a systemd resource plugin capable of reading, checking, and updating options in systemd unit files using go-systemd Refs updatecli#8951
There was a problem hiding this comment.
Pull request overview
Adds a new systemd resource plugin so Updatecli can read, check, and update options in systemd-style unit files, including Quadlet .container files.
Changes:
- Introduces
systemdresource implementation for source, condition, target, validation, and report config. - Registers the
systemdresource kind in the resource factory and schema mapping. - Adds unit tests and the
go-systemddependency.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
pkg/plugins/resources/systemd/main.go |
Defines the resource, defaults, config reporting, and unit option parsing. |
pkg/plugins/resources/systemd/spec.go |
Defines and validates the systemd resource spec. |
pkg/plugins/resources/systemd/source.go |
Reads configured option values from unit files. |
pkg/plugins/resources/systemd/condition.go |
Checks configured option values against expected values. |
pkg/plugins/resources/systemd/target.go |
Updates configured option values in unit files. |
pkg/plugins/resources/systemd/*_test.go |
Adds tests for construction, validation, source, condition, and target behavior. |
pkg/core/pipeline/resource/main.go |
Registers the new systemd resource kind. |
go.mod |
Adds github.com/coreos/go-systemd/v22. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| opt.Value = expected | ||
|
|
||
| reader := unit.Serialize(opts) |
| expected := source | ||
| if expected == "" { | ||
| expected = s.spec.Value | ||
| } |
| expected := source | ||
| if expected == "" { | ||
| expected = s.spec.Value | ||
| } |
|
I tested the pullrequest with the following example, where /tmp/wg.container is the file mentioned in the issue. Another question that I am wondering in the case of the example shared in the linked issue. |
Hmm, good point. I think a safer approach might be: update normally when there is only one match, but return an error when multiple matching options are found unless the user provides an explicit selector like |
Adds a systemd resource plugin for reading and updating options in systemd unit files using go-systemd. Defaults to Container/Image for Quadlet compat.
Test
go test ./pkg/plugins/resources/systemd/Checklist
Refs #8951