mirror of
https://github.com/containers/podman.git
synced 2025-06-24 19:42:56 +08:00
inspect, image: alias .Config.HealthCheck to .HealthCheck for compatibility
Support inspecting image healthcheck using docker supported `.Config.HealthCheck` by aliasing field to `.HealthCheck` Now supports ```Console podman image inspect -f "{{.Config.Healthcheck}}" imagename ``` Closes: https://github.com/containers/podman/issues/14661 Signed-off-by: Aditya R <arajan@redhat.com>
This commit is contained in:
@ -201,7 +201,7 @@ func (i *inspector) inspect(namesOrIDs []string) error {
|
|||||||
err = printJSON(data)
|
err = printJSON(data)
|
||||||
default:
|
default:
|
||||||
// Landing here implies user has given a custom --format
|
// Landing here implies user has given a custom --format
|
||||||
row := inspectNormalize(i.options.Format)
|
row := inspectNormalize(i.options.Format, tmpType)
|
||||||
row = report.NormalizeFormat(row)
|
row = report.NormalizeFormat(row)
|
||||||
row = report.EnforceRange(row)
|
row = report.EnforceRange(row)
|
||||||
err = printTmpl(tmpType, row, data)
|
err = printTmpl(tmpType, row, data)
|
||||||
@ -300,7 +300,7 @@ func (i *inspector) inspectAll(ctx context.Context, namesOrIDs []string) ([]inte
|
|||||||
return data, allErrs, nil
|
return data, allErrs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func inspectNormalize(row string) string {
|
func inspectNormalize(row string, inspectType string) string {
|
||||||
m := regexp.MustCompile(`{{\s*\.Id\s*}}`)
|
m := regexp.MustCompile(`{{\s*\.Id\s*}}`)
|
||||||
row = m.ReplaceAllString(row, "{{.ID}}")
|
row = m.ReplaceAllString(row, "{{.ID}}")
|
||||||
|
|
||||||
@ -309,5 +309,18 @@ func inspectNormalize(row string) string {
|
|||||||
".Dst", ".Destination",
|
".Dst", ".Destination",
|
||||||
".ImageID", ".Image",
|
".ImageID", ".Image",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// If inspect type is `image` we need to replace
|
||||||
|
// certain additional fields like `.Config.HealthCheck`
|
||||||
|
// but don't want to replace them for other inspect types.
|
||||||
|
if inspectType == common.ImageType {
|
||||||
|
r = strings.NewReplacer(
|
||||||
|
".Src", ".Source",
|
||||||
|
".Dst", ".Destination",
|
||||||
|
".ImageID", ".Image",
|
||||||
|
".Config.Healthcheck", ".HealthCheck",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return r.Replace(row)
|
return r.Replace(row)
|
||||||
}
|
}
|
||||||
|
@ -317,6 +317,12 @@ HEALTHCHECK CMD ls -l / 2>&1`, ALPINE)
|
|||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session).Should(Exit(0))
|
Expect(session).Should(Exit(0))
|
||||||
|
|
||||||
|
// Check if image inspect contains CMD-SHELL generated by healthcheck.
|
||||||
|
session = podmanTest.Podman([]string{"image", "inspect", "--format", "{{.Config.Healthcheck}}", "test"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session).Should(Exit(0))
|
||||||
|
Expect(session.OutputToString()).To(ContainSubstring("CMD-SHELL"))
|
||||||
|
|
||||||
run := podmanTest.Podman([]string{"run", "-dt", "--name", "hctest", "test", "ls"})
|
run := podmanTest.Podman([]string{"run", "-dt", "--name", "hctest", "test", "ls"})
|
||||||
run.WaitWithDefaultTimeout()
|
run.WaitWithDefaultTimeout()
|
||||||
Expect(run).Should(Exit(0))
|
Expect(run).Should(Exit(0))
|
||||||
|
Reference in New Issue
Block a user