Skip to content

Commit

Permalink
Merge pull request #20889 from ygalblum/quadlet-build-crash
Browse files Browse the repository at this point in the history
Kube Play - set ReportWriter when building an image
  • Loading branch information
openshift-merge-bot[bot] authored Dec 5, 2023
2 parents e8f3098 + a943be7 commit 6efebb3
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 4 deletions.
1 change: 1 addition & 0 deletions pkg/domain/infra/abi/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,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
}
Expand Down
21 changes: 17 additions & 4 deletions test/e2e/play_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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})
Expand Down
67 changes: 67 additions & 0 deletions test/system/252-quadlet.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1467,4 +1467,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

0 comments on commit 6efebb3

Please sign in to comment.