Merge pull request #8039 from zhangguanzhang/runlabel-panic

Fix panic when runlabel is missing
This commit is contained in:
OpenShift Merge Robot
2020-10-16 16:10:02 -04:00
committed by GitHub
2 changed files with 7 additions and 1 deletions

View File

@ -28,6 +28,9 @@ func (ic *ContainerEngine) ContainerRunlabel(ctx context.Context, label string,
if err != nil {
return err
}
if runlabel == "" {
return errors.Errorf("cannot find the value of label: %s in image: %s", label, imageRef)
}
cmd, env, err := generateRunlabelCommand(runlabel, img, args, options)
if err != nil {

View File

@ -88,12 +88,15 @@ var _ = Describe("podman container runlabel", func() {
result := podmanTest.Podman([]string{"container", "runlabel", "RUN", ALPINE})
result.WaitWithDefaultTimeout()
Expect(result).To(ExitWithError())
// should not panic when label missing the value or don't have the label
Expect(result.LineInOutputContains("panic")).NotTo(BeTrue())
})
It("podman container runlabel bogus label in remote image should result in non-zero exit", func() {
result := podmanTest.Podman([]string{"container", "runlabel", "RUN", "docker.io/library/ubuntu:latest"})
result.WaitWithDefaultTimeout()
Expect(result).To(ExitWithError())
// should not panic when label missing the value or don't have the label
Expect(result.LineInOutputContains("panic")).NotTo(BeTrue())
})
It("podman container runlabel global options", func() {