本文整理汇总了Golang中github.com/openshift/origin/pkg/image/api.PrioritizeTags函数的典型用法代码示例。如果您正苦于以下问题:Golang PrioritizeTags函数的具体用法?Golang PrioritizeTags怎么用?Golang PrioritizeTags使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PrioritizeTags函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: getTags
func getTags(stream *imageapi.ImageStream, image *imageapi.Image) []string {
tags := []string{}
for tag, history := range stream.Status.Tags {
if history.Items[0].Image == image.Name {
tags = append(tags, tag)
}
}
imageapi.PrioritizeTags(tags)
return tags
}
开发者ID:ncdc,项目名称:origin,代码行数:10,代码来源:images.go
示例2: Convert_api_TagEventListArray_to_v1_NamedTagEventListArray
func Convert_api_TagEventListArray_to_v1_NamedTagEventListArray(in *map[string]newer.TagEventList, out *[]NamedTagEventList, s conversion.Scope) error {
allKeys := make([]string, 0, len(*in))
for key := range *in {
allKeys = append(allKeys, key)
}
newer.PrioritizeTags(allKeys)
for _, key := range allKeys {
newTagEventList := (*in)[key]
oldTagEventList := &NamedTagEventList{Tag: key}
if err := s.Convert(&newTagEventList.Conditions, &oldTagEventList.Conditions, 0); err != nil {
return err
}
if err := s.Convert(&newTagEventList.Items, &oldTagEventList.Items, 0); err != nil {
return err
}
*out = append(*out, *oldTagEventList)
}
return nil
}
开发者ID:abhgupta,项目名称:origin,代码行数:22,代码来源:conversion.go
示例3: importRepositoryFromDockerV1
func importRepositoryFromDockerV1(ctx gocontext.Context, repository *importRepository, limiter flowcontrol.RateLimiter) {
value := ctx.Value(ContextKeyV1RegistryClient)
if value == nil {
err := kapierrors.NewForbidden(api.Resource(""), "", fmt.Errorf("registry %q does not support the v2 Registry API", repository.Registry.Host))
err.ErrStatus.Reason = "NotV2Registry"
applyErrorToRepository(repository, err)
return
}
client, ok := value.(dockerregistry.Client)
if !ok {
err := kapierrors.NewForbidden(api.Resource(""), "", fmt.Errorf("registry %q does not support the v2 Registry API", repository.Registry.Host))
err.ErrStatus.Reason = "NotV2Registry"
return
}
conn, err := client.Connect(repository.Registry.Host, repository.Insecure)
if err != nil {
applyErrorToRepository(repository, err)
return
}
// if repository import is requested (MaximumTags), attempt to load the tags, sort them, and request the first N
if count := repository.MaximumTags; count > 0 {
tagMap, err := conn.ImageTags(repository.Ref.Namespace, repository.Ref.Name)
if err != nil {
repository.Err = err
return
}
tags := make([]string, 0, len(tagMap))
for tag := range tagMap {
tags = append(tags, tag)
}
// some images on the Hub have empty tags - treat those as "latest"
set := sets.NewString(tags...)
if set.Has("") {
set.Delete("")
set.Insert(api.DefaultImageTag)
}
tags = set.List()
// include only the top N tags in the result, put the rest in AdditionalTags
api.PrioritizeTags(tags)
for _, s := range tags {
if count <= 0 {
repository.AdditionalTags = append(repository.AdditionalTags, s)
continue
}
count--
repository.Tags = append(repository.Tags, importTag{
Name: s,
})
}
}
// load digests
for i := range repository.Digests {
importDigest := &repository.Digests[i]
if importDigest.Err != nil || importDigest.Image != nil {
continue
}
limiter.Accept()
image, err := conn.ImageByID(repository.Ref.Namespace, repository.Ref.Name, importDigest.Name)
if err != nil {
importDigest.Err = err
continue
}
// we do not preserve manifests of legacy images
importDigest.Image, err = schema0ToImage(image, importDigest.Name)
if err != nil {
importDigest.Err = err
continue
}
}
for i := range repository.Tags {
importTag := &repository.Tags[i]
if importTag.Err != nil || importTag.Image != nil {
continue
}
limiter.Accept()
image, err := conn.ImageByTag(repository.Ref.Namespace, repository.Ref.Name, importTag.Name)
if err != nil {
importTag.Err = err
continue
}
// we do not preserve manifests of legacy images
importTag.Image, err = schema0ToImage(image, "")
if err != nil {
importTag.Err = err
continue
}
}
}
开发者ID:Xmagicer,项目名称:origin,代码行数:91,代码来源:importer.go
示例4: importRepositoryFromDocker
// importRepositoryFromDocker loads the tags and images requested in the passed importRepository, obeying the
// optional rate limiter. Errors are set onto the individual tags and digest objects.
func (isi *ImageStreamImporter) importRepositoryFromDocker(ctx gocontext.Context, retriever RepositoryRetriever, repository *importRepository, limiter flowcontrol.RateLimiter) {
glog.V(5).Infof("importing remote Docker repository registry=%s repository=%s insecure=%t", repository.Registry, repository.Name, repository.Insecure)
// retrieve the repository
repo, err := retriever.Repository(ctx, repository.Registry, repository.Name, repository.Insecure)
if err != nil {
glog.V(5).Infof("unable to access repository %#v: %#v", repository, err)
switch {
case err == reference.ErrReferenceInvalidFormat:
err = field.Invalid(field.NewPath("from", "name"), repository.Name, "the provided repository name is not valid")
case isDockerError(err, v2.ErrorCodeNameUnknown):
err = kapierrors.NewNotFound(api.Resource("dockerimage"), repository.Ref.Exact())
case isDockerError(err, errcode.ErrorCodeUnauthorized):
err = kapierrors.NewUnauthorized(fmt.Sprintf("you may not have access to the Docker image %q", repository.Ref.Exact()))
case strings.Contains(err.Error(), "tls: oversized record received with length") && !repository.Insecure:
err = kapierrors.NewBadRequest("this repository is HTTP only and requires the insecure flag to import")
case strings.HasSuffix(err.Error(), "no basic auth credentials"):
err = kapierrors.NewUnauthorized(fmt.Sprintf("you may not have access to the Docker image %q and did not have credentials to the repository", repository.Ref.Exact()))
case strings.HasSuffix(err.Error(), "does not support v2 API"):
importRepositoryFromDockerV1(ctx, repository, limiter)
return
}
applyErrorToRepository(repository, err)
return
}
// get a manifest context
s, err := repo.Manifests(ctx)
if err != nil {
glog.V(5).Infof("unable to access manifests for repository %#v: %#v", repository, err)
switch {
case isDockerError(err, v2.ErrorCodeNameUnknown):
err = kapierrors.NewNotFound(api.Resource("dockerimage"), repository.Ref.Exact())
case isDockerError(err, errcode.ErrorCodeUnauthorized):
err = kapierrors.NewUnauthorized(fmt.Sprintf("you may not have access to the Docker image %q", repository.Ref.Exact()))
case strings.HasSuffix(err.Error(), "no basic auth credentials"):
err = kapierrors.NewUnauthorized(fmt.Sprintf("you may not have access to the Docker image %q and did not have credentials to the repository", repository.Ref.Exact()))
}
applyErrorToRepository(repository, err)
return
}
// get a blob context
b := repo.Blobs(ctx)
// if repository import is requested (MaximumTags), attempt to load the tags, sort them, and request the first N
if count := repository.MaximumTags; count > 0 || count == -1 {
tags, err := repo.Tags(ctx).All(ctx)
if err != nil {
glog.V(5).Infof("unable to access tags for repository %#v: %#v", repository, err)
switch {
case isDockerError(err, v2.ErrorCodeNameUnknown):
err = kapierrors.NewNotFound(api.Resource("dockerimage"), repository.Ref.Exact())
case isDockerError(err, errcode.ErrorCodeUnauthorized):
err = kapierrors.NewUnauthorized(fmt.Sprintf("you may not have access to the Docker image %q", repository.Ref.Exact()))
}
repository.Err = err
return
}
// some images on the Hub have empty tags - treat those as "latest"
set := sets.NewString(tags...)
if set.Has("") {
set.Delete("")
set.Insert(api.DefaultImageTag)
}
tags = set.List()
// include only the top N tags in the result, put the rest in AdditionalTags
api.PrioritizeTags(tags)
for _, s := range tags {
if count <= 0 && repository.MaximumTags != -1 {
repository.AdditionalTags = append(repository.AdditionalTags, s)
continue
}
count--
repository.Tags = append(repository.Tags, importTag{
Name: s,
})
}
}
// load digests
for i := range repository.Digests {
importDigest := &repository.Digests[i]
if importDigest.Err != nil || importDigest.Image != nil {
continue
}
d, err := digest.ParseDigest(importDigest.Name)
if err != nil {
importDigest.Err = err
continue
}
limiter.Accept()
manifest, err := s.Get(ctx, d)
if err != nil {
glog.V(5).Infof("unable to access digest %q for repository %#v: %#v", d, repository, err)
importDigest.Err = formatRepositoryError(repository, "", importDigest.Name, err)
continue
}
//.........这里部分代码省略.........
开发者ID:Xmagicer,项目名称:origin,代码行数:101,代码来源:importer.go
示例5: formatImageStreamTags
func formatImageStreamTags(out *tabwriter.Writer, stream *imageapi.ImageStream) {
if len(stream.Status.Tags) == 0 && len(stream.Spec.Tags) == 0 {
fmt.Fprintf(out, "Tags:\t<none>\n")
return
}
fmt.Fprint(out, "\nTag\tSpec\tCreated\tPullSpec\tImage\n")
sortedTags := []string{}
for k := range stream.Status.Tags {
sortedTags = append(sortedTags, k)
}
for k := range stream.Spec.Tags {
if _, ok := stream.Status.Tags[k]; !ok {
sortedTags = append(sortedTags, k)
}
}
hasScheduled, hasInsecure := false, false
imageapi.PrioritizeTags(sortedTags)
for _, tag := range sortedTags {
tagRef, ok := stream.Spec.Tags[tag]
specTag := ""
scheduled := false
insecure := false
if ok {
if tagRef.From != nil {
namePair := ""
if len(tagRef.From.Namespace) > 0 && tagRef.From.Namespace != stream.Namespace {
namePair = fmt.Sprintf("%s/%s", tagRef.From.Namespace, tagRef.From.Name)
} else {
namePair = tagRef.From.Name
}
switch tagRef.From.Kind {
case "ImageStreamTag", "ImageStreamImage":
specTag = namePair
case "DockerImage":
specTag = tagRef.From.Name
default:
specTag = fmt.Sprintf("<unknown %s> %s", tagRef.From.Kind, namePair)
}
}
scheduled, insecure = tagRef.ImportPolicy.Scheduled, tagRef.ImportPolicy.Insecure
hasScheduled = hasScheduled || scheduled
hasInsecure = hasScheduled || insecure
} else {
specTag = "<pushed>"
}
if taglist, ok := stream.Status.Tags[tag]; ok {
if len(taglist.Conditions) > 0 {
var lastTime time.Time
summary := []string{}
for _, condition := range taglist.Conditions {
if condition.LastTransitionTime.After(lastTime) {
lastTime = condition.LastTransitionTime.Time
}
switch condition.Type {
case imageapi.ImportSuccess:
if condition.Status == api.ConditionFalse {
summary = append(summary, fmt.Sprintf("import failed: %s", condition.Message))
}
default:
summary = append(summary, string(condition.Type))
}
}
if len(summary) > 0 {
description := strings.Join(summary, ", ")
if len(description) > 70 {
description = strings.TrimSpace(description[:70-3]) + "..."
}
d := timeNowFn().Sub(lastTime)
fmt.Fprintf(out, "%s\t%s\t%s ago\t%s\t%v\n",
tag,
shortenImagePullSpec(specTag),
units.HumanDuration(d),
"",
description)
}
}
for i, event := range taglist.Items {
d := timeNowFn().Sub(event.Created.Time)
image := event.Image
ref, err := imageapi.ParseDockerImageReference(event.DockerImageReference)
if err == nil {
if ref.ID == image {
image = "<same>"
}
}
pullSpec := event.DockerImageReference
if pullSpec == specTag {
pullSpec = "<same>"
} else {
pullSpec = shortenImagePullSpec(pullSpec)
}
specTag = shortenImagePullSpec(specTag)
if i != 0 {
tag, specTag = "", ""
} else {
extra := ""
if scheduled {
extra += "*"
}
//.........这里部分代码省略.........
开发者ID:richm,项目名称:origin,代码行数:101,代码来源:helpers.go
示例6: importRepositoryFromDocker
// importRepositoryFromDocker loads the tags and images requested in the passed importRepository, obeying the
// optional rate limiter. Errors are set onto the individual tags and digest objects.
func importRepositoryFromDocker(ctx gocontext.Context, retriever RepositoryRetriever, repository *importRepository, limiter util.RateLimiter) {
// retrieve the repository
repo, err := retriever.Repository(ctx, repository.Registry, repository.Name, repository.Insecure)
if err != nil {
glog.V(5).Infof("unable to access repository %#v: %#v", repository, err)
switch {
case isDockerError(err, v2.ErrorCodeNameUnknown):
err = kapierrors.NewNotFound("DockerImage", repository.Ref.Exact())
case isDockerError(err, errcode.ErrorCodeUnauthorized):
err = kapierrors.NewUnauthorized(fmt.Sprintf("you may not have access to the Docker image %q", repository.Ref.Exact()))
case strings.Contains(err.Error(), "tls: oversized record received with length") && !repository.Insecure:
err = kapierrors.NewBadRequest("this repository is HTTP only and requires the insecure flag to import")
case strings.HasSuffix(err.Error(), "no basic auth credentials"):
err = kapierrors.NewUnauthorized(fmt.Sprintf("you may not have access to the Docker image %q and did not have credentials to the repository", repository.Ref.Exact()))
case strings.HasSuffix(err.Error(), "does not support v2 API"):
importRepositoryFromDockerV1(ctx, repository, limiter)
return
}
applyErrorToRepository(repository, err)
return
}
// get a manifest context
s, err := repo.Manifests(ctx)
if err != nil {
glog.V(5).Infof("unable to access manifests for repository %#v: %#v", repository, err)
switch {
case isDockerError(err, v2.ErrorCodeNameUnknown):
err = kapierrors.NewNotFound("DockerImage", repository.Ref.Exact())
case isDockerError(err, errcode.ErrorCodeUnauthorized):
err = kapierrors.NewUnauthorized(fmt.Sprintf("you may not have access to the Docker image %q", repository.Ref.Exact()))
case strings.HasSuffix(err.Error(), "no basic auth credentials"):
err = kapierrors.NewUnauthorized(fmt.Sprintf("you may not have access to the Docker image %q and did not have credentials to the repository", repository.Ref.Exact()))
}
applyErrorToRepository(repository, err)
return
}
// if repository import is requested (MaximumTags), attempt to load the tags, sort them, and request the first N
if count := repository.MaximumTags; count > 0 || count == -1 {
tags, err := s.Tags()
if err != nil {
glog.V(5).Infof("unable to access tags for repository %#v: %#v", repository, err)
switch {
case isDockerError(err, v2.ErrorCodeNameUnknown):
err = kapierrors.NewNotFound("DockerImage", repository.Ref.Exact())
case isDockerError(err, errcode.ErrorCodeUnauthorized):
err = kapierrors.NewUnauthorized(fmt.Sprintf("you may not have access to the Docker image %q", repository.Ref.Exact()))
}
repository.Err = err
return
}
// some images on the Hub have empty tags - treat those as "latest"
set := sets.NewString(tags...)
if set.Has("") {
set.Delete("")
set.Insert(api.DefaultImageTag)
}
tags = set.List()
// include only the top N tags in the result, put the rest in AdditionalTags
api.PrioritizeTags(tags)
for _, s := range tags {
if count <= 0 && repository.MaximumTags != -1 {
repository.AdditionalTags = append(repository.AdditionalTags, s)
continue
}
count--
repository.Tags = append(repository.Tags, importTag{
Name: s,
})
}
}
// load digests
for i := range repository.Digests {
importDigest := &repository.Digests[i]
if importDigest.Err != nil || importDigest.Image != nil {
continue
}
d, err := digest.ParseDigest(importDigest.Name)
if err != nil {
importDigest.Err = err
continue
}
limiter.Accept()
m, err := s.Get(d)
if err != nil {
glog.V(5).Infof("unable to access digest %q for repository %#v: %#v", d, repository, err)
switch {
case isDockerError(err, v2.ErrorCodeManifestUnknown):
ref := repository.Ref
ref.Tag, ref.ID = "", importDigest.Name
err = kapierrors.NewNotFound("DockerImage", ref.Exact())
case isDockerError(err, errcode.ErrorCodeUnauthorized):
err = kapierrors.NewUnauthorized(fmt.Sprintf("you may not have access to the Docker image %q", repository.Ref.Exact()))
case strings.HasSuffix(err.Error(), "no basic auth credentials"):
err = kapierrors.NewUnauthorized(fmt.Sprintf("you may not have access to the Docker image %q", repository.Ref.Exact()))
}
//.........这里部分代码省略.........
开发者ID:Vitogee,项目名称:origin,代码行数:101,代码来源:importer.go
示例7: formatImageStreamTags
func formatImageStreamTags(out *tabwriter.Writer, stream *imageapi.ImageStream) {
if len(stream.Status.Tags) == 0 && len(stream.Spec.Tags) == 0 {
fmt.Fprintf(out, "Tags:\t<none>\n")
return
}
now := timeNowFn()
images := make(map[string]string)
for tag, tags := range stream.Status.Tags {
for _, item := range tags.Items {
switch {
case len(item.Image) > 0:
if _, ok := images[item.Image]; !ok {
images[item.Image] = tag
}
case len(item.DockerImageReference) > 0:
if _, ok := images[item.DockerImageReference]; !ok {
images[item.Image] = item.DockerImageReference
}
}
}
}
sortedTags := []string{}
for k := range stream.Status.Tags {
sortedTags = append(sortedTags, k)
}
var localReferences sets.String
var referentialTags map[string]sets.String
for k := range stream.Spec.Tags {
if target, _, ok, multiple := imageapi.FollowTagReference(stream, k); ok && multiple {
if referentialTags == nil {
referentialTags = make(map[string]sets.String)
}
if localReferences == nil {
localReferences = sets.NewString()
}
localReferences.Insert(k)
v := referentialTags[target]
if v == nil {
v = sets.NewString()
referentialTags[target] = v
}
v.Insert(k)
}
if _, ok := stream.Status.Tags[k]; !ok {
sortedTags = append(sortedTags, k)
}
}
fmt.Fprintf(out, "Unique Images:\t%d\nTags:\t%d\n\n", len(images), len(sortedTags))
first := true
imageapi.PrioritizeTags(sortedTags)
for _, tag := range sortedTags {
if localReferences.Has(tag) {
continue
}
if first {
first = false
} else {
fmt.Fprintf(out, "\n")
}
taglist, _ := stream.Status.Tags[tag]
tagRef, hasSpecTag := stream.Spec.Tags[tag]
scheduled := false
insecure := false
importing := false
var name string
if hasSpecTag && tagRef.From != nil {
if len(tagRef.From.Namespace) > 0 && tagRef.From.Namespace != stream.Namespace {
name = fmt.Sprintf("%s/%s", tagRef.From.Namespace, tagRef.From.Name)
} else {
name = tagRef.From.Name
}
scheduled, insecure = tagRef.ImportPolicy.Scheduled, tagRef.ImportPolicy.Insecure
gen := imageapi.LatestObservedTagGeneration(stream, tag)
importing = !tagRef.Reference && tagRef.Generation != nil && *tagRef.Generation != gen
}
// updates whenever tag :5.2 is changed
// :latest (30 minutes ago) -> 102.205.358.453/foo/[email protected]:abcde734
// error: last import failed 20 minutes ago
// updates automatically from index.docker.io/mysql/bar
// will use insecure HTTPS connections or HTTP
//
// MySQL 5.5
// ---------
// Describes a system for updating based on practical changes to a database system
// with some other data involved
//
// 20 minutes ago <import failed>
// Failed to locate the server in time
// 30 minutes ago 102.205.358.453/foo/[email protected]:abcdef
// 1 hour ago 102.205.358.453/foo/[email protected]:bfedfc
//var shortErrors []string
/*
//.........这里部分代码省略.........
开发者ID:juanluisvaladas,项目名称:origin,代码行数:101,代码来源:helpers.go
注:本文中的github.com/openshift/origin/pkg/image/api.PrioritizeTags函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论