pkg/rootless: remove GetRootlessKitClient, and move to daemon

This utility was only used in a single location (as part of `docker info`),
but the `pkg/rootless` package is imported in various locations, causing
rootlesskit to be a dependency for consumers of that package.

Move GetRootlessKitClient to the daemon code, which is the only location
it was used.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-06-12 13:44:30 +02:00
parent ed798d651a
commit 59b5c6075f
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
2 changed files with 14 additions and 18 deletions

View file

@ -5,6 +5,7 @@ package daemon // import "github.com/docker/docker/daemon"
import (
"context"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
@ -16,6 +17,7 @@ import (
"github.com/docker/docker/pkg/rootless"
"github.com/docker/docker/pkg/sysinfo"
"github.com/pkg/errors"
rkclient "github.com/rootless-containers/rootlesskit/pkg/api/client"
"github.com/sirupsen/logrus"
)
@ -218,7 +220,7 @@ func (daemon *Daemon) fillRootlessVersion(v *types.Version) {
if !rootless.RunningWithRootlessKit() {
return
}
rlc, err := rootless.GetRootlessKitClient()
rlc, err := getRootlessKitClient()
if err != nil {
logrus.Warnf("failed to create RootlessKit client: %v", err)
return
@ -268,6 +270,16 @@ func (daemon *Daemon) fillRootlessVersion(v *types.Version) {
}
}
// getRootlessKitClient returns RootlessKit client
func getRootlessKitClient() (rkclient.Client, error) {
stateDir := os.Getenv("ROOTLESSKIT_STATE_DIR")
if stateDir == "" {
return nil, errors.New("environment variable `ROOTLESSKIT_STATE_DIR` is not set")
}
apiSock := filepath.Join(stateDir, "api.sock")
return rkclient.New(apiSock)
}
func fillDriverWarnings(v *types.Info) {
for _, pair := range v.DriverStatus {
if pair[0] == "Extended file attributes" && pair[1] == "best-effort" {

View file

@ -1,12 +1,6 @@
package rootless // import "github.com/docker/docker/pkg/rootless"
import (
"os"
"path/filepath"
"github.com/pkg/errors"
"github.com/rootless-containers/rootlesskit/pkg/api/client"
)
import "os"
// RootlessKitDockerProxyBinary is the binary name of rootlesskit-docker-proxy
const RootlessKitDockerProxyBinary = "rootlesskit-docker-proxy"
@ -15,13 +9,3 @@ const RootlessKitDockerProxyBinary = "rootlesskit-docker-proxy"
func RunningWithRootlessKit() bool {
return os.Getenv("ROOTLESSKIT_STATE_DIR") != ""
}
// GetRootlessKitClient returns RootlessKit client
func GetRootlessKitClient() (client.Client, error) {
stateDir := os.Getenv("ROOTLESSKIT_STATE_DIR")
if stateDir == "" {
return nil, errors.New("environment variable `ROOTLESSKIT_STATE_DIR` is not set")
}
apiSock := filepath.Join(stateDir, "api.sock")
return client.New(apiSock)
}