Kube Play - set ReportWriter when building an image

Add test for a specific crash
Update play build test to expect message in stderr

Signed-off-by: Ygal Blum <ygal.blum@gmail.com>
This commit is contained in:
Ygal Blum
2023-12-03 11:25:29 +02:00
parent bc124dd13f
commit a943be7e8e
3 changed files with 85 additions and 4 deletions

View File

@ -1023,6 +1023,7 @@ func (ic *ContainerEngine) getImageAndLabelInfo(ctx context.Context, cwd string,
buildOpts.CommonBuildOpts = commonOpts
buildOpts.Output = container.Image
buildOpts.ContextDirectory = filepath.Dir(buildFile)
buildOpts.ReportWriter = writer
if _, _, err := ic.Libpod.Build(ctx, *buildOpts, []string{buildFile}...); err != nil {
return nil, nil, err
}

View File

@ -12,6 +12,7 @@ import (
. "github.com/containers/podman/v4/test/utils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)
var _ = Describe("Podman play kube with build", func() {
@ -85,7 +86,10 @@ LABEL marge=mom
session := podmanTest.Podman([]string{"kube", "play", "top.yaml"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session).Should(Exit(0))
stdErrString := session.ErrorToString()
Expect(stdErrString).To(ContainSubstring("Getting image source signatures"))
Expect(stdErrString).To(ContainSubstring("Writing manifest to image destination"))
exists := podmanTest.Podman([]string{"image", "exists", "foobar"})
exists.WaitWithDefaultTimeout()
@ -122,7 +126,10 @@ LABEL marge=mom
session := podmanTest.Podman([]string{"kube", "play", "top.yaml"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session).Should(Exit(0))
stdErrString := session.ErrorToString()
Expect(stdErrString).To(ContainSubstring("Getting image source signatures"))
Expect(stdErrString).To(ContainSubstring("Writing manifest to image destination"))
exists := podmanTest.Podman([]string{"image", "exists", "foobar"})
exists.WaitWithDefaultTimeout()
@ -266,7 +273,10 @@ LABEL marge=mom
session := podmanTest.Podman([]string{"kube", "play", "--build", "top.yaml"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session).Should(Exit(0))
stdErrString := session.ErrorToString()
Expect(stdErrString).To(ContainSubstring("Getting image source signatures"))
Expect(stdErrString).To(ContainSubstring("Writing manifest to image destination"))
inspect := podmanTest.Podman([]string{"container", "inspect", "top_pod-foobar"})
inspect.WaitWithDefaultTimeout()
@ -351,7 +361,10 @@ echo GOT-HERE
session := podmanTest.Podman([]string{"kube", "play", "echo.yaml"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session).Should(Exit(0))
stdErrString := session.ErrorToString()
Expect(stdErrString).To(ContainSubstring("Getting image source signatures"))
Expect(stdErrString).To(ContainSubstring("Writing manifest to image destination"))
cid := "echo_pod-foobar"
wait := podmanTest.Podman([]string{"wait", cid})

View File

@ -1470,4 +1470,71 @@ EOF
run_podman rmi $(pause_image)
}
# This test reproduces https://github.com/containers/podman/issues/20432
# In order to reproduce the issue, the image in the FROM must no be available locally
# and must not have a tag. The first forces Pull and the second the resolution where the crash occurs
# Using a local registry does not work since kube play does not pass the autofile and tls-verify flags to the build
@test "quadlet - kube build from unavailable image with no tag" {
local quadlet_tmpdir=$PODMAN_TMPDIR/quadlets
local untagged_image=quay.io/libpod/busybox
local built_image=test_image
local yaml_dir=$quadlet_tmpdir/$built_image
local build_dir=$yaml_dir/$built_image
# Use the same directory for all quadlet files to make sure later steps access previous ones
mkdir -p $build_dir
container_file_path=$build_dir/Containerfile
cat >$container_file_path << EOF
FROM $untagged_image
EOF
# Create the YAMl file
pod_name="test_pod"
container_name="test"
yaml_source="$yaml_dir/build_$(random_string).yaml"
cat >$yaml_source <<EOF
apiVersion: v1
kind: Pod
metadata:
labels:
app: test
name: $pod_name
spec:
containers:
- command:
- "sh"
args:
- "-c"
- "echo STARTED CONTAINER; sleep inf"
image: $built_image
name: $container_name
EOF
# Create the Quadlet file
local quadlet_file=$quadlet_tmpdir/build_$(random_string).kube
cat > $quadlet_file <<EOF
[Kube]
Yaml=${yaml_source}
PodmanArgs=--build
SetWorkingDirectory=yaml
EOF
# Make sure the tagged image is not locally available
run_podman rmi -i $untagged_image:latest
run_quadlet "$quadlet_file"
service_setup $QUADLET_SERVICE_NAME
# Ensure we have output.
wait_for_output "STARTED CONTAINER" $pod_name-$container_name
run_podman container inspect --format "{{.State.Status}}" test_pod-test
is "$output" "running" "container should be started by systemd and hence be running"
service_cleanup $QUADLET_SERVICE_NAME inactive
run_podman rmi $untagged_image:latest $built_image $(pause_image)
}
# vim: filetype=sh