Skip to content

Commit

Permalink
Merge pull request #19917 from afbjorklund/unix-url
Browse files Browse the repository at this point in the history
Use url with scheme and path for the unix address
  • Loading branch information
openshift-merge-robot authored Sep 18, 2023
2 parents d41047c + 6f4f941 commit 5be2357
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ remotesystem:
rc=0;\
if timeout -v 1 true; then \
SOCK_FILE=$(shell mktemp --dry-run --tmpdir podman_tmp_XXXX);\
export PODMAN_SOCKET=unix:$$SOCK_FILE; \
export PODMAN_SOCKET=unix://$$SOCK_FILE; \
./bin/podman system service --timeout=0 $$PODMAN_SOCKET > $(if $(PODMAN_SERVER_LOG),$(PODMAN_SERVER_LOG),/dev/null) 2>&1 & \
retry=5;\
while [ $$retry -ge 0 ]; do\
Expand Down
6 changes: 3 additions & 3 deletions cmd/podman/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"github.com/spf13/cobra"
)

// DefaultRootAPIAddress is the default address of the REST socket with unix: prefix
const DefaultRootAPIAddress = "unix:" + DefaultRootAPIPath
// DefaultRootAPIAddress is the default path of the REST socket with unix:// prefix
const DefaultRootAPIAddress = "unix://" + DefaultRootAPIPath

type CliCommand struct {
Command *cobra.Command
Expand Down Expand Up @@ -104,7 +104,7 @@ func DefaultAPIAddress() string {
logrus.Warnf("Failed to get rootless runtime dir for DefaultAPIAddress: %s", err)
return DefaultRootAPIAddress
}
return "unix:" + filepath.Join(xdg, "podman", "podman.sock")
return "unix://" + filepath.Join(xdg, "podman", "podman.sock")
}
return DefaultRootAPIAddress
}
2 changes: 1 addition & 1 deletion cmd/podman/system/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func resolveAPIURI(uri []string) (string, error) {
if err := os.MkdirAll(filepath.Dir(socketPath), 0700); err != nil {
return "", err
}
return "unix:" + socketPath, nil
return "unix://" + socketPath, nil
default:
if err := os.MkdirAll(filepath.Dir(registry.DefaultRootAPIPath), 0700); err != nil {
return "", err
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/system/service_abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func restService(flags *pflag.FlagSet, cfg *entities.PodmanConfig, opts entities
return fmt.Errorf("unable to create socket %v: %w", host, err)
}
default:
return fmt.Errorf("API Service endpoint scheme %q is not supported. Try tcp://%s or unix:/%s", uri.Scheme, opts.URI, opts.URI)
return fmt.Errorf("API Service endpoint scheme %q is not supported. Try tcp://%s or unix://%s", uri.Scheme, opts.URI, opts.URI)
}
libpodRuntime.SetRemoteURI(uri.String())
}
Expand Down
6 changes: 3 additions & 3 deletions hack/podman-socat
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,16 @@ PODMAN_HOST="${TMPDIR}/podman/podman-socat.sock"
SOCAT_HOST="${TMPDIR}/podman/podman.sock"

cat <<-EOT
Podman service running at unix:$SOCAT_HOST
Podman service running at unix://$SOCAT_HOST
See /tmp/podman-socat.log for API stream capture
See /tmp/podman-service.log for service logging
usage: sudo bin/podman-remote --url unix:$SOCAT_HOST images
usage: sudo bin/podman-remote --url unix://$SOCAT_HOST images
^C to exit
EOT

$PODMAN system service --timeout=0 "unix:$PODMAN_HOST" >/tmp/podman-service.log 2>&1 &
$PODMAN system service --timeout=0 "unix://$PODMAN_HOST" >/tmp/podman-service.log 2>&1 &
REAP_PIDS=$!

socat -v "UNIX-LISTEN:$SOCAT_HOST",fork,reuseaddr,unlink-early "UNIX-CONNECT:$PODMAN_HOST" >/tmp/podman-socat.log 2>&1
2 changes: 1 addition & 1 deletion test/e2e/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ func PodmanTestCreateUtil(tempDir string, remote bool) *PodmanTestIntegration {
if err == nil {
lockFile.Close()
p.RemoteSocketLock = lockPath
p.RemoteSocket = fmt.Sprintf("unix:%s-%s.sock", pathPrefix, uuid)
p.RemoteSocket = fmt.Sprintf("unix://%s-%s.sock", pathPrefix, uuid)
break
}
tries++
Expand Down
18 changes: 16 additions & 2 deletions test/system/251-system-service.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,24 @@ function teardown() {
@test "podman system service <bad_scheme_uri> returns error" {
skip_if_remote "podman system service unavailable over remote"
run_podman 125 system service localhost:9292
is "$output" "Error: API Service endpoint scheme \"localhost\" is not supported. Try tcp://localhost:9292 or unix:/localhost:9292"
is "$output" "Error: API Service endpoint scheme \"localhost\" is not supported. Try tcp://localhost:9292 or unix://localhost:9292"

run_podman 125 system service myunix.sock
is "$output" "Error: API Service endpoint scheme \"\" is not supported. Try tcp://myunix.sock or unix:/myunix.sock"
is "$output" "Error: API Service endpoint scheme \"\" is not supported. Try tcp://myunix.sock or unix://myunix.sock"
}

@test "podman system service unix: without two slashes still works" {
skip_if_remote "podman system service unavailable over remote"
URL=unix:$PODMAN_TMPDIR/myunix.sock

systemd-run --unit=$SERVICE_NAME $PODMAN system service $URL --time=0
wait_for_file $PODMAN_TMPDIR/myunix.sock

run_podman --host $URL info --format '{{.Host.RemoteSocket.Path}}'
is "$output" "$URL" "RemoteSocket.Path using unix:"

systemctl stop $SERVICE_NAME
rm -f $PODMAN_TMPDIR/myunix.sock
}

@test "podman-system-service containers survive service stop" {
Expand Down

0 comments on commit 5be2357

Please sign in to comment.