mirror of https://github.com/k3s-io/k3s
Move parsers into util
parent
c1af9dcb7f
commit
121c7046aa
|
@ -25,7 +25,6 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/docker/docker/pkg/jsonmessage"
|
||||
"github.com/docker/docker/pkg/parsers"
|
||||
docker "github.com/fsouza/go-dockerclient"
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
|
@ -35,6 +34,7 @@ import (
|
|||
"k8s.io/kubernetes/pkg/types"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
utilerrors "k8s.io/kubernetes/pkg/util/errors"
|
||||
"k8s.io/kubernetes/pkg/util/parsers"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -115,10 +115,6 @@ func newDockerPuller(client DockerInterface, qps float32, burst int) DockerPulle
|
|||
}
|
||||
}
|
||||
|
||||
func parseImageName(image string) (string, string) {
|
||||
return parsers.ParseRepositoryTag(image)
|
||||
}
|
||||
|
||||
func filterHTTPError(err error, image string) error {
|
||||
// docker/docker/pull/11314 prints detailed error info for docker pull.
|
||||
// When it hits 502, it returns a verbose html output including an inline svg,
|
||||
|
@ -136,7 +132,7 @@ func filterHTTPError(err error, image string) error {
|
|||
}
|
||||
|
||||
func (p dockerPuller) Pull(image string, secrets []api.Secret) error {
|
||||
repoToPull, tag := parseImageName(image)
|
||||
repoToPull, tag := parsers.ParseImageName(image)
|
||||
|
||||
// If no tag was specified, use the default "latest".
|
||||
if len(tag) == 0 {
|
||||
|
|
|
@ -37,6 +37,7 @@ import (
|
|||
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
||||
"k8s.io/kubernetes/pkg/types"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
"k8s.io/kubernetes/pkg/util/parsers"
|
||||
)
|
||||
|
||||
func verifyCalls(t *testing.T, fakeDocker *FakeDockerClient, calls []string) {
|
||||
|
@ -204,16 +205,16 @@ func TestParseImageName(t *testing.T) {
|
|||
name string
|
||||
tag string
|
||||
}{
|
||||
{"ubuntu", "ubuntu", ""},
|
||||
{"ubuntu", "ubuntu", "latest"},
|
||||
{"ubuntu:2342", "ubuntu", "2342"},
|
||||
{"ubuntu:latest", "ubuntu", "latest"},
|
||||
{"foo/bar:445566", "foo/bar", "445566"},
|
||||
{"registry.example.com:5000/foobar", "registry.example.com:5000/foobar", ""},
|
||||
{"registry.example.com:5000/foobar", "registry.example.com:5000/foobar", "latest"},
|
||||
{"registry.example.com:5000/foobar:5342", "registry.example.com:5000/foobar", "5342"},
|
||||
{"registry.example.com:5000/foobar:latest", "registry.example.com:5000/foobar", "latest"},
|
||||
}
|
||||
for _, test := range tests {
|
||||
name, tag := parseImageName(test.imageName)
|
||||
name, tag := parsers.ParseImageName(test.imageName)
|
||||
if name != test.name || tag != test.tag {
|
||||
t.Errorf("Expected name/tag: %s/%s, got %s/%s", test.name, test.tag, name, tag)
|
||||
}
|
||||
|
|
|
@ -36,7 +36,6 @@ import (
|
|||
appctypes "github.com/appc/spec/schema/types"
|
||||
"github.com/coreos/go-systemd/unit"
|
||||
rktapi "github.com/coreos/rkt/api/v1alpha"
|
||||
"github.com/docker/docker/pkg/parsers"
|
||||
docker "github.com/fsouza/go-dockerclient"
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
|
@ -49,6 +48,7 @@ import (
|
|||
"k8s.io/kubernetes/pkg/types"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
utilexec "k8s.io/kubernetes/pkg/util/exec"
|
||||
"k8s.io/kubernetes/pkg/util/parsers"
|
||||
"k8s.io/kubernetes/pkg/util/sets"
|
||||
)
|
||||
|
||||
|
@ -389,23 +389,12 @@ func setApp(app *appctypes.App, c *api.Container, opts *kubecontainer.RunContain
|
|||
return setIsolators(app, c)
|
||||
}
|
||||
|
||||
// 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)
|
||||
// If no tag was specified, use the default "latest".
|
||||
if len(tag) == 0 {
|
||||
tag = defaultImageTag
|
||||
}
|
||||
return repoToPull, tag
|
||||
}
|
||||
|
||||
// getImageManifest invokes 'rkt image cat-manifest' to retrive the image manifest
|
||||
// for the image.
|
||||
func (r *Runtime) getImageManifest(image string) (*appcschema.ImageManifest, error) {
|
||||
var manifest appcschema.ImageManifest
|
||||
|
||||
repoToPull, tag := parseImageName(image)
|
||||
repoToPull, tag := parsers.ParseImageName(image)
|
||||
imgName, err := appctypes.SanitizeACIdentifier(repoToPull)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -929,7 +918,7 @@ func (r *Runtime) PullImage(image kubecontainer.ImageSpec, pullSecrets []api.Sec
|
|||
img := image.Image
|
||||
// TODO(yifan): The credential operation is a copy from dockertools package,
|
||||
// Need to resolve the code duplication.
|
||||
repoToPull, _ := parseImageName(img)
|
||||
repoToPull, _ := parsers.ParseImageName(img)
|
||||
keyring, err := credentialprovider.MakeDockerKeyring(pullSecrets, r.dockerKeyring)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -955,7 +944,7 @@ func (r *Runtime) PullImage(image kubecontainer.ImageSpec, pullSecrets []api.Sec
|
|||
|
||||
// TODO(yifan): Searching the image via 'rkt images' might not be the most efficient way.
|
||||
func (r *Runtime) IsImagePresent(image kubecontainer.ImageSpec) (bool, error) {
|
||||
repoToPull, tag := parseImageName(image.Image)
|
||||
repoToPull, tag := parsers.ParseImageName(image.Image)
|
||||
// Example output of 'rkt image list --fields=name':
|
||||
//
|
||||
// NAME
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package parsers
|
||||
|
||||
import (
|
||||
"github.com/docker/docker/pkg/parsers"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultImageTag = "latest"
|
||||
)
|
||||
|
||||
// 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)
|
||||
// If no tag was specified, use the default "latest".
|
||||
if len(tag) == 0 {
|
||||
tag = defaultImageTag
|
||||
}
|
||||
return repoToPull, tag
|
||||
}
|
Loading…
Reference in New Issue