本文整理汇总了Golang中github.com/openshift/origin/pkg/image/api.AddTagEventToImageStream函数的典型用法代码示例。如果您正苦于以下问题:Golang AddTagEventToImageStream函数的具体用法?Golang AddTagEventToImageStream怎么用?Golang AddTagEventToImageStream使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了AddTagEventToImageStream函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Create
// Create registers a new image (if it doesn't exist) and updates the specified ImageStream's tags.
func (s *REST) Create(ctx kapi.Context, obj runtime.Object) (runtime.Object, error) {
if err := rest.BeforeCreate(Strategy, ctx, obj); err != nil {
return nil, err
}
mapping := obj.(*api.ImageStreamMapping)
stream, err := s.findStreamForMapping(ctx, mapping)
if err != nil {
return nil, err
}
image := mapping.Image
tag := mapping.Tag
if len(tag) == 0 {
tag = api.DefaultImageTag
}
if err := s.imageRegistry.CreateImage(ctx, &image); err != nil && !errors.IsAlreadyExists(err) {
return nil, err
}
next := api.TagEvent{
Created: util.Now(),
DockerImageReference: image.DockerImageReference,
Image: image.Name,
}
if !api.AddTagEventToImageStream(stream, tag, next) {
// nothing actually changed
return &kapi.Status{Status: kapi.StatusSuccess}, nil
}
api.UpdateTrackingTags(stream, tag, next)
if _, err := s.imageStreamRegistry.UpdateImageStreamStatus(ctx, stream); err != nil {
return nil, err
}
return &kapi.Status{Status: kapi.StatusSuccess}, nil
}
开发者ID:jhadvig,项目名称:origin,代码行数:42,代码来源:rest.go
示例2: importSuccessful
// importSuccessful records a successful import into an image stream, setting the spec tag, status tag or conditions, and ensuring
// the image is created in etcd. Images are cached so they are not created multiple times in a row (when multiple tags point to the
// same image), and a failure to persist the image will be summarized before we update the stream. If an image was imported by this
// operation, it *replaces* the imported image (from the remote repository) with the updated image.
func (r *REST) importSuccessful(
ctx kapi.Context,
image *api.Image, stream *api.ImageStream, tag string, from string, nextGeneration int64, now unversioned.Time, importPolicy api.TagImportPolicy,
importedImages map[string]error, updatedImages map[string]*api.Image,
) (*api.Image, bool) {
Strategy.PrepareImageForCreate(image)
pullSpec, _ := api.MostAccuratePullSpec(image.DockerImageReference, image.Name, "")
tagEvent := api.TagEvent{
Created: now,
DockerImageReference: pullSpec,
Image: image.Name,
Generation: nextGeneration,
}
if stream.Spec.Tags == nil {
stream.Spec.Tags = make(map[string]api.TagReference)
}
// ensure the spec and status tag match the imported image
changed := api.DifferentTagEvent(stream, tag, tagEvent)
specTag, ok := stream.Spec.Tags[tag]
if changed || !ok {
specTag = ensureSpecTag(stream, tag, from, importPolicy, true)
api.AddTagEventToImageStream(stream, tag, tagEvent)
}
// always reset the import policy
specTag.ImportPolicy = importPolicy
stream.Spec.Tags[tag] = specTag
// import or reuse the image, and ensure tag conditions are set
importErr, alreadyImported := importedImages[image.Name]
if importErr != nil {
api.SetTagConditions(stream, tag, newImportFailedCondition(importErr, nextGeneration, now))
} else {
api.SetTagConditions(stream, tag)
}
// create the image if it does not exist, otherwise cache the updated status from the store for use by other tags
if alreadyImported {
if updatedImage, ok := updatedImages[image.Name]; ok {
return updatedImage, true
}
return nil, false
}
updated, err := r.images.Create(ctx, image)
switch {
case kapierrors.IsAlreadyExists(err):
if err := api.ImageWithMetadata(image); err != nil {
glog.V(4).Infof("Unable to update image metadata during image import when image already exists %q: err", image.Name, err)
}
updated = image
fallthrough
case err == nil:
updatedImage := updated.(*api.Image)
updatedImages[image.Name] = updatedImage
//isi.Status.Repository.Images[i].Image = updatedImage
importedImages[image.Name] = nil
return updatedImage, true
default:
importedImages[image.Name] = err
}
return nil, false
}
开发者ID:Xmagicer,项目名称:origin,代码行数:69,代码来源:rest.go
示例3: Create
//.........这里部分代码省略.........
}
// update the spec tag
ref, err := api.ParseDockerImageReference(image.DockerImageReference)
if err != nil {
// ???
continue
}
tag := ref.Tag
if len(imageStatus.Tag) > 0 {
tag = imageStatus.Tag
}
if _, ok := stream.Spec.Tags[tag]; !ok {
if stream.Spec.Tags == nil {
stream.Spec.Tags = make(map[string]api.TagReference)
}
stream.Spec.Tags[tag] = api.TagReference{
From: &kapi.ObjectReference{
Kind: "DockerImage",
Name: image.DockerImageReference,
},
Generation: &gen,
ImportPolicy: api.TagImportPolicy{Insecure: spec.ImportPolicy.Insecure},
}
}
// import or reuse the image
importErr, imported := importedImages[image.Name]
if importErr != nil {
api.SetTagConditions(stream, tag, newImportFailedCondition(err, gen, now))
}
pullSpec, _ := api.MostAccuratePullSpec(image.DockerImageReference, image.Name, "")
api.AddTagEventToImageStream(stream, tag, api.TagEvent{
Created: now,
DockerImageReference: pullSpec,
Image: image.Name,
Generation: gen,
})
if imported {
if updatedImage, ok := updatedImages[image.Name]; ok {
isi.Status.Repository.Images[i].Image = updatedImage
}
continue
}
// establish the image into the store
updated, err := r.images.Create(ctx, image)
switch {
case kapierrors.IsAlreadyExists(err):
if err := api.ImageWithMetadata(image); err != nil {
glog.V(4).Infof("Unable to update image metadata during image import when image already exists %q: err", image.Name, err)
}
updated = image
fallthrough
case err == nil:
updatedImage := updated.(*api.Image)
updatedImages[image.Name] = updatedImage
isi.Status.Repository.Images[i].Image = updatedImage
importedImages[image.Name] = nil
default:
importedImages[image.Name] = err
}
}
}
开发者ID:balv14,项目名称:origin,代码行数:67,代码来源:rest.go
示例4: tagsChanged
// tagsChanged updates stream.Status.Tags based on the old and new image stream.
// if the old stream is nil, all tags are considered additions.
func (s Strategy) tagsChanged(old, stream *api.ImageStream) fielderrors.ValidationErrorList {
var errs fielderrors.ValidationErrorList
oldTags := map[string]api.TagReference{}
if old != nil && old.Spec.Tags != nil {
oldTags = old.Spec.Tags
}
for tag, tagRef := range stream.Spec.Tags {
if oldRef, ok := oldTags[tag]; ok && !tagRefChanged(oldRef, tagRef, stream.Namespace) {
continue
}
if tagRef.From == nil {
continue
}
if tagRef.From.Kind == "DockerImage" && len(tagRef.From.Name) > 0 {
if tagRef.Reference {
event, err := tagReferenceToTagEvent(stream, tagRef, "")
if err != nil {
errs = append(errs, fielderrors.NewFieldInvalid(fmt.Sprintf("spec.tags[%s].from", tag), tagRef.From, err.Error()))
continue
}
api.AddTagEventToImageStream(stream, tag, *event)
}
continue
}
tagRefStreamName, tagOrID, err := parseFromReference(stream, tagRef.From)
if err != nil {
errs = append(errs, fielderrors.NewFieldInvalid(fmt.Sprintf("spec.tags[%s].from.name", tag), tagRef.From.Name, "must be of the form <tag>, <repo>:<tag>, <id>, or <repo>@<id>"))
continue
}
streamRef := stream
streamRefNamespace := tagRef.From.Namespace
if len(streamRefNamespace) == 0 {
streamRefNamespace = stream.Namespace
}
if streamRefNamespace != stream.Namespace || tagRefStreamName != stream.Name {
obj, err := s.ImageStreamGetter.Get(kapi.WithNamespace(kapi.NewContext(), streamRefNamespace), tagRefStreamName)
if err != nil {
if kerrors.IsNotFound(err) {
errs = append(errs, fielderrors.NewFieldNotFound(fmt.Sprintf("spec.tags[%s].from.name", tag), tagRef.From.Name))
} else {
errs = append(errs, fielderrors.NewFieldInvalid(fmt.Sprintf("spec.tags[%s].from.name", tag), tagRef.From.Name, fmt.Sprintf("unable to retrieve image stream: %v", err)))
}
continue
}
streamRef = obj.(*api.ImageStream)
}
event, err := tagReferenceToTagEvent(streamRef, tagRef, tagOrID)
if err != nil {
errs = append(errs, fielderrors.NewFieldInvalid(fmt.Sprintf("spec.tags[%s].from.name", tag), tagRef.From.Name, fmt.Sprintf("error generating tag event: %v", err)))
continue
}
if event == nil {
// referenced tag or ID doesn't exist, which is ok
continue
}
api.AddTagEventToImageStream(stream, tag, *event)
}
if old != nil {
api.UpdateChangedTrackingTags(stream, old)
}
// use a consistent timestamp on creation
if old == nil && !stream.CreationTimestamp.IsZero() {
for tag, list := range stream.Status.Tags {
for _, event := range list.Items {
event.Created = stream.CreationTimestamp
}
stream.Status.Tags[tag] = list
}
}
return errs
}
开发者ID:kcbabo,项目名称:origin,代码行数:86,代码来源:strategy.go
示例5: Create
// Create registers a new image (if it doesn't exist) and updates the
// specified ImageStream's tags. If attempts to update the ImageStream fail
// with a resource conflict, the update will be retried if the newer
// ImageStream has no tag diffs from the previous state. If tag diffs are
// detected, the conflict error is returned.
func (s *REST) Create(ctx kapi.Context, obj runtime.Object) (runtime.Object, error) {
if err := rest.BeforeCreate(Strategy, ctx, obj); err != nil {
return nil, err
}
mapping := obj.(*api.ImageStreamMapping)
stream, err := s.findStreamForMapping(ctx, mapping)
if err != nil {
return nil, err
}
image := mapping.Image
tag := mapping.Tag
if len(tag) == 0 {
tag = api.DefaultImageTag
}
if err := s.imageRegistry.CreateImage(ctx, &image); err != nil && !errors.IsAlreadyExists(err) {
return nil, err
}
next := api.TagEvent{
Created: unversioned.Now(),
DockerImageReference: image.DockerImageReference,
Image: image.Name,
}
err = wait.ExponentialBackoff(wait.Backoff{Steps: maxRetriesOnConflict}, func() (bool, error) {
lastEvent := api.LatestTaggedImage(stream, tag)
next.Generation = stream.Generation
if !api.AddTagEventToImageStream(stream, tag, next) {
// nothing actually changed
return true, nil
}
api.UpdateTrackingTags(stream, tag, next)
_, err := s.imageStreamRegistry.UpdateImageStreamStatus(ctx, stream)
if err == nil {
return true, nil
}
if !errors.IsConflict(err) {
return false, err
}
// If the update conflicts, get the latest stream and check for tag
// updates. If the latest tag hasn't changed, retry.
latestStream, findLatestErr := s.findStreamForMapping(ctx, mapping)
if findLatestErr != nil {
return false, findLatestErr
}
// no previous tag
if lastEvent == nil {
// The tag hasn't changed, so try again with the updated stream.
stream = latestStream
return false, nil
}
// check for tag change
newerEvent := api.LatestTaggedImage(latestStream, tag)
// generation and creation time differences are ignored
lastEvent.Generation = newerEvent.Generation
lastEvent.Created = newerEvent.Created
if kapi.Semantic.DeepEqual(lastEvent, newerEvent) {
// The tag hasn't changed, so try again with the updated stream.
stream = latestStream
return false, nil
}
// The tag changed, so return the conflict error back to the client.
return false, err
})
if err != nil {
return nil, err
}
return &unversioned.Status{Status: unversioned.StatusSuccess}, nil
}
开发者ID:RomainVabre,项目名称:origin,代码行数:83,代码来源:rest.go
示例6: tagsChanged
// tagsChanged updates stream.Status.Tags based on the old and new image stream.
// if the old stream is nil, all tags are considered additions.
func (s Strategy) tagsChanged(old, stream *api.ImageStream) field.ErrorList {
internalRegistry, hasInternalRegistry := s.defaultRegistry.DefaultRegistry()
var errs field.ErrorList
oldTags := map[string]api.TagReference{}
if old != nil && old.Spec.Tags != nil {
oldTags = old.Spec.Tags
}
for tag, tagRef := range stream.Spec.Tags {
if oldRef, ok := oldTags[tag]; ok && !tagRefChanged(oldRef, tagRef, stream.Namespace) {
continue
}
if tagRef.From == nil {
continue
}
glog.V(5).Infof("Detected changed tag %s in %s/%s", tag, stream.Namespace, stream.Name)
generation := stream.Generation
tagRef.Generation = &generation
fromPath := field.NewPath("spec", "tags").Key(tag).Child("from")
if tagRef.From.Kind == "DockerImage" && len(tagRef.From.Name) > 0 {
if tagRef.Reference {
event, err := tagReferenceToTagEvent(stream, tagRef, "")
if err != nil {
errs = append(errs, field.Invalid(fromPath, tagRef.From, err.Error()))
continue
}
stream.Spec.Tags[tag] = tagRef
api.AddTagEventToImageStream(stream, tag, *event)
}
continue
}
tagRefStreamName, tagOrID, err := parseFromReference(stream, tagRef.From)
if err != nil {
errs = append(errs, field.Invalid(fromPath.Child("name"), tagRef.From.Name, "must be of the form <tag>, <repo>:<tag>, <id>, or <repo>@<id>"))
continue
}
streamRef := stream
streamRefNamespace := tagRef.From.Namespace
if len(streamRefNamespace) == 0 {
streamRefNamespace = stream.Namespace
}
if streamRefNamespace != stream.Namespace || tagRefStreamName != stream.Name {
obj, err := s.ImageStreamGetter.Get(kapi.WithNamespace(kapi.NewContext(), streamRefNamespace), tagRefStreamName)
if err != nil {
if kerrors.IsNotFound(err) {
errs = append(errs, field.NotFound(fromPath.Child("name"), tagRef.From.Name))
} else {
errs = append(errs, field.Invalid(fromPath.Child("name"), tagRef.From.Name, fmt.Sprintf("unable to retrieve image stream: %v", err)))
}
continue
}
streamRef = obj.(*api.ImageStream)
}
event, err := tagReferenceToTagEvent(streamRef, tagRef, tagOrID)
if err != nil {
errs = append(errs, field.Invalid(fromPath.Child("name"), tagRef.From.Name, fmt.Sprintf("error generating tag event: %v", err)))
continue
}
if event == nil {
// referenced tag or ID doesn't exist, which is ok
continue
}
// if this is not a reference tag, and the tag points to the internal registry for the other namespace, alter it to
// point to this stream so that pulls happen from this stream in the future.
if !tagRef.Reference {
if ref, err := api.ParseDockerImageReference(event.DockerImageReference); err == nil {
if hasInternalRegistry && ref.Registry == internalRegistry && ref.Namespace == streamRef.Namespace && ref.Name == streamRef.Name {
ref.Namespace = stream.Namespace
ref.Name = stream.Name
event.DockerImageReference = ref.Exact()
}
}
}
stream.Spec.Tags[tag] = tagRef
api.AddTagEventToImageStream(stream, tag, *event)
}
api.UpdateChangedTrackingTags(stream, old)
// use a consistent timestamp on creation
if old == nil && !stream.CreationTimestamp.IsZero() {
for tag, list := range stream.Status.Tags {
for _, event := range list.Items {
event.Created = stream.CreationTimestamp
}
stream.Status.Tags[tag] = list
//.........这里部分代码省略.........
开发者ID:legionus,项目名称:origin,代码行数:101,代码来源:strategy.go
注:本文中的github.com/openshift/origin/pkg/image/api.AddTagEventToImageStream函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论