Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check other dirs for .dockercfg #3844

Merged
merged 1 commit into from
Jan 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -127,6 +128,8 @@ func main() {
glog.Warningf("No API client: %v", err)
}

credentialprovider.SetPreferredDockercfgPath(*rootDirectory)

kcfg := standalone.KubeletConfig{
Address: address,
AllowPrivileged: *allowPrivileged,
Expand Down
61 changes: 43 additions & 18 deletions pkg/credentialprovider/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"os"
"path/filepath"
"strings"
"sync"

"github.com/golang/glog"
)
Expand All @@ -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 SetPreferredDockercfgPath(path string) {
preferredPathLock.Lock()
defer preferredPathLock.Unlock()
preferredPath = path
}

func GetPreferredDockercfgPath() string {
preferredPathLock.Lock()
defer preferredPathLock.Unlock()
return preferredPath
}

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
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 readDockerConfigFileFromBytes(contents)
return nil, fmt.Errorf("couldn't find valid .dockercfg after checking in %v", dockerConfigFileLocations)
}

// HttpError wraps a non-StatusOK error code as an error.
Expand Down
2 changes: 1 addition & 1 deletion pkg/credentialprovider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/standalone/standalone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down