Commit 84f03ef9 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #36140 from guangxuli/k8s_extend_get_docker_auth

Automatic merge from submit-queue make invocation ReadDockerConfigFile can handle .dockerconfigjson file **What this PR does / why we need it**: When **.docker/config.json** is used to authenticate docker registry, the data key **.dockerconfigjson** should be used if we want to save this kind of docker auth data into a secret. So this PR is mainly to make invocation `ReadDockerConfigFile `have ability to read **.dockerconfigjson** file. @liggitt
parents 08c0f7dd 032e450e
...@@ -122,29 +122,35 @@ func ReadDockerConfigJSONFile(searchPaths []string) (cfg DockerConfig, err error ...@@ -122,29 +122,35 @@ func ReadDockerConfigJSONFile(searchPaths []string) (cfg DockerConfig, err error
if len(searchPaths) == 0 { if len(searchPaths) == 0 {
searchPaths = DefaultDockerConfigJSONPaths() searchPaths = DefaultDockerConfigJSONPaths()
} }
for _, configPath := range searchPaths { for _, configPath := range searchPaths {
absDockerConfigFileLocation, err := filepath.Abs(filepath.Join(configPath, configJsonFileName)) absDockerConfigFileLocation, err := filepath.Abs(filepath.Join(configPath, configJsonFileName))
if err != nil { if err != nil {
glog.Errorf("while trying to canonicalize %s: %v", configPath, err) glog.Errorf("while trying to canonicalize %s: %v", configPath, err)
continue continue
} }
glog.V(4).Infof("looking for .docker/config.json at %s", absDockerConfigFileLocation) glog.V(4).Infof("looking for %s at %s", configJsonFileName, absDockerConfigFileLocation)
contents, err := ioutil.ReadFile(absDockerConfigFileLocation) cfg, err = ReadSpecificDockerConfigJsonFile(absDockerConfigFileLocation)
if os.IsNotExist(err) {
continue
}
if err != nil { if err != nil {
glog.V(4).Infof("while trying to read %s: %v", absDockerConfigFileLocation, err) if !os.IsNotExist(err) {
glog.V(4).Infof("while trying to read %s: %v", absDockerConfigFileLocation, err)
}
continue continue
} }
cfg, err := readDockerConfigJsonFileFromBytes(contents) glog.V(4).Infof("found valid %s at %s", configJsonFileName, absDockerConfigFileLocation)
if err == nil { return cfg, nil
glog.V(4).Infof("found .docker/config.json at %s", absDockerConfigFileLocation) }
return cfg, nil return nil, fmt.Errorf("couldn't find valid %s after checking in %v", configJsonFileName, searchPaths)
}
}
//ReadSpecificDockerConfigJsonFile attempts to read docker configJSON from a given file path.
func ReadSpecificDockerConfigJsonFile(filePath string) (cfg DockerConfig, err error) {
var contents []byte
if contents, err = ioutil.ReadFile(filePath); err != nil {
return nil, err
} }
return nil, fmt.Errorf("couldn't find valid .docker/config.json after checking in %v", searchPaths) return readDockerConfigJsonFileFromBytes(contents)
} }
func ReadDockerConfigFile() (cfg DockerConfig, err error) { func ReadDockerConfigFile() (cfg DockerConfig, err error) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment