Merge pull request #17588 from ygalblum/quadlet-logdriver

Quadlet: Add support for LogDriver key in container and kube units
This commit is contained in:
OpenShift Merge Robot
2023-02-21 16:24:03 +01:00
committed by GitHub
5 changed files with 46 additions and 6 deletions

View File

@ -88,6 +88,7 @@ Valid options for `[Container]` are listed below:
| Group=1234 | --user UID:1234 |
| Image=ubi8 | Image specification - ubi8 |
| Label="YXZ" | --label "XYZ" |
| LogDriver=journald | --log-driver journald |
| Network=host | --net host |
| NoNewPrivileges=true | --security-opt no-new-privileges |
| Rootfs=/var/lib/rootfs | --rootfs /var/lib/rootfs |
@ -209,6 +210,13 @@ similar to `Environment`.
This key can be listed multiple times.
### `LogDriver=`
Set the log-driver Podman should use when running the container.
Equivalent to the Podman `--log-driver` option.
The default value is `passthrough`.
### `Network=`
Specify a custom network for the container. This has the same format as the `--network` option
@ -385,6 +393,7 @@ Valid options for `[Kube]` are listed below:
| **[Kube] options** | **podman kube play equivalent** |
| ----------------- | ------------------ |
| ConfigMap=/tmp/config.map | --config-map /tmp/config.map |
| LogDriver=journald | --log-driver journald |
| Network=host | --net host |
| PublishPort=59-60 | --publish=59-60 |
| RemapGid=keep-id | --group-add keep-id |
@ -403,6 +412,13 @@ it may be absolute or relative to the location of the unit file.
This key may be used multiple times
### `LogDriver=`
Set the log-driver Podman should use when running the container.
Equivalent to the Podman `--log-driver` option.
The default value is `passthrough`.
### `Network=`
Specify a custom network for the container. This has the same format as the `--network` option

View File

@ -27,6 +27,9 @@ const (
XKubeGroup = "X-Kube"
XNetworkGroup = "X-Network"
XVolumeGroup = "X-Volume"
// Use passthough as the default log driver to output to Journal
defaultLogDriver = "passthrough"
)
// All the supported quadlet keys
@ -47,6 +50,7 @@ const (
KeyGroup = "Group"
KeyImage = "Image"
KeyLabel = "Label"
KeyLogDriver = "LogDriver"
KeyNetwork = "Network"
KeyNetworkDisableDNS = "DisableDNS"
KeyNetworkDriver = "Driver"
@ -101,6 +105,7 @@ var (
KeyGroup: true,
KeyImage: true,
KeyLabel: true,
KeyLogDriver: true,
KeyNetwork: true,
KeyNoNewPrivileges: true,
KeyNotify: true,
@ -153,6 +158,7 @@ var (
// Supported keys in "Kube" group
supportedKubeKeys = map[string]bool{
KeyConfigMap: true,
KeyLogDriver: true,
KeyNetwork: true,
KeyPublishPort: true,
KeyRemapGID: true,
@ -309,11 +315,10 @@ func ConvertContainer(container *parser.UnitFile, isUser bool) (*parser.UnitFile
// On clean shutdown, remove container
"--rm",
// But we still want output to the journal, so use the log driver.
"--log-driver", "passthrough",
)
handleLogDriver(container, ContainerGroup, podman)
// We use crun as the runtime and delegated groups to it
service.Add(ServiceGroup, "Delegate", "yes")
podman.add(
@ -793,11 +798,10 @@ func ConvertKube(kube *parser.UnitFile, isUser bool) (*parser.UnitFile, error) {
// Use a service container
"--service-container=true",
// We want output to the journal, so use the log driver.
"--log-driver", "passthrough",
)
handleLogDriver(kube, KubeGroup, execStart)
if err := handleUserRemap(kube, KubeGroup, execStart, isUser, false); err != nil {
return nil, err
}
@ -982,3 +986,11 @@ func handlePublishPorts(unitFile *parser.UnitFile, groupName string, podman *Pod
return nil
}
func handleLogDriver(unitFile *parser.UnitFile, groupName string, podman *PodmanCmdline) {
logDriver, found := unitFile.Lookup(groupName, KeyLogDriver)
if !found {
logDriver = defaultLogDriver
}
podman.add("--log-driver", logDriver)
}

View File

@ -0,0 +1,5 @@
## assert-podman-args "--log-driver" "journald"
[Container]
Image=localhost/imagename
LogDriver=journald

View File

@ -0,0 +1,5 @@
## assert-podman-args "--log-driver" "journald"
[Kube]
Yaml=deployment.yml
LogDriver=journald

View File

@ -483,6 +483,7 @@ var _ = Describe("quadlet system generator", func() {
Entry("env-host.container", "env-host.container"),
Entry("env-host-false.container", "env-host-false.container"),
Entry("secrets.container", "secrets.container"),
Entry("logdriver.container", "logdriver.container"),
Entry("basic.volume", "basic.volume"),
Entry("label.volume", "label.volume"),
@ -500,6 +501,7 @@ var _ = Describe("quadlet system generator", func() {
Entry("Kube - ConfigMap", "configmap.kube"),
Entry("Kube - Publish IPv4 ports", "ports.kube"),
Entry("Kube - Publish IPv6 ports", "ports_ipv6.kube"),
Entry("Kube - Logdriver", "logdriver.kube"),
Entry("Network - Basic", "basic.network"),
Entry("Network - Label", "label.network"),