本文整理汇总了Golang中github.com/projectatomic/atomic-enterprise/pkg/image/api.ParseDockerImageReference函数的典型用法代码示例。如果您正苦于以下问题:Golang ParseDockerImageReference函数的具体用法?Golang ParseDockerImageReference怎么用?Golang ParseDockerImageReference使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ParseDockerImageReference函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: convert_v1_BuildOutput_To_api_BuildOutput
func convert_v1_BuildOutput_To_api_BuildOutput(in *BuildOutput, out *newer.BuildOutput, s conversion.Scope) error {
if err := s.DefaultConvert(in, out, conversion.IgnoreMissingFields); err != nil {
return err
}
if in.To != nil && in.To.Kind == "ImageStreamTag" {
name, tag, ok := imageapi.SplitImageStreamTag(in.To.Name)
if !ok {
return fmt.Errorf("ImageStreamTag object references must be in the form <name>:<tag>: %s", in.To.Name)
}
out.To.Kind = "ImageStream"
out.To.Name = name
out.Tag = tag
return nil
}
if in.To != nil && in.To.Kind == "DockerImage" {
out.To = nil
if ref, err := imageapi.ParseDockerImageReference(in.To.Name); err == nil {
out.Tag = ref.Tag
ref.Tag = ""
out.DockerImageReference = ref.String()
} else {
out.DockerImageReference = in.To.Name
}
}
return nil
}
示例2: convert_v1beta3_DeploymentTriggerImageChangeParams_To_api_DeploymentTriggerImageChangeParams
func convert_v1beta3_DeploymentTriggerImageChangeParams_To_api_DeploymentTriggerImageChangeParams(in *DeploymentTriggerImageChangeParams, out *newer.DeploymentTriggerImageChangeParams, s conversion.Scope) error {
out.Automatic = in.Automatic
out.ContainerNames = make([]string, len(in.ContainerNames))
copy(out.ContainerNames, in.ContainerNames)
out.LastTriggeredImage = in.LastTriggeredImage
if err := s.Convert(&in.From, &out.From, 0); err != nil {
return err
}
switch in.From.Kind {
case "DockerImage":
ref, err := imageapi.ParseDockerImageReference(in.From.Name)
if err != nil {
return err
}
out.Tag = ref.Tag
ref.Tag, ref.ID = "", ""
out.RepositoryName = ref.String()
case "ImageStreamTag":
name, tag, ok := imageapi.SplitImageStreamTag(in.From.Name)
if !ok {
return fmt.Errorf("ImageStreamTag object references must be in the form <name>:<tag>: %s", in.From.Name)
}
out.From.Kind = "ImageStream"
out.From.Name = name
out.Tag = tag
}
return nil
}
示例3: DockerRepository
// DockerRepository adds the named Docker repository tag reference to the graph if it does
// not already exist. If the reference is invalid, the Name field of the graph will be
// used directly.
func DockerRepository(g MutableUniqueGraph, name, tag string) graph.Node {
ref, err := image.ParseDockerImageReference(name)
if err == nil {
if len(tag) != 0 {
ref.Tag = tag
}
if len(ref.Tag) == 0 {
ref.Tag = image.DefaultImageTag
}
if len(ref.Registry) == 0 {
ref.Registry = "docker.io"
}
if len(ref.Namespace) == 0 {
ref.Namespace = image.DockerDefaultNamespace
}
// TODO: canonicalize
name = ref.String()
} else {
ref = image.DockerImageReference{Name: name}
}
return EnsureUnique(g,
UniqueName(fmt.Sprintf("%d|%s", DockerRepositoryGraphKind, name)),
func(node Node) graph.Node {
return &DockerImageRepositoryNode{node, ref}
},
)
}
示例4: ValidateImageStreamMapping
// ValidateImageStreamMapping tests required fields for an ImageStreamMapping.
func ValidateImageStreamMapping(mapping *api.ImageStreamMapping) fielderrors.ValidationErrorList {
result := fielderrors.ValidationErrorList{}
result = append(result, validation.ValidateObjectMeta(&mapping.ObjectMeta, true, oapi.MinimalNameRequirements).Prefix("metadata")...)
hasRepository := len(mapping.DockerImageRepository) != 0
hasName := len(mapping.Name) != 0
switch {
case hasRepository:
if _, err := api.ParseDockerImageReference(mapping.DockerImageRepository); err != nil {
result = append(result, fielderrors.NewFieldInvalid("dockerImageRepository", mapping.DockerImageRepository, err.Error()))
}
case hasName:
default:
result = append(result, fielderrors.NewFieldRequired("name"))
result = append(result, fielderrors.NewFieldRequired("dockerImageRepository"))
}
if ok, msg := validation.ValidateNamespaceName(mapping.Namespace, false); !ok {
result = append(result, fielderrors.NewFieldInvalid("namespace", mapping.Namespace, msg))
}
if len(mapping.Tag) == 0 {
result = append(result, fielderrors.NewFieldRequired("tag"))
}
if errs := ValidateImage(&mapping.Image).Prefix("image"); len(errs) != 0 {
result = append(result, errs...)
}
return result
}
示例5: FromName
// FromName generates an ImageRef from a given name
func (g *imageRefGenerator) FromName(name string) (*ImageRef, error) {
ref, err := imageapi.ParseDockerImageReference(name)
if err != nil {
return nil, err
}
return &ImageRef{
DockerImageReference: ref,
}, nil
}
示例6: Resolve
// Resolve will attempt to find an imagestream with a name that matches the passed in value
func (r ImageStreamResolver) Resolve(value string) (*ComponentMatch, error) {
ref, err := imageapi.ParseDockerImageReference(value)
if err != nil || len(ref.Registry) != 0 {
return nil, fmt.Errorf("image repositories must be of the form [<namespace>/]<name>[:<tag>|@<digest>]")
}
namespaces := r.Namespaces
if len(ref.Namespace) != 0 {
namespaces = []string{ref.Namespace}
}
searchTag := ref.Tag
if len(searchTag) == 0 {
searchTag = imageapi.DefaultImageTag
}
for _, namespace := range namespaces {
glog.V(4).Infof("checking ImageStream %s/%s with ref %q", namespace, ref.Name, searchTag)
repo, err := r.Client.ImageStreams(namespace).Get(ref.Name)
if err != nil {
if errors.IsNotFound(err) || errors.IsForbidden(err) {
continue
}
return nil, err
}
ref.Namespace = namespace
latest := imageapi.LatestTaggedImage(repo, searchTag)
if latest == nil {
// continue searching in the next namespace
glog.V(2).Infof("no image recorded for %s/%s:%s", repo.Namespace, repo.Name, searchTag)
continue
}
imageStreamImage, err := r.ImageStreamImages.ImageStreamImages(namespace).Get(ref.Name, latest.Image)
if err != nil {
if errors.IsNotFound(err) {
// continue searching in the next namespace
glog.V(2).Infof("tag %q is set, but image %q has been removed", searchTag, latest.Image)
continue
}
return nil, err
}
imageData := imageStreamImage.Image
ref.Registry = ""
return &ComponentMatch{
Value: ref.String(),
Argument: fmt.Sprintf("--image=%q", ref.String()),
Name: ref.Name,
Description: fmt.Sprintf("Image repository %s (tag %q) in project %s, tracks %q", repo.Name, searchTag, repo.Namespace, repo.Status.DockerImageRepository),
Builder: IsBuilderImage(&imageData.DockerImageMetadata),
Score: 0,
ImageStream: repo,
Image: &imageData.DockerImageMetadata,
ImageTag: searchTag,
}, nil
}
return nil, ErrNoMatch{value: value}
}
示例7: BuildConfig
// BuildConfig adds a graph node for the specific build config if it does not exist,
// and will link the build config to other nodes for the images and source repositories
// it depends on.
func BuildConfig(g MutableUniqueGraph, config *build.BuildConfig) graph.Node {
node, found := g.FindOrCreate(
UniqueName(fmt.Sprintf("%d|%s/%s", BuildConfigGraphKind, config.Namespace, config.Name)),
func(node Node) graph.Node {
return &BuildConfigNode{
Node: node,
BuildConfig: config,
}
},
)
if found {
return node
}
output := config.Parameters.Output
to := output.To
switch {
case to != nil && len(to.Name) > 0:
out := ImageStreamTag(g, defaultNamespace(to.Namespace, config.Namespace), to.Name, output.Tag)
g.AddEdge(node, out, BuildOutputGraphEdgeKind)
case len(output.DockerImageReference) > 0:
out := DockerRepository(g, output.DockerImageReference, output.Tag)
g.AddEdge(node, out, BuildOutputGraphEdgeKind)
}
if in, ok := SourceRepository(g, config.Parameters.Source); ok {
g.AddEdge(in, node, BuildInputGraphEdgeKind)
}
from := buildutil.GetImageStreamForStrategy(config.Parameters.Strategy)
if from != nil {
switch from.Kind {
case "DockerImage":
if ref, err := image.ParseDockerImageReference(from.Name); err == nil {
tag := ref.Tag
ref.Tag = ""
in := DockerRepository(g, ref.String(), tag)
g.AddEdge(in, node, BuildInputImageGraphEdgeKind)
}
case "ImageStream":
tag := image.DefaultImageTag
in := ImageStreamTag(g, defaultNamespace(from.Namespace, config.Namespace), from.Name, tag)
g.AddEdge(in, node, BuildInputImageGraphEdgeKind)
case "ImageStreamTag":
name, tag, _ := image.SplitImageStreamTag(from.Name)
in := ImageStreamTag(g, defaultNamespace(from.Namespace, config.Namespace), name, tag)
g.AddEdge(in, node, BuildInputImageGraphEdgeKind)
case "ImageStreamImage":
glog.V(4).Infof("Ignoring ImageStreamImage reference in BuildConfig %s/%s", config.Namespace, config.Name)
}
}
return node
}
示例8: convert_api_DeploymentCauseImageTrigger_To_v1beta3_DeploymentCauseImageTrigger
func convert_api_DeploymentCauseImageTrigger_To_v1beta3_DeploymentCauseImageTrigger(in *newer.DeploymentCauseImageTrigger, out *DeploymentCauseImageTrigger, s conversion.Scope) error {
if len(in.RepositoryName) != 0 {
ref, err := imageapi.ParseDockerImageReference(in.RepositoryName)
if err != nil {
return err
}
ref.Tag = in.Tag
out.From.Kind = "DockerImage"
out.From.Name = ref.String()
}
return nil
}
示例9: convert_v1beta3_DeploymentCauseImageTrigger_To_api_DeploymentCauseImageTrigger
func convert_v1beta3_DeploymentCauseImageTrigger_To_api_DeploymentCauseImageTrigger(in *DeploymentCauseImageTrigger, out *newer.DeploymentCauseImageTrigger, s conversion.Scope) error {
switch in.From.Kind {
case "DockerImage":
ref, err := imageapi.ParseDockerImageReference(in.From.Name)
if err != nil {
return err
}
out.Tag = ref.Tag
ref.Tag, ref.ID = "", ""
out.RepositoryName = ref.Minimal().String()
}
return nil
}
示例10: ValidateImage
// ValidateImage tests required fields for an Image.
func ValidateImage(image *api.Image) fielderrors.ValidationErrorList {
result := fielderrors.ValidationErrorList{}
result = append(result, validation.ValidateObjectMeta(&image.ObjectMeta, false, oapi.MinimalNameRequirements).Prefix("metadata")...)
if len(image.DockerImageReference) == 0 {
result = append(result, fielderrors.NewFieldRequired("dockerImageReference"))
} else {
if _, err := api.ParseDockerImageReference(image.DockerImageReference); err != nil {
result = append(result, fielderrors.NewFieldInvalid("dockerImageReference", image.DockerImageReference, err.Error()))
}
}
return result
}
示例11: EachTemplateImage
func EachTemplateImage(pod *kapi.PodSpec, triggerFn TriggeredByFunc, fn func(TemplateImage, error)) {
for _, container := range pod.Containers {
var ref image.DockerImageReference
if trigger, ok := triggerFn(&container); ok {
trigger.Image = container.Image
fn(trigger, nil)
continue
}
ref, err := image.ParseDockerImageReference(container.Image)
if err != nil {
fn(TemplateImage{Image: container.Image}, err)
continue
}
fn(TemplateImage{Image: container.Image, Ref: &ref}, nil)
}
}
示例12: matchTag
func matchTag(image docker.APIImages, value, registry, namespace, name, tag string) []*ComponentMatch {
if len(tag) == 0 {
tag = imageapi.DefaultImageTag
}
matches := []*ComponentMatch{}
for _, s := range image.RepoTags {
if value == s {
matches = append(matches, &ComponentMatch{
Value: s,
Score: 0.0,
})
continue
}
iRef, err := imageapi.ParseDockerImageReference(s)
if err != nil {
continue
}
if len(iRef.Tag) == 0 {
iRef.Tag = imageapi.DefaultImageTag
}
match := &ComponentMatch{}
ok, score := partialScorer(name, iRef.Name, true, 0.5, 1.0)
if !ok {
continue
}
match.Score += score
_, score = partialScorer(namespace, iRef.Namespace, false, 0.5, 1.0)
match.Score += score
_, score = partialScorer(registry, iRef.Registry, false, 0.5, 1.0)
match.Score += score
_, score = partialScorer(tag, iRef.Tag, false, 0.5, 1.0)
match.Score += score
if match.Score >= 4.0 {
continue
}
match.Score = match.Score / 4.0
glog.V(4).Infof("partial match on %q with %f", s, match.Score)
match.Value = s
matches = append(matches, match)
}
return matches
}
示例13: ValidateImageStream
// ValidateImageStream tests required fields for an ImageStream.
func ValidateImageStream(stream *api.ImageStream) fielderrors.ValidationErrorList {
result := fielderrors.ValidationErrorList{}
result = append(result, validation.ValidateObjectMeta(&stream.ObjectMeta, true, ValidateImageStreamName).Prefix("metadata")...)
// Ensure we can generate a valid docker image repository from namespace/name
if len(stream.Namespace) > 0 && len(stream.Namespace) < v2.RepositoryNameComponentMinLength {
result = append(result, fielderrors.NewFieldInvalid("metadata.namespace", stream.Namespace, fmt.Sprintf("must be at least %d characters long", v2.RepositoryNameComponentMinLength)))
}
if len(stream.Namespace+"/"+stream.Name) > v2.RepositoryNameTotalLengthMax {
result = append(result, fielderrors.NewFieldInvalid("metadata.name", stream.Name, fmt.Sprintf("'namespace/name' cannot be longer than %d characters", v2.RepositoryNameTotalLengthMax)))
}
if stream.Spec.Tags == nil {
stream.Spec.Tags = make(map[string]api.TagReference)
}
if len(stream.Spec.DockerImageRepository) != 0 {
if _, err := api.ParseDockerImageReference(stream.Spec.DockerImageRepository); err != nil {
result = append(result, fielderrors.NewFieldInvalid("spec.dockerImageRepository", stream.Spec.DockerImageRepository, err.Error()))
}
}
for tag, tagRef := range stream.Spec.Tags {
if tagRef.From != nil {
switch tagRef.From.Kind {
case "DockerImage", "ImageStreamImage", "ImageStreamTag":
default:
result = append(result, fielderrors.NewFieldInvalid(fmt.Sprintf("spec.tags[%s].from.kind", tag), tagRef.From.Kind, "valid values are 'DockerImage', 'ImageStreamImage', 'ImageStreamTag'"))
}
}
}
for tag, history := range stream.Status.Tags {
for i, tagEvent := range history.Items {
if len(tagEvent.DockerImageReference) == 0 {
result = append(result, fielderrors.NewFieldRequired(fmt.Sprintf("status.tags[%s].Items[%d].dockerImageReference", tag, i)))
}
}
}
return result
}
示例14: FromStream
// FromStream generates an ImageRef from an OpenShift ImageStream
func (g *imageRefGenerator) FromStream(stream *imageapi.ImageStream, tag string) (*ImageRef, error) {
pullSpec := stream.Status.DockerImageRepository
if len(pullSpec) == 0 {
// need to know the default OpenShift registry
return nil, fmt.Errorf("the repository does not resolve to a pullable Docker repository")
}
ref, err := imageapi.ParseDockerImageReference(pullSpec)
if err != nil {
return nil, err
}
switch {
case len(tag) > 0:
ref.Tag = tag
case len(tag) == 0 && len(ref.Tag) == 0:
ref.Tag = imageapi.DefaultImageTag
}
return &ImageRef{
DockerImageReference: ref,
Stream: stream,
}, nil
}
示例15: Export
//.........这里部分代码省略.........
// TODO: when internal refactor is completed use status reset
t.LatestVersion = 0
t.Details = nil
for i := range t.Triggers {
if p := t.Triggers[i].ImageChangeParams; p != nil {
p.LastTriggeredImage = ""
}
}
case *buildapi.BuildConfig:
buildconfigrest.Strategy.PrepareForCreate(obj)
// TODO: should be handled by prepare for create
t.LastVersion = 0
for i := range t.Triggers {
if p := t.Triggers[i].ImageChange; p != nil {
p.LastTriggeredImageID = ""
}
}
case *buildapi.Build:
buildrest.Strategy.PrepareForCreate(obj)
// TODO: should be handled by prepare for create
t.Duration = 0
t.Message = ""
t.Status = buildapi.BuildStatusNew
t.StartTimestamp = nil
t.CompletionTimestamp = nil
if exact {
return nil
}
if t.Config != nil {
t.Config = &kapi.ObjectReference{Name: t.Config.Name}
}
case *routeapi.Route:
case *imageapi.Image:
case *imageapi.ImageStream:
if exact {
return nil
}
// if we point to a docker image repository upstream, copy only the spec tags
if len(t.Spec.DockerImageRepository) > 0 {
t.Status = imageapi.ImageStreamStatus{}
break
}
// create an image stream that mirrors (each spec tag points to the remote image stream)
if len(t.Status.DockerImageRepository) > 0 {
ref, err := imageapi.ParseDockerImageReference(t.Status.DockerImageRepository)
if err != nil {
return err
}
newSpec := imageapi.ImageStreamSpec{}
for name, tag := range t.Status.Tags {
if len(tag.Items) > 0 {
// copy annotations
existing := t.Spec.Tags[name]
// point directly to that registry
ref.Tag = name
existing.From = &kapi.ObjectReference{
Kind: "DockerImage",
Name: ref.String(),
}
newSpec.Tags[name] = existing
}
}
for name, ref := range t.Spec.Tags {
if _, ok := t.Status.Tags[name]; ok {
continue
}
// TODO: potentially trim some of these
newSpec.Tags[name] = ref
}
t.Spec = newSpec
t.Status = imageapi.ImageStreamStatus{}
break
}
// otherwise, try to snapshot the most recent image as spec items
newSpec := imageapi.ImageStreamSpec{}
for name, tag := range t.Status.Tags {
if len(tag.Items) > 0 {
// copy annotations
existing := t.Spec.Tags[name]
existing.From = &kapi.ObjectReference{
Kind: "DockerImage",
Name: tag.Items[0].DockerImageReference,
}
newSpec.Tags[name] = existing
}
}
t.Spec = newSpec
t.Status = imageapi.ImageStreamStatus{}
case *imageapi.ImageStreamTag:
exportObjectMeta(&t.Image.ObjectMeta, exact)
case *imageapi.ImageStreamImage:
exportObjectMeta(&t.Image.ObjectMeta, exact)
default:
glog.V(4).Infof("No export strategy defined for objects of type %v", reflect.TypeOf(obj))
}
return nil
}