Merge pull request #20966 from ygalblum/kube-play-build-private-reg

Kube Play - pass arguments to build
This commit is contained in:
openshift-merge-bot[bot] 2023-12-14 20:33:10 +00:00 committed by GitHub
commit fb9e9de1ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 55 additions and 0 deletions

View File

@ -12,6 +12,7 @@ import (
"strings" "strings"
"syscall" "syscall"
buildahParse "github.com/containers/buildah/pkg/parse"
"github.com/containers/common/pkg/auth" "github.com/containers/common/pkg/auth"
"github.com/containers/common/pkg/completion" "github.com/containers/common/pkg/completion"
"github.com/containers/image/v5/types" "github.com/containers/image/v5/types"
@ -219,6 +220,13 @@ func play(cmd *cobra.Command, args []string) error {
} }
if cmd.Flags().Changed("build") { if cmd.Flags().Changed("build") {
playOptions.Build = types.NewOptionalBool(playOptions.BuildCLI) playOptions.Build = types.NewOptionalBool(playOptions.BuildCLI)
if playOptions.Build == types.OptionalBoolTrue {
systemContext, err := buildahParse.SystemContextFromOptions(cmd)
if err != nil {
return err
}
playOptions.SystemContext = systemContext
}
} }
if cmd.Flags().Changed("authfile") { if cmd.Flags().Changed("authfile") {
if err := auth.CheckAuthFile(playOptions.Authfile); err != nil { if err := auth.CheckAuthFile(playOptions.Authfile); err != nil {

View File

@ -75,6 +75,8 @@ type PlayKubeOptions struct {
PublishAllPorts bool PublishAllPorts bool
// Wait - indicates whether to return after having created the pods // Wait - indicates whether to return after having created the pods
Wait bool Wait bool
// SystemContext - used when building the image
SystemContext *types.SystemContext
} }
// PlayKubePod represents a single pod and associated containers created by play kube // PlayKubePod represents a single pod and associated containers created by play kube

View File

@ -1025,6 +1025,7 @@ func (ic *ContainerEngine) getImageAndLabelInfo(ctx context.Context, cwd string,
} }
buildOpts.Isolation = isolation buildOpts.Isolation = isolation
buildOpts.CommonBuildOpts = commonOpts buildOpts.CommonBuildOpts = commonOpts
buildOpts.SystemContext = options.SystemContext
buildOpts.Output = container.Image buildOpts.Output = container.Image
buildOpts.ContextDirectory = filepath.Dir(buildFile) buildOpts.ContextDirectory = filepath.Dir(buildFile)
buildOpts.ReportWriter = writer buildOpts.ReportWriter = writer

View File

@ -5,6 +5,7 @@
load helpers load helpers
load helpers.network load helpers.network
load helpers.registry
# This is a long ugly way to clean up pods and remove the pause image # This is a long ugly way to clean up pods and remove the pause image
function teardown() { function teardown() {
@ -934,3 +935,46 @@ spec:
run_podman pod rm -a run_podman pod rm -a
run_podman rm -a run_podman rm -a
} }
@test "podman play --build private registry" {
skip_if_remote "--build is not supported in context remote"
local registry=localhost:${PODMAN_LOGIN_REGISTRY_PORT}
local from_image=$registry/quadlet_image_test:$(random_string)
local authfile=$PODMAN_TMPDIR/authfile.json
mkdir -p $PODMAN_TMPDIR/userimage
cat > $PODMAN_TMPDIR/userimage/Containerfile << _EOF
from $from_image
USER bin
_EOF
# Start the registry and populate the authfile that we can use for the test.
start_registry
run_podman login --authfile=$authfile \
--tls-verify=false \
--username ${PODMAN_LOGIN_USER} \
--password ${PODMAN_LOGIN_PASS} \
$registry
# Push the test image to the registry
run_podman image tag $IMAGE $from_image
run_podman image push --tls-verify=false --authfile=$authfile $from_image
# Remove the local image to make sure it will be pulled again
run_podman image rm --ignore $from_image
_write_test_yaml command=id image=userimage
run_podman 125 play kube --build --start=false $PODMAN_TMPDIR/test.yaml
assert "$output" "=~" \
"Error: short-name resolution enforced but cannot prompt without a TTY|Resolving \"userimage\" using unqualified-search registries" \
"The error message does match any of the expected ones"
run_podman play kube --replace --context-dir=$PODMAN_TMPDIR --tls-verify=false --authfile=$authfile --build --start=false $PODMAN_TMPDIR/test.yaml
run_podman inspect --format "{{ .Config.User }}" test_pod-test
is "$output" bin "expect container within pod to run as the bin user"
run_podman stop -a -t 0
run_podman pod rm -t 0 -f test_pod
run_podman rmi -f userimage:latest $from_image
}