mirror of
https://github.com/containers/podman.git
synced 2025-10-13 17:26:13 +08:00
Add key to control if a container can get started by its pod
By default today, the container is always started if its pod is also started. This prevents to create custom with systemd where containers in a pod could be started through their `[Install]` section. We add a key `StartWithPod=`, enabled by default, that enables one to disable that behavior. This prevents the pod service from changing the state of the container service. Fixes #24401 Signed-off-by: Farya L. Maerten <me@ltow.me>
This commit is contained in:
@ -154,6 +154,7 @@ const (
|
||||
KeyServiceName = "ServiceName"
|
||||
KeySetWorkingDirectory = "SetWorkingDirectory"
|
||||
KeyShmSize = "ShmSize"
|
||||
KeyStartWithPod = "StartWithPod"
|
||||
KeyStopSignal = "StopSignal"
|
||||
KeyStopTimeout = "StopTimeout"
|
||||
KeySubGIDMap = "SubGIDMap"
|
||||
@ -185,8 +186,8 @@ type UnitInfo struct {
|
||||
ResourceName string
|
||||
|
||||
// For .pod units
|
||||
// List of containers in a pod
|
||||
Containers []string
|
||||
// List of containers to start with the pod
|
||||
ContainersToStart []string
|
||||
}
|
||||
|
||||
var (
|
||||
@ -267,6 +268,7 @@ var (
|
||||
KeyServiceName: true,
|
||||
KeyShmSize: true,
|
||||
KeyStopSignal: true,
|
||||
KeyStartWithPod: true,
|
||||
KeyStopTimeout: true,
|
||||
KeySubGIDMap: true,
|
||||
KeySubUIDMap: true,
|
||||
@ -1563,7 +1565,7 @@ func ConvertPod(podUnit *parser.UnitFile, name string, unitsInfoMap map[string]*
|
||||
// Need the containers filesystem mounted to start podman
|
||||
service.Add(UnitGroup, "RequiresMountsFor", "%t/containers")
|
||||
|
||||
for _, containerService := range unitInfo.Containers {
|
||||
for _, containerService := range unitInfo.ContainersToStart {
|
||||
service.Add(UnitGroup, "Wants", containerService)
|
||||
service.Add(UnitGroup, "Before", containerService)
|
||||
}
|
||||
@ -2133,7 +2135,11 @@ func handlePod(quadletUnitFile, serviceUnitFile *parser.UnitFile, groupName stri
|
||||
serviceUnitFile.Add(UnitGroup, "BindsTo", podServiceName)
|
||||
serviceUnitFile.Add(UnitGroup, "After", podServiceName)
|
||||
|
||||
podInfo.Containers = append(podInfo.Containers, serviceUnitFile.Filename)
|
||||
// If we want to start the container with the pod, we add it to this list.
|
||||
// This creates corresponding Wants=/Before= statements in the pod service.
|
||||
if quadletUnitFile.LookupBooleanWithDefault(groupName, KeyStartWithPod, true) {
|
||||
podInfo.ContainersToStart = append(podInfo.ContainersToStart, serviceUnitFile.Filename)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user