mirror of
https://github.com/containers/podman.git
synced 2025-05-17 15:18:43 +08:00
Quadlet - remove the usage of cid and podid for container and pod files
Signed-off-by: Ygal Blum <ygal.blum@gmail.com>
This commit is contained in:
@ -604,6 +604,9 @@ func generateUnitsInfoMap(units []*parser.UnitFile) map[string]*quadlet.UnitInfo
|
|||||||
case strings.HasSuffix(unit.Filename, ".pod"):
|
case strings.HasSuffix(unit.Filename, ".pod"):
|
||||||
serviceName = quadlet.GetPodServiceName(unit)
|
serviceName = quadlet.GetPodServiceName(unit)
|
||||||
containers = make([]string, 0)
|
containers = make([]string, 0)
|
||||||
|
// Prefill resouceNames for .pod files.
|
||||||
|
// This is requires for referencing the pod from .container files
|
||||||
|
resourceName = quadlet.GetPodResourceName(unit)
|
||||||
default:
|
default:
|
||||||
Logf("Unsupported file type %q", unit.Filename)
|
Logf("Unsupported file type %q", unit.Filename)
|
||||||
continue
|
continue
|
||||||
|
@ -608,16 +608,14 @@ func ConvertContainer(container *parser.UnitFile, isUser bool, unitsInfoMap map[
|
|||||||
// If conmon exited uncleanly it may not have removed the container, so
|
// If conmon exited uncleanly it may not have removed the container, so
|
||||||
// force it, -i makes it ignore non-existing files.
|
// force it, -i makes it ignore non-existing files.
|
||||||
serviceStopCmd := createBasePodmanCommand(container, ContainerGroup)
|
serviceStopCmd := createBasePodmanCommand(container, ContainerGroup)
|
||||||
serviceStopCmd.add("rm", "-v", "-f", "-i", "--cidfile=%t/%N.cid")
|
serviceStopCmd.add("rm", "-v", "-f", "-i", containerName)
|
||||||
service.AddCmdline(ServiceGroup, "ExecStop", serviceStopCmd.Args)
|
service.AddCmdline(ServiceGroup, "ExecStop", serviceStopCmd.Args)
|
||||||
// The ExecStopPost is needed when the main PID (i.e., conmon) gets killed.
|
// The ExecStopPost is needed when the main PID (i.e., conmon) gets killed.
|
||||||
// In that case, ExecStop is not executed but *Post only. If both are
|
// In that case, ExecStop is not executed but *Post only.
|
||||||
// fired in sequence, *Post will exit when detecting that the --cidfile
|
|
||||||
// has already been removed by the previous `rm`..
|
|
||||||
serviceStopCmd.Args[0] = fmt.Sprintf("-%s", serviceStopCmd.Args[0])
|
serviceStopCmd.Args[0] = fmt.Sprintf("-%s", serviceStopCmd.Args[0])
|
||||||
service.AddCmdline(ServiceGroup, "ExecStopPost", serviceStopCmd.Args)
|
service.AddCmdline(ServiceGroup, "ExecStopPost", serviceStopCmd.Args)
|
||||||
|
|
||||||
if err := handleExecReload(container, service, ContainerGroup); err != nil {
|
if err := handleExecReload(container, service, ContainerGroup, containerName); err != nil {
|
||||||
return nil, warnings, err
|
return nil, warnings, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -628,9 +626,6 @@ func ConvertContainer(container *parser.UnitFile, isUser bool, unitsInfoMap map[
|
|||||||
podman.add("--name", containerName)
|
podman.add("--name", containerName)
|
||||||
|
|
||||||
podman.add(
|
podman.add(
|
||||||
// We store the container id so we can clean it up in case of failure
|
|
||||||
"--cidfile=%t/%N.cid",
|
|
||||||
|
|
||||||
// And replace any previous container with the same name, not fail
|
// And replace any previous container with the same name, not fail
|
||||||
"--replace",
|
"--replace",
|
||||||
|
|
||||||
@ -1483,6 +1478,15 @@ func getServiceName(quadletUnitFile *parser.UnitFile, groupName string, defaultE
|
|||||||
return removeExtension(quadletUnitFile.Filename, "", defaultExtraSuffix)
|
return removeExtension(quadletUnitFile.Filename, "", defaultExtraSuffix)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetPodResourceName(podUnit *parser.UnitFile) string {
|
||||||
|
// Derive pod name from unit name (with added prefix), or use user-provided name.
|
||||||
|
podName, ok := podUnit.Lookup(PodGroup, KeyPodName)
|
||||||
|
if !ok || len(podName) == 0 {
|
||||||
|
podName = removeExtension(podUnit.Filename, "systemd-", "")
|
||||||
|
}
|
||||||
|
return podName
|
||||||
|
}
|
||||||
|
|
||||||
func ConvertPod(podUnit *parser.UnitFile, name string, unitsInfoMap map[string]*UnitInfo, isUser bool) (*parser.UnitFile, error, error) {
|
func ConvertPod(podUnit *parser.UnitFile, name string, unitsInfoMap map[string]*UnitInfo, isUser bool) (*parser.UnitFile, error, error) {
|
||||||
var warn, warnings error
|
var warn, warnings error
|
||||||
|
|
||||||
@ -1491,11 +1495,7 @@ func ConvertPod(podUnit *parser.UnitFile, name string, unitsInfoMap map[string]*
|
|||||||
return nil, warnings, err
|
return nil, warnings, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Derive pod name from unit name (with added prefix), or use user-provided name.
|
podName := GetPodResourceName(podUnit)
|
||||||
podName, ok := podUnit.Lookup(PodGroup, KeyPodName)
|
|
||||||
if !ok || len(podName) == 0 {
|
|
||||||
podName = removeExtension(name, "systemd-", "")
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, containerService := range unitInfo.ContainersToStart {
|
for _, containerService := range unitInfo.ContainersToStart {
|
||||||
service.Add(UnitGroup, "Wants", containerService)
|
service.Add(UnitGroup, "Wants", containerService)
|
||||||
@ -1507,24 +1507,24 @@ func ConvertPod(podUnit *parser.UnitFile, name string, unitsInfoMap map[string]*
|
|||||||
}
|
}
|
||||||
|
|
||||||
execStart := createBasePodmanCommand(podUnit, PodGroup)
|
execStart := createBasePodmanCommand(podUnit, PodGroup)
|
||||||
execStart.add("pod", "start", "--pod-id-file=%t/%N.pod-id")
|
execStart.add("pod", "start", podName)
|
||||||
service.AddCmdline(ServiceGroup, "ExecStart", execStart.Args)
|
service.AddCmdline(ServiceGroup, "ExecStart", execStart.Args)
|
||||||
|
|
||||||
execStop := createBasePodmanCommand(podUnit, PodGroup)
|
execStop := createBasePodmanCommand(podUnit, PodGroup)
|
||||||
execStop.add("pod", "stop")
|
execStop.add("pod", "stop")
|
||||||
execStop.add(
|
execStop.add(
|
||||||
"--pod-id-file=%t/%N.pod-id",
|
|
||||||
"--ignore",
|
"--ignore",
|
||||||
"--time=10",
|
"--time=10",
|
||||||
|
podName,
|
||||||
)
|
)
|
||||||
service.AddCmdline(ServiceGroup, "ExecStop", execStop.Args)
|
service.AddCmdline(ServiceGroup, "ExecStop", execStop.Args)
|
||||||
|
|
||||||
execStopPost := createBasePodmanCommand(podUnit, PodGroup)
|
execStopPost := createBasePodmanCommand(podUnit, PodGroup)
|
||||||
execStopPost.add("pod", "rm")
|
execStopPost.add("pod", "rm")
|
||||||
execStopPost.add(
|
execStopPost.add(
|
||||||
"--pod-id-file=%t/%N.pod-id",
|
|
||||||
"--ignore",
|
"--ignore",
|
||||||
"--force",
|
"--force",
|
||||||
|
podName,
|
||||||
)
|
)
|
||||||
service.AddCmdline(ServiceGroup, "ExecStopPost", execStopPost.Args)
|
service.AddCmdline(ServiceGroup, "ExecStopPost", execStopPost.Args)
|
||||||
|
|
||||||
@ -1532,7 +1532,6 @@ func ConvertPod(podUnit *parser.UnitFile, name string, unitsInfoMap map[string]*
|
|||||||
execStartPre.add("pod", "create")
|
execStartPre.add("pod", "create")
|
||||||
execStartPre.add(
|
execStartPre.add(
|
||||||
"--infra-conmon-pidfile=%t/%N.pid",
|
"--infra-conmon-pidfile=%t/%N.pid",
|
||||||
"--pod-id-file=%t/%N.pod-id",
|
|
||||||
"--exit-policy=stop",
|
"--exit-policy=stop",
|
||||||
"--replace",
|
"--replace",
|
||||||
)
|
)
|
||||||
@ -2075,7 +2074,7 @@ func handlePod(quadletUnitFile, serviceUnitFile *parser.UnitFile, groupName stri
|
|||||||
return fmt.Errorf("quadlet pod unit %s does not exist", pod)
|
return fmt.Errorf("quadlet pod unit %s does not exist", pod)
|
||||||
}
|
}
|
||||||
|
|
||||||
podman.add("--pod-id-file", fmt.Sprintf("%%t/%s.pod-id", podInfo.ServiceName))
|
podman.add("--pod", podInfo.ResourceName)
|
||||||
|
|
||||||
podServiceName := podInfo.ServiceFileName()
|
podServiceName := podInfo.ServiceFileName()
|
||||||
serviceUnitFile.Add(UnitGroup, "BindsTo", podServiceName)
|
serviceUnitFile.Add(UnitGroup, "BindsTo", podServiceName)
|
||||||
@ -2146,7 +2145,7 @@ func addDefaultDependencies(service *parser.UnitFile, isUser bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleExecReload(quadletUnitFile, serviceUnitFile *parser.UnitFile, groupName string) error {
|
func handleExecReload(quadletUnitFile, serviceUnitFile *parser.UnitFile, groupName, containerName string) error {
|
||||||
reloadSignal, signalOk := quadletUnitFile.Lookup(groupName, KeyReloadSignal)
|
reloadSignal, signalOk := quadletUnitFile.Lookup(groupName, KeyReloadSignal)
|
||||||
signalOk = signalOk && len(reloadSignal) > 0
|
signalOk = signalOk && len(reloadSignal) > 0
|
||||||
reloadcmd, cmdOk := quadletUnitFile.LookupLastArgs(groupName, KeyReloadCmd)
|
reloadcmd, cmdOk := quadletUnitFile.LookupLastArgs(groupName, KeyReloadCmd)
|
||||||
@ -2162,10 +2161,10 @@ func handleExecReload(quadletUnitFile, serviceUnitFile *parser.UnitFile, groupNa
|
|||||||
|
|
||||||
serviceReloadCmd := createBasePodmanCommand(quadletUnitFile, groupName)
|
serviceReloadCmd := createBasePodmanCommand(quadletUnitFile, groupName)
|
||||||
if cmdOk {
|
if cmdOk {
|
||||||
serviceReloadCmd.add("exec", "--cidfile=%t/%N.cid")
|
serviceReloadCmd.add("exec", containerName)
|
||||||
serviceReloadCmd.add(reloadcmd...)
|
serviceReloadCmd.add(reloadcmd...)
|
||||||
} else {
|
} else {
|
||||||
serviceReloadCmd.add("kill", "--cidfile=%t/%N.cid", "--signal", reloadSignal)
|
serviceReloadCmd.add("kill", "--signal", reloadSignal, containerName)
|
||||||
}
|
}
|
||||||
serviceUnitFile.AddCmdline(ServiceGroup, "ExecReload", serviceReloadCmd.Args)
|
serviceUnitFile.AddCmdline(ServiceGroup, "ExecReload", serviceReloadCmd.Args)
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
## assert-podman-final-args run --name systemd-%N --cidfile=%t/%N.cid --replace --rm --cgroups=split --sdnotify=conmon -d localhost/imagename
|
## assert-podman-final-args run --name systemd-%N --replace --rm --cgroups=split --sdnotify=conmon -d localhost/imagename
|
||||||
|
|
||||||
[Container]
|
[Container]
|
||||||
Image=localhost/imagename
|
Image=localhost/imagename
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
## assert-podman-final-args localhost/imagename
|
## assert-podman-final-args localhost/imagename
|
||||||
## assert-podman-args "--name" "systemd-%N"
|
## assert-podman-args "--name" "systemd-%N"
|
||||||
## assert-podman-args "--cidfile=%t/%N.cid"
|
|
||||||
## assert-podman-args "--rm"
|
## assert-podman-args "--rm"
|
||||||
## assert-podman-args "--replace"
|
## assert-podman-args "--replace"
|
||||||
## assert-podman-args "-d"
|
## assert-podman-args "-d"
|
||||||
@ -12,8 +11,8 @@
|
|||||||
## assert-key-is "Service" "Type" "notify"
|
## assert-key-is "Service" "Type" "notify"
|
||||||
## assert-key-is "Service" "NotifyAccess" "all"
|
## assert-key-is "Service" "NotifyAccess" "all"
|
||||||
## assert-key-is "Service" "SyslogIdentifier" "%N"
|
## assert-key-is "Service" "SyslogIdentifier" "%N"
|
||||||
## assert-key-is-regex "Service" "ExecStopPost" "-[/S].*/podman rm -v -f -i --cidfile=%t/%N.cid"
|
## assert-key-is-regex "Service" "ExecStopPost" "-[/S].*/podman rm -v -f -i systemd-%N"
|
||||||
## assert-key-is-regex "Service" "ExecStop" ".*/podman rm -v -f -i --cidfile=%t/%N.cid"
|
## assert-key-is-regex "Service" "ExecStop" ".*/podman rm -v -f -i systemd-%N"
|
||||||
## assert-key-is "Service" "Environment" "PODMAN_SYSTEMD_UNIT=%n"
|
## assert-key-is "Service" "Environment" "PODMAN_SYSTEMD_UNIT=%n"
|
||||||
## assert-key-is-regex "Unit" "After" "network-online.target|podman-user-wait-network-online.service"
|
## assert-key-is-regex "Unit" "After" "network-online.target|podman-user-wait-network-online.service"
|
||||||
## assert-key-is-regex "Unit" "Wants" "network-online.target|podman-user-wait-network-online.service"
|
## assert-key-is-regex "Unit" "Wants" "network-online.target|podman-user-wait-network-online.service"
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
## assert-key-is Unit RequiresMountsFor "%t/containers"
|
## assert-key-is Unit RequiresMountsFor "%t/containers"
|
||||||
## assert-key-is Service Type forking
|
## assert-key-is Service Type forking
|
||||||
## assert-key-is Service SyslogIdentifier "%N"
|
## assert-key-is Service SyslogIdentifier "%N"
|
||||||
## assert-key-is-regex Service ExecStartPre ".*/podman pod create --infra-conmon-pidfile=%t/%N.pid --pod-id-file=%t/%N.pod-id --exit-policy=stop --replace --infra-name systemd-basic-infra --name systemd-basic"
|
## assert-key-is-regex Service ExecStartPre ".*/podman pod create --infra-conmon-pidfile=%t/%N.pid --exit-policy=stop --replace --infra-name systemd-basic-infra --name systemd-basic"
|
||||||
## assert-key-is-regex Service ExecStart ".*/podman pod start --pod-id-file=%t/%N.pod-id"
|
## assert-key-is-regex Service ExecStart ".*/podman pod start systemd-basic"
|
||||||
## assert-key-is-regex Service ExecStop ".*/podman pod stop --pod-id-file=%t/%N.pod-id --ignore --time=10"
|
## assert-key-is-regex Service ExecStop ".*/podman pod stop --ignore --time=10 systemd-basic"
|
||||||
## assert-key-is-regex Service ExecStopPost ".*/podman pod rm --pod-id-file=%t/%N.pod-id --ignore --force"
|
## assert-key-is-regex Service ExecStopPost ".*/podman pod rm --ignore --force systemd-basic"
|
||||||
|
|
||||||
[Pod]
|
[Pod]
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
## assert-podman-reload-args "exec"
|
## assert-podman-reload-args "exec"
|
||||||
## assert-podman-reload-args "--cidfile=%t/%N.cid"
|
## assert-podman-reload-args "systemd-%N"
|
||||||
## assert-podman-reload-final-args "/some/binary file" "--arg1" "arg 2"
|
## assert-podman-reload-final-args "/some/binary file" "--arg1" "arg 2"
|
||||||
|
|
||||||
[Container]
|
[Container]
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
## assert-podman-reload-args "kill"
|
## assert-podman-reload-args "kill"
|
||||||
## assert-podman-reload-args "--cidfile=%t/%N.cid"
|
## assert-podman-reload-args "systemd-%N"
|
||||||
## assert-podman-reload-args "--signal" "SIGHUP"
|
## assert-podman-reload-args "--signal" "SIGHUP"
|
||||||
|
|
||||||
[Container]
|
[Container]
|
||||||
|
Reference in New Issue
Block a user