mirror of https://github.com/containers/podman.git
Merge pull request #10080 from rhatdan/remote
podman-remote should show podman.sock info
This commit is contained in:
commit
544c315665
|
|
@ -6,11 +6,13 @@ import (
|
|||
"context"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
api "github.com/containers/podman/v3/pkg/api/server"
|
||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||
"github.com/containers/podman/v3/pkg/domain/infra"
|
||||
"github.com/containers/podman/v3/pkg/util"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/pflag"
|
||||
|
|
@ -24,6 +26,17 @@ func restService(opts entities.ServiceOptions, flags *pflag.FlagSet, cfg *entiti
|
|||
)
|
||||
|
||||
if opts.URI != "" {
|
||||
fields := strings.Split(opts.URI, ":")
|
||||
if len(fields) == 1 {
|
||||
return errors.Errorf("%s is an invalid socket destination", opts.URI)
|
||||
}
|
||||
path := opts.URI
|
||||
if fields[0] == "unix" {
|
||||
if path, err = filepath.Abs(fields[1]); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
util.SetSocketPath(path)
|
||||
if os.Getenv("LISTEN_FDS") != "" {
|
||||
// If it is activated by systemd, use the first LISTEN_FD (3)
|
||||
// instead of opening the socket file.
|
||||
|
|
@ -34,10 +47,6 @@ func restService(opts entities.ServiceOptions, flags *pflag.FlagSet, cfg *entiti
|
|||
}
|
||||
listener = &l
|
||||
} else {
|
||||
fields := strings.Split(opts.URI, ":")
|
||||
if len(fields) == 1 {
|
||||
return errors.Errorf("%s is an invalid socket destination", opts.URI)
|
||||
}
|
||||
network := fields[0]
|
||||
address := strings.Join(fields[1:], ":")
|
||||
l, err := net.Listen(network, address)
|
||||
|
|
|
|||
|
|
@ -5,11 +5,13 @@ import (
|
|||
|
||||
"github.com/containers/podman/v3/libpod"
|
||||
"github.com/containers/podman/v3/pkg/api/handlers/utils"
|
||||
"github.com/containers/podman/v3/pkg/domain/infra/abi"
|
||||
)
|
||||
|
||||
func GetInfo(w http.ResponseWriter, r *http.Request) {
|
||||
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
||||
info, err := runtime.Info()
|
||||
containerEngine := abi.ContainerEngine{Libpod: runtime}
|
||||
info, err := containerEngine.Info(r.Context())
|
||||
if err != nil {
|
||||
utils.InternalServerError(w, err)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -32,17 +32,11 @@ func (ic *ContainerEngine) Info(ctx context.Context) (*define.Info, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
xdg, err := util.GetRuntimeDir()
|
||||
|
||||
socketPath, err := util.SocketPath()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(xdg) == 0 {
|
||||
// If no xdg is returned, assume root socket
|
||||
xdg = "/run"
|
||||
}
|
||||
|
||||
// Glue the socket path together
|
||||
socketPath := filepath.Join(xdg, "podman", "podman.sock")
|
||||
rs := define.RemoteSocket{
|
||||
Path: socketPath,
|
||||
Exists: false,
|
||||
|
|
|
|||
|
|
@ -706,3 +706,26 @@ func IDtoolsToRuntimeSpec(idMaps []idtools.IDMap) (convertedIDMap []specs.LinuxI
|
|||
}
|
||||
return convertedIDMap
|
||||
}
|
||||
|
||||
var socketPath string
|
||||
|
||||
func SetSocketPath(path string) {
|
||||
socketPath = path
|
||||
}
|
||||
|
||||
func SocketPath() (string, error) {
|
||||
if socketPath != "" {
|
||||
return socketPath, nil
|
||||
}
|
||||
xdg, err := GetRuntimeDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if len(xdg) == 0 {
|
||||
// If no xdg is returned, assume root socket
|
||||
xdg = "/run"
|
||||
}
|
||||
|
||||
// Glue the socket path together
|
||||
return filepath.Join(xdg, "podman", "podman.sock"), nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,4 +109,19 @@ var _ = Describe("Podman Info", func() {
|
|||
Expect(err).To(BeNil())
|
||||
Expect(string(out)).To(Equal(expect))
|
||||
})
|
||||
|
||||
It("podman info check RemoteSocket", func() {
|
||||
session := podmanTest.Podman([]string{"info", "--format", "{{.Host.RemoteSocket.Path}}"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
Expect(session.OutputToString()).To(MatchRegexp("/run/.*podman.*sock"))
|
||||
|
||||
if IsRemote() {
|
||||
session = podmanTest.Podman([]string{"info", "--format", "{{.Host.RemoteSocket.Exists}}"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
Expect(session.OutputToString()).To(ContainSubstring("true"))
|
||||
}
|
||||
})
|
||||
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue