Merge pull request #29818 from BartSimpson001/feature/29811-init-container-inspect

inspect: expose init container information
This commit is contained in:
Danish Prakash 2026-09-24 00:37:34 +05:30 • committed by GitHub
commit 7b76d74080
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 28 additions and 0 deletions

View file

@ -40,7 +40,9 @@ Valid placeholders for the Go template are listed below:
| .Image | Container image ID (64-char hash) |
| .ImageDigest | Container image digest (sha256:+64-char hash) |
| .ImageName | Container image name (string) |
| .InitContainerType | Type of init container if applicable (string) |
| .IsInfra | Is this an infra container? (string: true/false) |
| .IsInitCtr | Is this an init container? (string: true/false) |
| .IsService | Is this a service container? (string: true/false) |
| .KubeExitCodePropagation | Kube exit-code propagation (string) |
| .LockNumber | Number of the container's Libpod lock |

View file

@ -168,6 +168,8 @@ func (c *Container) getContainerInspectData(size bool, driverData *define.Driver
Dependencies: c.Dependencies(),
IsInfra: c.IsInfra(),
IsService: c.IsService(),
IsInitCtr: c.IsInitCtr(),
InitContainerType: c.config.InitContainerType,
KubeExitCodePropagation: config.KubeExitCodePropagation.String(),
LockNumber: c.lock.ID(),
UseImageHosts: c.config.UseImageHosts,

View file

@ -807,6 +807,8 @@ type InspectContainerData struct {
Namespace string `json:"Namespace"`
IsInfra bool `json:"IsInfra"`
IsService bool `json:"IsService"`
IsInitCtr bool `json:"IsInitCtr"`
InitContainerType string `json:"InitContainerType,omitempty"`
KubeExitCodePropagation string `json:"KubeExitCodePropagation"`
LockNumber uint32 `json:"lockNumber"`
Config *InspectContainerConfig `json:"Config"`

View file

@ -141,6 +141,28 @@ var _ = Describe("Podman container inspect", func() {
Expect(data[0].Config.Env).To(ContainElement(Equal(secretName + "=*******")))
})
It("podman inspect identifies init container", func() {
podName := "test-init-pod"
initCtrName := "test-init-ctr"
normalCtrName := "test-normal-ctr"
podmanTest.PodmanExitCleanly("pod", "create", "--name", podName)
podmanTest.PodmanExitCleanly("create", "--pod", podName, "--init-ctr=always", "--name", initCtrName, ALPINE, "echo", "init")
podmanTest.PodmanExitCleanly("create", "--pod", podName, "--name", normalCtrName, ALPINE, "top")
initData := podmanTest.InspectContainer(initCtrName)
Expect(initData).To(HaveLen(1))
Expect(initData[0].IsInitCtr).To(BeTrue())
Expect(initData[0].InitContainerType).To(Equal("always"))
normalData := podmanTest.InspectContainer(normalCtrName)
Expect(normalData).To(HaveLen(1))
Expect(normalData[0].IsInitCtr).To(BeFalse())
Expect(normalData[0].InitContainerType).To(BeEmpty())
})
It("podman inspect NetworkSettings DNSNames and Aliases", func() {
netName := "dnstest"
session := podmanTest.Podman([]string{"network", "create", netName})