Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kube Play - set ReportWriter when building an image #20889

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/domain/infra/abi/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
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 @@ -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