Skip to content

Commit 3f4bf82

Browse files
authored
Merge pull request #3324 from thaJeztah/no_pkg_homedir
driver/kubernetes: remove uses of pkg/homedir
2 parents dcd1133 + 3f725bf commit 3f4bf82

File tree

5 files changed

+29
-169
lines changed

5 files changed

+29
-169
lines changed

driver/kubernetes/context/load.go

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ package context
33
import (
44
"net/url"
55
"os"
6+
"os/user"
67
"path/filepath"
8+
"runtime"
79
"strings"
810

911
"github.com/docker/cli/cli/command"
1012
"github.com/docker/cli/cli/context"
1113
"github.com/docker/cli/cli/context/store"
12-
"github.com/docker/docker/pkg/homedir"
1314
"k8s.io/client-go/tools/clientcmd"
1415
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
1516
)
@@ -99,7 +100,7 @@ func (c *Endpoint) KubernetesConfig() clientcmd.ClientConfig {
99100
func (c *EndpointMeta) ResolveDefault() (any, *store.EndpointTLSData, error) {
100101
kubeconfig := os.Getenv("KUBECONFIG")
101102
if kubeconfig == "" {
102-
kubeconfig = filepath.Join(homedir.Get(), ".kube/config")
103+
kubeconfig = filepath.Join(getHomeDir(), ".kube/config")
103104
}
104105
kubeEP, err := FromKubeConfig(kubeconfig, "", "")
105106
if err != nil {
@@ -156,7 +157,7 @@ func NewKubernetesConfig(configPath string) clientcmd.ClientConfig {
156157
if config := os.Getenv("KUBECONFIG"); config != "" {
157158
kubeConfig = config
158159
} else {
159-
kubeConfig = filepath.Join(homedir.Get(), ".kube/config")
160+
kubeConfig = filepath.Join(getHomeDir(), ".kube/config")
160161
}
161162
}
162163
return clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
@@ -181,3 +182,28 @@ func ConfigFromEndpoint(endpointName string, s store.Reader) (clientcmd.ClientCo
181182
}
182183
return ConfigFromContext(endpointName, s)
183184
}
185+
186+
// getHomeDir returns the home directory of the current user with the help of
187+
// environment variables depending on the target operating system.
188+
// Returned path should be used with "path/filepath" to form new paths.
189+
//
190+
// On non-Windows platforms, it falls back to nss lookups, if the home
191+
// directory cannot be obtained from environment-variables.
192+
//
193+
// If linking statically with cgo enabled against glibc, ensure the
194+
// osusergo build tag is used.
195+
//
196+
// If needing to do nss lookups, do not disable cgo or set osusergo.
197+
//
198+
// It's a local fork of [pkg/homedir].
199+
//
200+
// [pkg/homedir]: https://github.com/moby/moby/blob/v28.3.2/pkg/homedir/homedir.go#L9-L28
201+
func getHomeDir() string {
202+
home, _ := os.UserHomeDir()
203+
if home == "" && runtime.GOOS != "windows" {
204+
if u, err := user.Current(); err == nil {
205+
return u.HomeDir
206+
}
207+
}
208+
return home
209+
}

vendor/github.com/docker/docker/pkg/homedir/homedir.go

Lines changed: 0 additions & 28 deletions
This file was deleted.

vendor/github.com/docker/docker/pkg/homedir/homedir_linux.go

Lines changed: 0 additions & 105 deletions
This file was deleted.

vendor/github.com/docker/docker/pkg/homedir/homedir_others.go

Lines changed: 0 additions & 32 deletions
This file was deleted.

vendor/modules.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,6 @@ github.com/docker/docker/api/types/volume
282282
github.com/docker/docker/client
283283
github.com/docker/docker/internal/lazyregexp
284284
github.com/docker/docker/internal/multierror
285-
github.com/docker/docker/pkg/homedir
286285
github.com/docker/docker/pkg/jsonmessage
287286
github.com/docker/docker/pkg/namesgenerator
288287
github.com/docker/docker/pkg/stdcopy

0 commit comments

Comments
 (0)