Fix use of docker removed ParseRepositoryTag() function

Docker has removed the ParseRepositoryTag() function in
leading to failures using the kubernetes Go client API.

Lets use github.com/docker/distribution reference.ParseNamed()
instead.

Failure:

../k8s.io/kubernetes/pkg/util/parsers/parsers.go:30: undefined: parsers.ParseRepositoryTag
This commit is contained in:
Stef Walter
2016-03-30 16:23:07 +02:00
parent 04da473594
commit 481dbca8bc
7 changed files with 505 additions and 224 deletions

View File

@@ -17,7 +17,9 @@ limitations under the License.
package parsers
import (
"github.com/docker/docker/pkg/parsers"
"fmt"
"github.com/docker/distribution/reference"
)
const (
@@ -26,11 +28,28 @@ const (
// parseImageName parses a docker image string into two parts: repo and tag.
// If tag is empty, return the defaultImageTag.
func ParseImageName(image string) (string, string) {
repoToPull, tag := parsers.ParseRepositoryTag(image)
func ParseImageName(image string) (string, string, error) {
named, err := reference.ParseNamed(image)
if err != nil {
return "", "", fmt.Errorf("couldn't parse image name: %v", err)
}
repoToPull := named.Name()
var tag string
tagged, ok := named.(reference.Tagged)
if ok {
tag = tagged.Tag()
}
digested, ok := named.(reference.Digested)
if ok {
tag = digested.Digest().String()
}
// If no tag was specified, use the default "latest".
if len(tag) == 0 {
tag = defaultImageTag
}
return repoToPull, tag
return repoToPull, tag, nil
}