Skip to content

Commit fb9e9de

Browse files
Merge pull request #20966 from ygalblum/kube-play-build-private-reg
Kube Play - pass arguments to build
2 parents 9c16f1b + d026ccf commit fb9e9de

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

cmd/podman/kube/play.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"strings"
1313
"syscall"
1414

15+
buildahParse "github.com/containers/buildah/pkg/parse"
1516
"github.com/containers/common/pkg/auth"
1617
"github.com/containers/common/pkg/completion"
1718
"github.com/containers/image/v5/types"
@@ -219,6 +220,13 @@ func play(cmd *cobra.Command, args []string) error {
219220
}
220221
if cmd.Flags().Changed("build") {
221222
playOptions.Build = types.NewOptionalBool(playOptions.BuildCLI)
223+
if playOptions.Build == types.OptionalBoolTrue {
224+
systemContext, err := buildahParse.SystemContextFromOptions(cmd)
225+
if err != nil {
226+
return err
227+
}
228+
playOptions.SystemContext = systemContext
229+
}
222230
}
223231
if cmd.Flags().Changed("authfile") {
224232
if err := auth.CheckAuthFile(playOptions.Authfile); err != nil {

pkg/domain/entities/play.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ type PlayKubeOptions struct {
7575
PublishAllPorts bool
7676
// Wait - indicates whether to return after having created the pods
7777
Wait bool
78+
// SystemContext - used when building the image
79+
SystemContext *types.SystemContext
7880
}
7981

8082
// PlayKubePod represents a single pod and associated containers created by play kube

pkg/domain/infra/abi/play.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,7 @@ func (ic *ContainerEngine) getImageAndLabelInfo(ctx context.Context, cwd string,
10251025
}
10261026
buildOpts.Isolation = isolation
10271027
buildOpts.CommonBuildOpts = commonOpts
1028+
buildOpts.SystemContext = options.SystemContext
10281029
buildOpts.Output = container.Image
10291030
buildOpts.ContextDirectory = filepath.Dir(buildFile)
10301031
buildOpts.ReportWriter = writer

test/system/700-play.bats

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
load helpers
77
load helpers.network
8+
load helpers.registry
89

910
# This is a long ugly way to clean up pods and remove the pause image
1011
function teardown() {
@@ -934,3 +935,46 @@ spec:
934935
run_podman pod rm -a
935936
run_podman rm -a
936937
}
938+
939+
@test "podman play --build private registry" {
940+
skip_if_remote "--build is not supported in context remote"
941+
942+
local registry=localhost:${PODMAN_LOGIN_REGISTRY_PORT}
943+
local from_image=$registry/quadlet_image_test:$(random_string)
944+
local authfile=$PODMAN_TMPDIR/authfile.json
945+
946+
mkdir -p $PODMAN_TMPDIR/userimage
947+
cat > $PODMAN_TMPDIR/userimage/Containerfile << _EOF
948+
from $from_image
949+
USER bin
950+
_EOF
951+
952+
# Start the registry and populate the authfile that we can use for the test.
953+
start_registry
954+
run_podman login --authfile=$authfile \
955+
--tls-verify=false \
956+
--username ${PODMAN_LOGIN_USER} \
957+
--password ${PODMAN_LOGIN_PASS} \
958+
$registry
959+
960+
# Push the test image to the registry
961+
run_podman image tag $IMAGE $from_image
962+
run_podman image push --tls-verify=false --authfile=$authfile $from_image
963+
964+
# Remove the local image to make sure it will be pulled again
965+
run_podman image rm --ignore $from_image
966+
967+
_write_test_yaml command=id image=userimage
968+
run_podman 125 play kube --build --start=false $PODMAN_TMPDIR/test.yaml
969+
assert "$output" "=~" \
970+
"Error: short-name resolution enforced but cannot prompt without a TTY|Resolving \"userimage\" using unqualified-search registries" \
971+
"The error message does match any of the expected ones"
972+
973+
run_podman play kube --replace --context-dir=$PODMAN_TMPDIR --tls-verify=false --authfile=$authfile --build --start=false $PODMAN_TMPDIR/test.yaml
974+
run_podman inspect --format "{{ .Config.User }}" test_pod-test
975+
is "$output" bin "expect container within pod to run as the bin user"
976+
977+
run_podman stop -a -t 0
978+
run_podman pod rm -t 0 -f test_pod
979+
run_podman rmi -f userimage:latest $from_image
980+
}

0 commit comments

Comments
 (0)