Handle uninstantiated template quadlets#28380
Conversation
|
The issue proposes to diff --git a/pkg/domain/infra/abi/quadlet.go b/pkg/domain/infra/abi/quadlet.go
index 34652ebbc4..c8a4dc24ed 100644
--- a/pkg/domain/infra/abi/quadlet.go
+++ b/pkg/domain/infra/abi/quadlet.go
@@ -708,6 +708,12 @@ func (ic *ContainerEngine) QuadletList(ctx context.Context, options entities.Qua
reports = append(reports, &report)
continue
}
+
+ if strings.Contains(serviceName, "@.") {
+ // Template file, skipping
+ continue
+ }
+
partialReports[serviceName] = report
allServiceNames = append(allServiceNames, serviceName)
}I will try to use a different way to query systemd, so that templates could also be included in the listing. |
64918ba to
8194502
Compare
e27140d to
28a5a12
Compare
c20f56e to
9266aa5
Compare
|
[NON-BLOCKING] Packit jobs failed. @containers/packit-build please check. Everyone else, feel free to ignore. |
bd08c84 to
36d7f3c
Compare
| } | ||
| } | ||
|
|
||
| if len(templateServiceNames) != 0 { |
There was a problem hiding this comment.
There can still be running instances of the templates removed, right? I wonder if we should distinguish between the removal of concrete services and templated ones. Because while concrete services are stopped before they are removed, it's not the same for template services, and iiuc the user can't really tell the difference while running podman quadlet rm <concrete_svc> <template_svc>, unless I'm missing something.
There was a problem hiding this comment.
Yes, that is right. I documented it that way
When the argument is uninstantiated template quadlet, this command removes the
template quadlet file (e.g. `templateName@.container`) and the generated systemd
template unit (e.g. `templateName@.service`, unless **--reload-systemd** is set to `false`).
Instances of the systemd template unit (e.g. `templateName@instanceName.service`)
may persist, and can be removed with **systemctl(1)**.
It seemed reasonable to do it this way for the minimal fix of the issue, but there could be a follow up which elaborates on this.
On one hand, perhaps it would be nice to help users to manage instances, but there are plenty of ways how instances can be created:
- from a file which has instance name already -
podman quadlet install templateName@instanceName.container - by creating a symlink to template name in
~/.config/containers/systemd/ DefaultInstancesystemctl --user start- Systemd dependency (
Wantskey for example)
so it could be messy to cover all the cases.
On the other hand, instances of templates could be even considered out of scope, as quadlets are about generating services, and what the services are used for is responsibility of systemd. So from this point of view - my fix is consistent, it removes the .container file and the .service file generated from it for both concrete units and templates.
36d7f3c to
c3ecb25
Compare
|
/packit rebuild-failed |
|
[NON-BLOCKING] Packit jobs failed. @containers/packit-build please check. Everyone else, feel free to ignore. |
|
/packit rebuild-failed |
|
Removing all instances when template is removed could be tricky as but https://0pointer.de/blog/projects/instances.html I'll try to solve it by looking at the |
|
I changed |
|
[NON-BLOCKING] Packit jobs failed. @containers/packit-build please check. Everyone else, feel free to ignore. |
| continue | ||
| } | ||
|
|
||
| if sourcePath == templateQuadletPath { |
There was a problem hiding this comment.
I would consider using filepath.Clean.
| report.UnitName = templateServiceName | ||
|
|
||
| if _, ok := unitFilesFound[templateServiceName]; ok { | ||
| report.Status = "loaded template" |
There was a problem hiding this comment.
I would define Status as constants.
071ffed to
be7265c
Compare
b192bec to
28c1ce4
Compare
Honny1
left a comment
There was a problem hiding this comment.
I didn't check the CI failures, but they seem to be serious. Also, please check the REST API to see if there are any actions for updates.
|
|
||
| // Uninstantiated template units need to be handled separately, because | ||
| // ListUnitsBy* functions do not return anything for templates. | ||
| unitFiles, err := conn.ListUnitFilesByPatternsContext(ctx, []string{}, templateServiceNames) |
There was a problem hiding this comment.
What happens if templateServiceNames is empty? Will ListUnitFilesByPatternsContext list all unitFiles or empty unitFiles?
There was a problem hiding this comment.
templateServiceNames []
NAME UNIT NAME PATH ON DISK STATUS APPLICATION POD
ListUnitFilesByPatternsContext returns units matched by at least one pattern, so empty list of templateServiceNames means that there are no patterns, so nothing will match.
There was a problem hiding this comment.
We don't need to list unit files when templateServiceNames is empty.
| as input and removes all the Quadlets which belongs to that specific application. | ||
|
|
||
| When the argument is uninstantiated template quadlet, this command removes the template quadlet file (e.g. `templateName@.container`) and the generated systemd template unit (e.g. `templateName@.service`). If there are running instances of that systemd template, the command fails if **--force** option is not set, and tries to remove the instances if **--force** option is set. Instances which were not running may persist, and can be removed with **systemctl(1)**. | ||
|
|
There was a problem hiding this comment.
| Flag `--force` stops active instances of the template so removal can proceed. It does not disable or remove instance units (e.g. `foo@bar.service`). Use `systemctl(1)` to disable or reset instances that remain after the template quadlet is removed. |
There was a problem hiding this comment.
I don't know whether this is accurate.
so removal can proceed it is not that the template removal could not proceed with running instances, it's just that user probably does not want to remove definition of something that is running.
disable or reset instances enable/disable does not work because the service is transient or generated. Restart does not work, as systemd does not have anything to reload from. I don't know if there is something reasonable to do with systemctl, so I'm thinking, maybe I should just get rid of the systemctl(1) bit and only say that if --force then stop_instances else fail?
26bb0c4 to
09dd82a
Compare
Fixes: containers#26960 Signed-off-by: Šimon Brauner <sbrauner@redhat.com>
Starting the container from the test didn't work, so I removed that part.
This is just a bugfix, the functionality is the same (just extended to templates), maybe except for the semantics of removing a template, so I addressed that specifically. |
Checklist
Ensure you have completed the following checklist for your pull request to be reviewed:
commits. (
git commit -s). (If needed, usegit commit -s --amend). The author email must matchthe sign-off email address. See CONTRIBUTING.md
for more information.
Fixes: #00000in commit message (if applicable)make validatepr(format/lint checks)Noneif no user-facing changes)Does this PR introduce a user-facing change?