mirror of https://github.com/k3s-io/k3s
Check other dirs for .dockercfg
parent
c3da4f0b19
commit
33f158073b
|
@ -27,6 +27,7 @@ import (
|
|||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/cmd/kubelet/app"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/credentialprovider"
|
||||
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/healthz"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/master/ports"
|
||||
|
@ -127,6 +128,8 @@ func main() {
|
|||
glog.Warningf("No API client: %v", err)
|
||||
}
|
||||
|
||||
credentialprovider.SetPreferredDockercfgPath(*rootDirectory)
|
||||
|
||||
kcfg := standalone.KubeletConfig{
|
||||
Address: address,
|
||||
AllowPrivileged: *allowPrivileged,
|
||||
|
|
|
@ -25,6 +25,7 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
@ -40,28 +41,52 @@ type DockerConfigEntry struct {
|
|||
Email string
|
||||
}
|
||||
|
||||
const (
|
||||
dockerConfigFileLocation = ".dockercfg"
|
||||
var (
|
||||
preferredPathLock sync.Mutex
|
||||
preferredPath = ""
|
||||
workingDirPath = ""
|
||||
homeDirPath = os.Getenv("HOME")
|
||||
rootDirPath = "/"
|
||||
|
||||
configFileName = ".dockercfg"
|
||||
)
|
||||
|
||||
func ReadDockerConfigFile() (cfg DockerConfig, err error) {
|
||||
// TODO(mattmoor): This causes the Kubelet to read /.dockercfg,
|
||||
// which is incorrect. It should come from $HOME/.dockercfg.
|
||||
absDockerConfigFileLocation, err := filepath.Abs(dockerConfigFileLocation)
|
||||
if err != nil {
|
||||
glog.Errorf("while trying to canonicalize %s: %v", dockerConfigFileLocation, err)
|
||||
}
|
||||
glog.V(2).Infof("looking for .dockercfg at %s", absDockerConfigFileLocation)
|
||||
contents, err := ioutil.ReadFile(absDockerConfigFileLocation)
|
||||
if os.IsNotExist(err) {
|
||||
return make(DockerConfig), nil
|
||||
}
|
||||
if err != nil {
|
||||
glog.Errorf("while trying to read %s: %v", absDockerConfigFileLocation, err)
|
||||
return nil, err
|
||||
}
|
||||
func SetPreferredDockercfgPath(path string) {
|
||||
preferredPathLock.Lock()
|
||||
defer preferredPathLock.Unlock()
|
||||
preferredPath = path
|
||||
}
|
||||
|
||||
return readDockerConfigFileFromBytes(contents)
|
||||
func GetPreferredDockercfgPath() string {
|
||||
preferredPathLock.Lock()
|
||||
defer preferredPathLock.Unlock()
|
||||
return preferredPath
|
||||
}
|
||||
|
||||
func ReadDockerConfigFile() (cfg DockerConfig, err error) {
|
||||
dockerConfigFileLocations := []string{GetPreferredDockercfgPath(), workingDirPath, homeDirPath, rootDirPath}
|
||||
for _, configPath := range dockerConfigFileLocations {
|
||||
absDockerConfigFileLocation, err := filepath.Abs(filepath.Join(configPath, configFileName))
|
||||
if err != nil {
|
||||
glog.Errorf("while trying to canonicalize %s: %v", configPath, err)
|
||||
continue
|
||||
}
|
||||
glog.V(4).Infof("looking for .dockercfg at %s", absDockerConfigFileLocation)
|
||||
contents, err := ioutil.ReadFile(absDockerConfigFileLocation)
|
||||
if os.IsNotExist(err) {
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
glog.V(4).Infof("while trying to read %s: %v", absDockerConfigFileLocation, err)
|
||||
continue
|
||||
}
|
||||
cfg, err := readDockerConfigFileFromBytes(contents)
|
||||
if err == nil {
|
||||
glog.V(4).Infof("found .dockercfg at %s", absDockerConfigFileLocation)
|
||||
return cfg, nil
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("couldn't find valid .dockercfg after checking in %v", dockerConfigFileLocations)
|
||||
}
|
||||
|
||||
// HttpError wraps a non-StatusOK error code as an error.
|
||||
|
|
|
@ -68,7 +68,7 @@ func (d *defaultDockerConfigProvider) Provide() DockerConfig {
|
|||
if cfg, err := ReadDockerConfigFile(); err == nil {
|
||||
return cfg
|
||||
} else if !os.IsNotExist(err) {
|
||||
glog.V(1).Infof("Unable to parse Docker config file: %v", err)
|
||||
glog.V(4).Infof("Unable to parse Docker config file: %v", err)
|
||||
}
|
||||
return DockerConfig{}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import (
|
|||
"github.com/GoogleCloudPlatform/kubernetes/pkg/clientauth"
|
||||
nodeControllerPkg "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/controller"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/credentialprovider"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/config"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools"
|
||||
|
@ -188,6 +189,8 @@ func RunKubelet(kcfg *KubeletConfig) {
|
|||
kubelet.SetupLogging()
|
||||
kubelet.SetupCapabilities(kcfg.AllowPrivileged)
|
||||
|
||||
credentialprovider.SetPreferredDockercfgPath(kcfg.RootDirectory)
|
||||
|
||||
cfg := makePodSourceConfig(kcfg)
|
||||
k, err := createAndInitKubelet(kcfg, cfg)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue